Skip to content

Commit

Permalink
Add add-api
Browse files Browse the repository at this point in the history
Validate during initialization

Improve Node representation

Adapt type hint

Minimal version of `Model`

Add existing methods to `Model`

Continue

Fix remaining problems
  • Loading branch information
Hofer-Julian committed Feb 26, 2024
1 parent 7ee3f1a commit 491911b
Show file tree
Hide file tree
Showing 7 changed files with 434 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,4 @@ report.xml

# Designated working dir for working on Ribasim models
models/
playground/output
50 changes: 50 additions & 0 deletions playground/playground.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# %%
import shutil
from pathlib import Path

from pandas import DataFrame
from ribasim.add import Basins, Model
from ribasim.config import Basin

# %%
output_dir = Path(__file__).parent / "output"
shutil.rmtree(output_dir, ignore_errors=True)
# %%

basins = Basins(
[
Basin(
profile=DataFrame({"area": [1.0, 3.0], "level": [1.1, 2.2]}),
# static=DataFrame(
# {"precipitation": [1.0, 3.0], "control_state": [1.1, 2.2]}
# ),
node={
"node_id": 2,
"geometry": (2.0, 3.6),
"name": "IJsselmeer",
"subnetwork_id": 5,
},
),
Basin(
profile=DataFrame({"area": [2.0, 4.0], "level": [6.1, 7.2]}),
# static=DataFrame(
# {"precipitation": [1.0, 3.0], "control_state": [1.1, 2.2]}
# ),
node={
"node_id": 1,
"geometry": (5.0, 3.6),
"name": "Zoetermeer",
"subnetwork_id": 6,
},
),
]
)
basins
# %%
model = Model(
starttime="2020-01-01 00:00:00", endtime="2021-01-01 00:00:00", basins=basins
)
model
# %%
toml_path = output_dir / "ribasim.toml"
model.write(toml_path)
38 changes: 38 additions & 0 deletions python/ribasim/playground.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# %%
import tempfile
from pathlib import Path

import geopandas
import pandas as pd
from pandas import DataFrame
from ribasim.add import Basins, Model
from ribasim.config import Basin

basins = Basins(
[
Basin(
profile=DataFrame({"area": [1.0, 3.0], "level": [1.1, 2.2]}),
# static=DataFrame(
# {"precipitation": [1.0, 3.0], "control_state": [1.1, 2.2]}
# ),
node={
"id": 2,
# allow tuples, call gpd.points_from_xy ourselves
"geometry": (2.0, 3.6),
"name": "IJsselmeer",
"allocation_network_id": 5,
},
)
]
)
basins
# %%
model = Model(
starttime="2020-01-01 00:00:00", endtime="2021-01-01 00:00:00", basins=basins
)
model
# %%
with tempfile.TemporaryDirectory() as tmpdirname:
toml_path = Path(tmpdirname) / "ribasim.toml"
model.write(toml_path)
print(toml_path.read_text())
Loading

0 comments on commit 491911b

Please sign in to comment.