-
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.
Add two_basin model to ribasim-testsmodels (#994)
This model is only defined in the imod_coupler tests, which means it's not automatically updated when someone makes a breaking change. Then, the imod_coupler tests will fail. I'll update the fixture in imod_coupler after this is merged.
- Loading branch information
Showing
2 changed files
with
128 additions
and
0 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
126 changes: 126 additions & 0 deletions
126
python/ribasim_testmodels/ribasim_testmodels/two_basin.py
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,126 @@ | ||
import geopandas as gpd | ||
import numpy as np | ||
import pandas as pd | ||
import ribasim | ||
|
||
|
||
def two_basin_model() -> ribasim.Model: | ||
""" | ||
Create a model of two basins. | ||
The basins are not connected; the model is mostly designed to test in | ||
combination with a groundwater model. | ||
The left basin receives water. In case of a coupled run, the water | ||
infiltrates in the left basin, and exfiltrates in the right basin. | ||
The right basin fills up and discharges over the rating curve. | ||
""" | ||
flow_boundary = ribasim.FlowBoundary( | ||
static=pd.DataFrame( | ||
data={ | ||
"node_id": [1], | ||
"flow_rate": [1e-2], | ||
} | ||
) | ||
) | ||
|
||
xy = np.array( | ||
[ | ||
(0, 0.0), # FlowBoundary | ||
(250.0, 0.0), # Basin 1 | ||
(750.0, 0.0), # Basin 2 | ||
(1000.00, 0.0), # TabulatedRatingCurve | ||
(1100.00, 0.0), # Terminal | ||
] | ||
) | ||
# Rectangular profile | ||
profile = pd.DataFrame( | ||
data={ | ||
"node_id": [2, 2, 3, 3], | ||
"area": [400.0, 400.0, 400.0, 400.0], | ||
"level": [0.0, 1.0, 0.0, 1.0], | ||
} | ||
) | ||
state = pd.DataFrame(data={"node_id": [2, 3], "level": [0.01, 0.01]}) | ||
static = pd.DataFrame( | ||
data={ | ||
"node_id": [2, 3], | ||
"drainage": [0.0, 0.0], | ||
"potential_evaporation": [0.0, 0.0], | ||
"infiltration": [0.0, 0.0], | ||
"precipitation": [0.0, 0.0], | ||
"urban_runoff": [0.0, 0.0], | ||
} | ||
) | ||
subgrid = pd.DataFrame( | ||
data={ | ||
"node_id": [2, 2, 3, 3], | ||
"subgrid_id": [1, 1, 2, 2], | ||
"basin_level": [0.0, 1.0, 0.0, 1.0], | ||
"subgrid_level": [0.0, 1.0, 0.0, 1.0], | ||
"meta_x": [250.0, 250.0, 750.0, 750.0], | ||
"meta_y": [0.0, 0.0, 0.0, 0.0], | ||
} | ||
) | ||
basin = ribasim.Basin(profile=profile, state=state, static=static, subgrid=subgrid) | ||
|
||
rating_curve = ribasim.TabulatedRatingCurve( | ||
static=pd.DataFrame( | ||
data={ | ||
"node_id": [4, 4], | ||
"level": [0.0, 1.0], | ||
"flow_rate": [0.0, 0.01], | ||
} | ||
) | ||
) | ||
|
||
terminal = ribasim.Terminal( | ||
static=pd.DataFrame( | ||
data={ | ||
"node_id": [5], | ||
} | ||
) | ||
) | ||
node_id, node_type = ribasim.Node.node_ids_and_types( | ||
basin, | ||
rating_curve, | ||
flow_boundary, | ||
terminal, | ||
) | ||
node_xy = gpd.points_from_xy(x=xy[:, 0], y=xy[:, 1]) | ||
|
||
# Make sure the feature id starts at 1: explicitly give an index. | ||
node = ribasim.Node( | ||
df=gpd.GeoDataFrame( | ||
data={"type": node_type}, | ||
index=pd.Index(node_id, name="fid"), | ||
geometry=node_xy, | ||
crs="EPSG:28992", | ||
) | ||
) | ||
|
||
from_id = np.array([1, 3, 4], dtype=np.int64) | ||
to_id = np.array([2, 4, 5], dtype=np.int64) | ||
lines = node.geometry_from_connectivity([1, 3, 4], [2, 4, 5]) | ||
edge = ribasim.Edge( | ||
df=gpd.GeoDataFrame( | ||
data={ | ||
"from_node_id": from_id, | ||
"to_node_id": to_id, | ||
"edge_type": len(from_id) * ["flow"], | ||
}, | ||
geometry=lines, | ||
crs="EPSG:28992", | ||
) | ||
) | ||
|
||
ribasim_model = ribasim.Model( | ||
network=ribasim.Network(node=node, edge=edge), | ||
basin=basin, | ||
flow_boundary=flow_boundary, | ||
tabulated_rating_curve=rating_curve, | ||
terminal=terminal, | ||
starttime="2020-01-01 00:00:00", | ||
endtime="2030-01-01 00:00:00", | ||
) | ||
return ribasim_model |