Skip to content

Commit

Permalink
update ribasim python before building coupler to have the latest stuff (
Browse files Browse the repository at this point in the history
#322)


---------

Co-authored-by: HendrikKok <[email protected]>
  • Loading branch information
rleander and HendrikKok authored Aug 27, 2024
1 parent e9dd53d commit 97b3e7a
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,6 @@ object IMODCollector_X64development : BuildType({
}

steps {
script {
name = "Create imod_collector conda environment"
id = "Create_imod_collector_conda_environment"
enabled = false
scriptContent = """
if exist "%conda_env_path%" rd /q /s "%conda_env_path%"
conda env create --file coupler/environment-minimal.yml -p "%conda_env_path%"
""".trimIndent()
}
script {
name = "Install iMOD Coupler"
enabled = false
Expand Down
1 change: 1 addition & 0 deletions .teamcity/Primod/buildTypes/Primod_TestPrimodWin64.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ object Primod_TestPrimodWin64 : Template({
scriptContent = """
pixi --version
pixi run --environment %pixi-environment% install
pixi run --environment %pixi-environment% update-git-dependencies
""".trimIndent()
}
script {
Expand Down
1 change: 1 addition & 0 deletions .teamcity/_Self/buildTypes/TestbenchCouplerWin64_2.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ object TestbenchCouplerWin64_2 : BuildType({
scriptContent = """
pixi --version
pixi run -e dev install
pixi run -e dev update-git-dependencies
""".trimIndent()
}
script {
Expand Down
10 changes: 6 additions & 4 deletions pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ install = { depends_on = [
"install-primod",
] }

update-git-dependencies = """pip install --upgrade --force-reinstall --no-deps
git+https://github.com/Deltares/Ribasim.git/#subdirectory=python/ribasim
git+https://github.com/Deltares/Ribasim.git/#subdirectory=python/ribasim_api
git+https://github.com/Deltares/Ribasim.git/#subdirectory=python/ribasim_testmodels"""

# Tests
test-primod = "pytest --junitxml=report.xml tests/test_primod"

Expand Down Expand Up @@ -76,10 +81,7 @@ install-test-dependencies = { depends_on = [
"install-imod-collector-regression",
"generate-env-file",
] }
update-git-dependencies = """pip install --upgrade --force-reinstall --no-deps
git+https://github.com/Deltares/Ribasim.git/#subdirectory=python/ribasim
git+https://github.com/Deltares/Ribasim.git/#subdirectory=python/ribasim_api
git+https://github.com/Deltares/Ribasim.git/#subdirectory=python/ribasim_testmodels"""

# Tests
test-imod-coupler = "pytest -v -s --numprocesses=auto --dist=loadgroup --basetemp=tests/temp --junitxml=report.xml tests/test_imod_coupler"
tests = { depends_on = ["test-primod", "test-imod-coupler"] }
Expand Down
2 changes: 1 addition & 1 deletion pre-processing/primod/driver_coupling/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def _validate_node_ids(
f"Columns in dataframe: {definition.columns}"
)

basin_ids: NDArray[Int] = np.unique(dataframe["node_id"])
basin_ids: NDArray[Int] = np.unique(dataframe.index)
missing = ~np.isin(definition["node_id"], basin_ids)
if missing.any():
missing_nodes = definition["node_id"].to_numpy()[missing]
Expand Down
17 changes: 7 additions & 10 deletions tests/test_imod_coupler/test_ribametamod_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ def create_basin_definition(
if "nodes" in kwargs:
nodelist = kwargs["nodes"]
else:
nodelist = list(node.df["node_id"])
sel = node.df["node_id"].isin(nodelist)
nodelist = list(node.df.index)
sel = node.df.index.isin(nodelist)
basin_definition = gpd.GeoDataFrame(
data={"node_id": node.df.loc[sel]["node_id"].to_numpy()},
data={"node_id": node.df.loc[sel].index.to_numpy()},
geometry=node.df[sel]["geometry"]
.translate(yoff=yoff, xoff=xoff)
.buffer(buffersize)
Expand Down Expand Up @@ -97,12 +97,8 @@ def remove_sprinkling_from_groundwater(

def add_water_users(ribasim_model: ribasim.Model) -> ribasim.Model:
# add subnetwork id to basins
ribasim_model.basin.node.df["subnetwork_id"].loc[
ribasim_model.basin.node.df["node_id"] == 2
] = 2
ribasim_model.basin.node.df["subnetwork_id"].loc[
ribasim_model.basin.node.df["node_id"] == 3
] = 3
ribasim_model.basin.node.df["subnetwork_id"][2] = 2
ribasim_model.basin.node.df["subnetwork_id"][3] = 3

# Add waterusers to model; basin 2
ribasim_model.user_demand.add(
Expand Down Expand Up @@ -198,7 +194,7 @@ def two_basin_model_sprinkling_sw_variations(

# increase initial stage second basin, to be able to extract irrigation water.
ribasim_two_basin_model.basin.state.df["level"].loc[
ribasim_two_basin_model.basin.node.df["node_id"] == 3
ribasim_two_basin_model.basin.node.df.index == 3
] = 8.0
new_df = pd.DataFrame(
{
Expand All @@ -209,6 +205,7 @@ def two_basin_model_sprinkling_sw_variations(
"control_state": [None, None, None],
}
)
new_df.index.name = "fid"
ribasim_two_basin_model.tabulated_rating_curve.static.df = new_df

# increase inflow rate first basinto be able to extract irrigation water
Expand Down
2 changes: 1 addition & 1 deletion tests/test_imod_coupler/test_ribamod_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def create_basin_definition(
ribasim_model: ribasim.Model, buffersize: float
) -> gpd.GeoDataFrame:
basin_geometry = ribasim_model.basin.node.df["geometry"]
basin_ids = ribasim_model.basin.node.df["node_id"]
basin_ids = ribasim_model.basin.node.df.index
# Call to_numpy() to get rid of the index
basin_definition = gpd.GeoDataFrame(
data={"node_id": basin_ids.to_numpy()},
Expand Down
13 changes: 8 additions & 5 deletions tests/test_primod/test_preprocessing_ribamod.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,13 @@ def test_nullify_on_write(

# This basin definition is still a point geometry.
# This mean it will be rasterized to just two pixels.
gdf = ribasim_two_basin_model.basin.node.df
basin_definition = ribasim_two_basin_model.basin.node.df.copy()
if basin_definition.index.name == "node_id":
basin_definition["node_id"] = basin_definition.index

driver_coupling = RibaModActiveDriverCoupling(
mf6_model=mf6_modelname,
ribasim_basin_definition=gdf,
ribasim_basin_definition=basin_definition,
mf6_packages=mf6_river_packages,
)

Expand All @@ -272,14 +275,14 @@ def test_nullify_on_write(
ribasim_dll_dependency="c",
)
# check if columns will be nullified correctly
node_id = coupled_models.ribasim_model.basin.node.df["node_id"].to_numpy()
node_id = coupled_models.ribasim_model.basin.node.df.index.to_numpy()
df = pd.DataFrame.from_dict(
{
"node_id": node_id,
"fid": node_id,
"drainage": np.ones_like(node_id),
"infiltration": np.ones_like(node_id),
}
)
).set_index("fid")
coupled_models.ribasim_model.basin.static.df = df
coupled_models.write(
directory=tmp_path,
Expand Down

0 comments on commit 97b3e7a

Please sign in to comment.