-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'ribasim-python/main' into merge
- Loading branch information
Showing
37 changed files
with
3,150 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
ribasim-python | ||
============== | ||
|
||
A Python package for working with `Ribasim.jl <https://github.com/Deltares/Ribasim.jl>`_. | ||
|
||
|
||
Documentation | ||
------------- | ||
|
||
API documentation can be found `here <https://deltares.github.io/ribasim-python/ribasim.html>`_. | ||
See also the examples directory. |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: ribasim | ||
|
||
channels: | ||
- conda-forge | ||
|
||
dependencies: | ||
- python >= 3.9 | ||
- matplotlib | ||
- pandas | ||
- geopandas | ||
- pandera | ||
- pyarrow | ||
- pydantic | ||
- pyogrio | ||
- shapely >=2.0 | ||
- tomli | ||
- tomli-w | ||
- xarray |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# %% | ||
import os | ||
|
||
os.environ["USE_PYGEOS"] = "0" | ||
|
||
import numpy as np | ||
import pandas as pd | ||
import xarray as xr | ||
|
||
import ribasim | ||
|
||
# %% | ||
|
||
model = ribasim.Model.from_toml("basic/basic.toml") | ||
|
||
# %% | ||
|
||
time = pd.date_range(model.starttime, model.endtime) | ||
day_of_year = time.day_of_year.values | ||
seconds_per_day = 24 * 60 * 60 | ||
evaporation = ( | ||
(-1.0 * np.cos(day_of_year / 365.0 * 2 * np.pi) + 1.0) * 0.0025 / seconds_per_day | ||
) | ||
rng = np.random.default_rng() | ||
precipitation = ( | ||
rng.lognormal(mean=-1.0, sigma=1.7, size=time.size) * 0.001 / seconds_per_day | ||
) | ||
|
||
# %% | ||
# We'll use xarray to easily broadcast the values. | ||
|
||
timeseries = ( | ||
pd.DataFrame( | ||
data={ | ||
"node_id": 1, | ||
"time": time, | ||
"drainage": 0.0, | ||
"potential_evaporation": evaporation, | ||
"infiltration": 0.0, | ||
"precipitation": precipitation, | ||
"urban_runoff": 0.0, | ||
} | ||
) | ||
.set_index("time") | ||
.to_xarray() | ||
) | ||
|
||
basin_ids = model.basin.static["node_id"].unique() | ||
basin_nodes = xr.DataArray( | ||
np.ones(len(basin_ids)), coords={"node_id": basin_ids}, dims=["node_id"] | ||
) | ||
forcing = (timeseries * basin_nodes).to_dataframe().reset_index() | ||
|
||
# %% | ||
|
||
state = pd.DataFrame( | ||
data={ | ||
"node_id": basin_ids, | ||
"storage": 1000.0, | ||
"concentration": 0.0, | ||
} | ||
) | ||
|
||
# %% | ||
|
||
model.basin.forcing = forcing | ||
model.basin.state = state | ||
|
||
# %% | ||
|
||
model.write("basic-transient") | ||
# %% | ||
# After running the model, read back the input: | ||
|
||
df = pd.read_feather(r"c:\src\ribasim.jl\examples\basic-transient\basin.arrow") | ||
output = df.set_index(["time", "node_id"]).to_xarray() | ||
output["level"].plot(hue="node_id") | ||
# %% |
Oops, something went wrong.