From 83bd1c99c7ffc0083da54acd4cf1f9b02e43bd36 Mon Sep 17 00:00:00 2001 From: JoerivanEngelen Date: Wed, 6 May 2026 11:55:29 +0200 Subject: [PATCH 1/3] Add functionality to provide custom name for Modflow6Simulation.from_imod5_data --- imod/mf6/simulation.py | 12 +++++++++--- imod/tests/test_mf6/test_mf6_simulation.py | 20 ++++++++++++++++---- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/imod/mf6/simulation.py b/imod/mf6/simulation.py index 2589fad14..6e73257b8 100644 --- a/imod/mf6/simulation.py +++ b/imod/mf6/simulation.py @@ -1752,6 +1752,7 @@ def from_imod5_data( distributing_options: Optional[SimulationDistributingOptions] = None, regridder_types: Optional[dict[str, DataclassType]] = None, target_grid: Optional[GridDataArray] = None, + name: str = "imported", ) -> "Modflow6Simulation": """ Imports a GroundwaterFlowModel (GWF) from the data in an iMOD5 project @@ -1799,6 +1800,9 @@ def from_imod5_data( target_grid: GridDataArray, optional the target grid to which the data should be regridded. If not provided, the first grid of the BND package is used as target grid. + name: str, optional + name that will be used as a prefix for the simulation and model + names. Default is "imported". Returns ------- @@ -1866,8 +1870,9 @@ def from_imod5_data( strict_well_validation=False, strict_hfb_validation=False, ) + simulation_name = f"{name}_simulation" simulation = Modflow6Simulation( - "imported_simulation", validation_settings=validation_settings + simulation_name, validation_settings=validation_settings ) # import GWF model, @@ -1880,11 +1885,12 @@ def from_imod5_data( regridder_types, target_grid, ) - simulation["imported_model"] = gwf_model + gwf_modelname = f"{name}_model" + simulation[gwf_modelname] = gwf_model # generate ims package solution = SolutionPresetModerate( - ["imported_model"], + [gwf_modelname], print_option="all", ) simulation["ims"] = solution diff --git a/imod/tests/test_mf6/test_mf6_simulation.py b/imod/tests/test_mf6/test_mf6_simulation.py index 35406a52c..c857589ef 100644 --- a/imod/tests/test_mf6/test_mf6_simulation.py +++ b/imod/tests/test_mf6/test_mf6_simulation.py @@ -610,6 +610,22 @@ def test_import_from_imod5(imod5_dataset, tmp_path): assert simulation._validation_context.strict_well_validation is False +@pytest.mark.unittest_jit +def test_import_from_imod5__custom_name(imod5_dataset): + imod5_data = imod5_dataset[0] + period_data = imod5_dataset[1] + + datelist = pd.date_range(start="1/1/1989", end="1/3/1989", freq="D") + simulation = Modflow6Simulation.from_imod5_data( + imod5_data, + period_data, + datelist, + name="custom", + ) + assert "custom_simulation" in simulation.name + assert "custom_model" in simulation.keys() + + @pytest.mark.unittest_jit def test_from_imod5__has_cap_data(imod5_dataset): imod5_data = deepcopy(imod5_dataset[0]) @@ -669,8 +685,6 @@ def test_import_from_imod5__correct_well_type(imod5_dataset): original_wel_layer = imod5_data["wel-WELLS_L3"]["layer"] imod5_data["wel-WELLS_L3"]["layer"] = [0] * len(original_wel_layer) # Other arrangement - default_simulation_allocation_options = SimulationAllocationOptions - default_simulation_distributing_options = SimulationDistributingOptions datelist = pd.date_range(start="1/1/1989", end="1/1/2013", freq="W") # Act @@ -678,8 +692,6 @@ def test_import_from_imod5__correct_well_type(imod5_dataset): imod5_data, period_data, datelist, - default_simulation_allocation_options, - default_simulation_distributing_options, ) # Set layer back to right value (before AssertionError might be thrown) imod5_data["wel-WELLS_L3"]["layer"] = original_wel_layer From 6ca030feb5975c47adb81ce2405762820c397efe Mon Sep 17 00:00:00 2001 From: JoerivanEngelen Date: Wed, 6 May 2026 11:59:47 +0200 Subject: [PATCH 2/3] Update changelog --- docs/api/changelog.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/api/changelog.rst b/docs/api/changelog.rst index e71ba80b4..0dd6c8165 100644 --- a/docs/api/changelog.rst +++ b/docs/api/changelog.rst @@ -20,7 +20,8 @@ Added - Added :meth:`imod.msw.MetaSwapModel.split` to split MetaSWAP models. - Added :meth:`imod.mf6.HorizontalFlowBarrierResistance.from_imod5_data` to load barriers from 3D GEN files. - +- Added ``name`` argument to:meth:`imod.mf6.Modflow6Simulation.from_imod5_data` + to provide custom name to imported simulation and model. Fixed ~~~~~ From b0def9ea01159a7a9c8849e350a2cffe64b87d31 Mon Sep 17 00:00:00 2001 From: JoerivanEngelen Date: Wed, 6 May 2026 12:05:49 +0200 Subject: [PATCH 3/3] Provide custom name to simulation and model --- imod/mf6/simulation.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/imod/mf6/simulation.py b/imod/mf6/simulation.py index 6e73257b8..b2d254b7e 100644 --- a/imod/mf6/simulation.py +++ b/imod/mf6/simulation.py @@ -1857,7 +1857,13 @@ def from_imod5_data( >>> imod5_data, period_data, times, regridder_types=regridder_types, target_grid=target_grid >>> ) + Provide custom name to the simulation and model: + >>> mf6_sim = imod.mf6.Modflow6Simulation.from_imod5_data( + >>> imod5_data, period_data, times, name="custom" + >>> ) + >>> print(mf6_sim.name) # prints "custom_simulation" + >>> gwf_model = mf6_sim["custom_model"] """ if allocation_options is None: allocation_options = SimulationAllocationOptions()