Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #1041 import simulation #1059

Merged

Conversation

luitjansl
Copy link
Contributor

Fixes #1041

Description

Adds a function that imports a simulation from an imod5 project file. It creates a simulation, containing 1 GroundwaterFlowModel, containing the packages for which we support importing currently. This includes the mandatory flow packages like NPF and STO, and some boundary conditions (like DRN and RCH) but not yet CHD or WEL.

Checklist

  • Links to correct issue
  • Update changelog, if changes affect users
  • PR title starts with Issue #nr, e.g. Issue #737
  • Unit tests were added
  • If feature added: Added/extended example

luitjansl and others added 20 commits May 21, 2024 14:28
…version

# Conflicts:
#	imod/mf6/rch.py
#	imod/tests/fixtures/backward_compatibility_fixture.py
#	imod/tests/test_mf6/test_mf6_rch.py
#	imod/tests/test_typing/test_typing_grid.py
#	imod/typing/grid.py
review comment

Co-authored-by: Joeri van Engelen <[email protected]>
review comment

Co-authored-by: Joeri van Engelen <[email protected]>
…_simulation

# Conflicts:
#	imod/tests/test_typing/test_typing_grid.py
#	imod/typing/grid.py
review comment

Co-authored-by: Joeri van Engelen <[email protected]>
review comment

Co-authored-by: Joeri van Engelen <[email protected]>
review comment

Co-authored-by: Joeri van Engelen <[email protected]>
@luitjansl luitjansl changed the base branch from master to imod5_converter_feature_branch May 27, 2024 14:01
@luitjansl luitjansl requested a review from JoerivanEngelen May 27, 2024 14:12
Copy link
Contributor

@JoerivanEngelen JoerivanEngelen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, approving in advance, since I'm not going to be so active the coming 10 days. My main points are the quite long variable names for the simulation options and the missing docstrings, could you fix/implement those?

default_simulation_allocation_options: SimulationAllocationOptions,
default_simulation_distributing_options: SimulationDistributingOptions,
regridder_types: Optional[dict[str, tuple[RegridderType, str]]] = None,
) -> "GroundwaterFlowModel":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a docstring to the method, explaining what it does

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, added the docstring

Comment on lines 175 to 176
default_simulation_allocation_options: SimulationAllocationOptions,
default_simulation_distributing_options: SimulationDistributingOptions,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These variable names are quite long. I think going with this is fine:

Suggested change
default_simulation_allocation_options: SimulationAllocationOptions,
default_simulation_distributing_options: SimulationDistributingOptions,
allocation_options: SimulationAllocationOptions,
distributing_options: SimulationDistributingOptions,

The type annotation hints that we are expecting a certain object and you can describe this also in the docstring. Furthermore, the plural options subtly hints that this is something different then option used for specific packages.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines +184 to +194
# import npf
npf_pkg = NodePropertyFlow.from_imod5_data(imod5_data, grid, regridder_types)

# import sto
sto_pkg = StorageCoefficient.from_imod5_data(imod5_data, grid, regridder_types)

# import initial conditions
ic_pkg = InitialConditions.from_imod5_data(imod5_data, grid, regridder_types)

# import recharge
rch_pkg = Recharge.from_imod5_data(imod5_data, dis_pkg, regridder_types)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this looks very clean and readable!

Comment on lines 203 to 204
oc = OutputControl(save_head="last", save_budget="last")
result["oc"] = oc
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be more consistent with iMOD5, we can make the user responsible for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 1322 to 1323
default_simulation_allocation_options: SimulationAllocationOptions,
default_simulation_distributing_options: SimulationDistributingOptions,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem, long argument name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

default_simulation_allocation_options: SimulationAllocationOptions,
default_simulation_distributing_options: SimulationDistributingOptions,
regridder_types: Optional[dict[str, tuple[RegridderType, str]]] = None,
) -> "Modflow6Simulation":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add a docstring for this method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines +7 to +8
@dataclass()
class SimulationAllocationOptions:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@@ -0,0 +1,40 @@
from dataclasses import dataclass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: changing the dataclass to pydantic dataclass, would be as easy as:

Suggested change
from dataclasses import dataclass
from pydantic.dataclasses import dataclass

You can make this change when PR #1054 is merged, probably not for this PR.



@pytest.mark.usefixtures("imod5_dataset")
def test_import_from_imod5(imod5_dataset, tmp_path):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we also going to add a test to see if it runs? Or do we assume our validation is good enough to capture all input mistakes, and save some precious CI time? I'm open to both options.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried if it runs (it does), but I didn't add it to the test because that adds 20 seconds or so to the test run time.

@luitjansl luitjansl merged commit a31d86f into imod5_converter_feature_branch May 30, 2024
7 checks passed
@luitjansl luitjansl deleted the issue_#1041_import_simulation branch May 30, 2024 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create Modflow6Simulation.from_imod5_data method
2 participants