Skip to content

Commit cfadad0

Browse files
authored
Docs: overwrite run_ribasim (#2929)
Fixes #2700 We overwrite the ribasim function with our hidden function that runs the julia code, so we don't need to have a ribasim binary at doc build time.
1 parent 48d1726 commit cfadad0

File tree

6 files changed

+33
-59
lines changed

6 files changed

+33
-59
lines changed

docs/getting-started/examples.qmd

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,6 @@ jupyter: python3
55

66
This is an overview of example codes to set-up and run models.
77

8-
```{python}
9-
#| eval: false
10-
from ribasim import run_ribasim
11-
```
12-
13-
```{python}
14-
#| include: false
15-
%run ../run_ribasim.py
16-
```
17-
188
# Basic model with static forcing
199

2010
```{python}
@@ -31,7 +21,7 @@ from pathlib import Path
3121
import matplotlib.pyplot as plt
3222
import numpy as np
3323
import pandas as pd
34-
from ribasim import Allocation, Model, Node, Solver
24+
from ribasim import Allocation, Model, Node, Solver, run_ribasim
3525
from ribasim.config import Experimental
3626
from ribasim.nodes import (
3727
basin,
@@ -51,6 +41,11 @@ from ribasim.nodes import (
5141
from shapely.geometry import Point
5242
```
5343

44+
```{python}
45+
#| include: false
46+
%run ../run_ribasim.py
47+
```
48+
5449
```{python}
5550
datadir = Path("data")
5651
shutil.rmtree(datadir, ignore_errors=True)

docs/getting-started/tutorial/irrigation-demand.qmd

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,14 @@ title: Irrigation demand
33
jupyter: python3
44
---
55

6-
```{python}
7-
#| eval: false
8-
from ribasim import run_ribasim
9-
```
10-
11-
```{python}
12-
#| include: false
13-
%run ../../run_ribasim.py
14-
```
15-
166
```{python}
177
from pathlib import Path
188
199
import matplotlib.pyplot as plt
2010
import pandas as pd
2111
import plotly.express as px
2212
import xarray as xr
23-
from ribasim import Model, Node
13+
from ribasim import Model, Node, run_ribasim
2414
from ribasim.nodes import (
2515
basin,
2616
flow_boundary,
@@ -30,6 +20,11 @@ from ribasim.nodes import (
3020
from shapely.geometry import Point
3121
```
3222

23+
```{python}
24+
#| include: false
25+
%run ../../run_ribasim.py
26+
```
27+
3328
```{python}
3429
base_dir = Path("crystal-basin")
3530

docs/getting-started/tutorial/natural-flow.qmd

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,6 @@ title: Natural flow
33
jupyter: python3
44
---
55

6-
```{python}
7-
#| eval: false
8-
from ribasim import run_ribasim
9-
```
10-
11-
```{python}
12-
#| include: false
13-
%run ../../run_ribasim.py
14-
```
15-
166
# Introduction
177
Welcome to Ribasim!
188
This tutorial will help you get started with the basics of using Ribasim for river basin simulation.
@@ -63,11 +53,16 @@ from pathlib import Path
6353
import matplotlib.pyplot as plt
6454
import pandas as pd
6555
import xarray as xr
66-
from ribasim import Model, Node
56+
from ribasim import Model, Node, run_ribasim
6757
from ribasim.nodes import basin, flow_boundary, tabulated_rating_curve
6858
from shapely.geometry import Point
6959
```
7060

61+
```{python}
62+
#| include: false
63+
%run ../../run_ribasim.py
64+
```
65+
7166
### Setup paths and model configuration
7267
Reference the paths of the Ribasim installation and model directory and define the time period.
7368
The used simulation period is defined by the `starttime` and `endtime` of the model, not by the input timeseries.

docs/getting-started/tutorial/reservoir.qmd

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,14 @@ title: Reservoir
33
jupyter: python3
44
---
55

6-
```{python}
7-
#| eval: false
8-
from ribasim import run_ribasim
9-
```
10-
11-
```{python}
12-
#| include: false
13-
%run ../../run_ribasim.py
14-
```
15-
166
```{python}
177
from pathlib import Path
188
199
import matplotlib.pyplot as plt
2010
import pandas as pd
2111
import plotly.express as px
2212
import xarray as xr
23-
from ribasim import Model, Node
13+
from ribasim import Model, Node, run_ribasim
2414
from ribasim.nodes import (
2515
basin,
2616
flow_boundary,
@@ -30,6 +20,11 @@ from ribasim.nodes import (
3020
from shapely.geometry import Point
3121
```
3222

23+
```{python}
24+
#| include: false
25+
%run ../../run_ribasim.py
26+
```
27+
3328
```{python}
3429
base_dir = Path("crystal-basin")
3530

docs/guide/delwaq.qmd

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,6 @@ title: Ribasim Delwaq coupling
33
jupyter: python3
44
---
55

6-
```{python}
7-
#| eval: false
8-
from ribasim import run_ribasim
9-
```
10-
11-
```{python}
12-
#| include: false
13-
%run ../run_ribasim.py
14-
```
15-
166
In order to generate the Delwaq input files, we need a completed Ribasim simulation (typically one with a results folder) that ideally also includes some substances and initial concentrations. Let's take the basic test model for example, which already has set some initial concentrations.
177

188
All testmodels can be [downloaded from here](/getting-started/install.qmd).
@@ -30,7 +20,7 @@ assert toml_path.is_file()
3020
This Ribasim model already has substance concentrations for `Cl` and `Tracer` in the input tables, and we will use these to generate the Delwaq input files.
3121

3222
```{python}
33-
from ribasim import Model
23+
from ribasim import Model, run_ribasim
3424
3525
model = Model.read(toml_path)
3626
@@ -41,6 +31,11 @@ display(model.level_boundary.concentration) # level boundaries
4131
model.plot(); # for later comparison
4232
```
4333

34+
```{python}
35+
#| include: false
36+
%run ../run_ribasim.py
37+
```
38+
4439
```{python}
4540
model.basin.profile
4641
```

docs/run_ribasim.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
In a file where multiple simulations are run this has the benefit
99
of only needing to start Julia once, compared to `subprocess.run`.
1010
11-
Since Ribasim Python also has `run_ribasim`, we can include
12-
this script in a hidden evaluated cell, and put `from ribasim import run_ribasim`
13-
in a visible unevaluated cell. That way we can run this version on CI but
14-
it looks like we run the Ribasim Python version.
11+
Since Ribasim Python also has `run_ribasim`, we can include this script
12+
in a hidden evaluated cell, after `from ribasim import run_ribasim`.
13+
That way we can run this version on CI but it looks like we run the Ribasim Python version.
1514
"""
1615

1716
from pathlib import Path

0 commit comments

Comments
 (0)