diff --git a/.teamcity/IMODCollector/buildTypes/IMODCollector_X64development.kt b/.teamcity/IMODCollector/buildTypes/IMODCollector_X64development.kt index b6aad3d0..521176fe 100644 --- a/.teamcity/IMODCollector/buildTypes/IMODCollector_X64development.kt +++ b/.teamcity/IMODCollector/buildTypes/IMODCollector_X64development.kt @@ -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 diff --git a/.teamcity/Primod/buildTypes/Primod_TestPrimodWin64.kt b/.teamcity/Primod/buildTypes/Primod_TestPrimodWin64.kt index eaa5d935..ab90c4fb 100644 --- a/.teamcity/Primod/buildTypes/Primod_TestPrimodWin64.kt +++ b/.teamcity/Primod/buildTypes/Primod_TestPrimodWin64.kt @@ -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 { diff --git a/.teamcity/_Self/buildTypes/TestbenchCouplerWin64_2.kt b/.teamcity/_Self/buildTypes/TestbenchCouplerWin64_2.kt index 166e2833..d9c1ef42 100644 --- a/.teamcity/_Self/buildTypes/TestbenchCouplerWin64_2.kt +++ b/.teamcity/_Self/buildTypes/TestbenchCouplerWin64_2.kt @@ -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 { diff --git a/pixi.toml b/pixi.toml index 8b43ccd0..fe40a9b4 100644 --- a/pixi.toml +++ b/pixi.toml @@ -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" @@ -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"] } diff --git a/pre-processing/primod/driver_coupling/util.py b/pre-processing/primod/driver_coupling/util.py index c112bb96..ba01891d 100644 --- a/pre-processing/primod/driver_coupling/util.py +++ b/pre-processing/primod/driver_coupling/util.py @@ -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] diff --git a/tests/test_imod_coupler/test_ribametamod_cases.py b/tests/test_imod_coupler/test_ribametamod_cases.py index 94d32b87..a037859e 100644 --- a/tests/test_imod_coupler/test_ribametamod_cases.py +++ b/tests/test_imod_coupler/test_ribametamod_cases.py @@ -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) @@ -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( @@ -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( { @@ -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 diff --git a/tests/test_imod_coupler/test_ribamod_cases.py b/tests/test_imod_coupler/test_ribamod_cases.py index 7abbb15f..81febdbf 100644 --- a/tests/test_imod_coupler/test_ribamod_cases.py +++ b/tests/test_imod_coupler/test_ribamod_cases.py @@ -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()}, diff --git a/tests/test_primod/test_preprocessing_ribamod.py b/tests/test_primod/test_preprocessing_ribamod.py index 68e3fb92..586327a7 100644 --- a/tests/test_primod/test_preprocessing_ribamod.py +++ b/tests/test_primod/test_preprocessing_ribamod.py @@ -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, ) @@ -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,