Skip to content

Commit

Permalink
Add two_basin model to ribasim-testsmodels (#994)
Browse files Browse the repository at this point in the history
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
Huite authored Jan 26, 2024
1 parent 26c1b7f commit f4e90ad
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 0 deletions.
2 changes: 2 additions & 0 deletions python/ribasim_testmodels/ribasim_testmodels/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
)
from ribasim_testmodels.time import flow_boundary_time_model
from ribasim_testmodels.trivial import trivial_model
from ribasim_testmodels.two_basin import two_basin_model

__all__ = [
"allocation_example_model",
Expand Down Expand Up @@ -83,6 +84,7 @@
"minimal_subnetwork_model",
"fractional_flow_subnetwork_model",
"looped_subnetwork_model",
"two_basin_model",
]

# provide a mapping from model name to its constructor, so we can iterate over all models
Expand Down
126 changes: 126 additions & 0 deletions python/ribasim_testmodels/ribasim_testmodels/two_basin.py
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

0 comments on commit f4e90ad

Please sign in to comment.