Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/api/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
~~~~~
Expand Down
18 changes: 15 additions & 3 deletions imod/mf6/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
-------
Expand Down Expand Up @@ -1853,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()
Expand All @@ -1866,8 +1876,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,
Expand All @@ -1880,11 +1891,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
Expand Down
20 changes: 16 additions & 4 deletions imod/tests/test_mf6/test_mf6_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -669,17 +685,13 @@ 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
simulation = Modflow6Simulation.from_imod5_data(
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
Expand Down
Loading