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 #1260 from imod5 data metaswap #1335

Open
wants to merge 18 commits into
base: master
Choose a base branch
from

Conversation

JoerivanEngelen
Copy link
Contributor

Fixes #1260

Description

Adds MetaSwapModel.from_imod5_data

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

Fixes #1285 

# Description

- This PR implements ``GridData.from_imod5_data``, which has the
following requirements:
  - Area: Split area in rural & urban area
  - Active: Split where active/inactive
  - Landuse: Set urban_landuse to 18
  - Rootzone thickness: convert from centimeter to meter
- Refactors the ``test_grid_data.py`` to separate cases, reduces code
duplication
- Add unittest for ``GridData.from_imod5_data``

It has a arguments for regridding, but these don't do anything yet. I
wasn't sure if I should keep this to already have a future-proof
signature, or not add these, as the regridder arguments only confuse
people. I don't think regridding the MetaSWAP iMOD5 grids (like we do
with MODFLOW6 data) is a part of iMOD Python now, as we are first
focusing on the LHM, for which this is not a hard requirement.

# Checklist
<!---
Before requesting review, please go through this checklist:
-->

- [x] Links to correct issue
- [ ] Update changelog, if changes affect users
- [x] PR title starts with ``Issue #nr``, e.g. ``Issue #737``
- [x] Unit tests were added
- [ ] **If feature added**: Added/extended example
Fixes #1288

# Description

* Adds Ponding.from_imod5_data
* Adds msw.utilities namespace to put useful utility functions in
* Rename _concat_subunits to concat_imod5, as it is a very imod5
specific function.
Fixes #1290

# Description
Adds from_imod5_data classmethod.

Requirements:

* Set runon/runoff resistance to downward/upward resistance respectively
* Set extra storage coefficient and bottom resistance to 1
* If resistance smaller than 5.0, deactivate resistance by setting it to
MetaSWAP nodata value.

I also added the ``upward_resistance`` and ``downward_resistance`` to
the list with grids which have a subunit coordinate, as a comment in
@HendrikKok's script mentioned this was missing, and a required feature.
Fixes #1292

# Description
Context: MetaSWAP can map meteorological grids, which have a coarser
grid but a very fine time resolution, to its svats.
The ``mete_grid.inp`` file contains paths to meteorological information,
stored in ASCII grids, and there are separate mapping files
``"svat2precgrid.inp"`` and ``"svat2etrefgrid.inp"``. Nota bene:
MetaSWAP has hardcoded filenames for packages, hence why I can search
for "mete_grid.inp".

Adds the following:
- A ``MeteoGridCopy`` class to copy "mete_grid.inp" files, to avoid
having to read and write the crazy amount of meteo files that exist in
existing databases.
- A ``MeteoMapping.from_imod5_data`` method which looks for the first
ascii grid in the ``mete_grid.inp`` file, and reads that to derive
mappings from meteorological cell to metaswap grid cell.
- Add ``Imod5DataDict`` type alias, which can be implemented for other
``from_imod5_data`` methods in the future.
Fixes #1313

# Description
Construct an rch-package from iMOD5 data in the CAP package, loaded with
the ``open_projectfile_data`` function. Package is
used to couple MODFLOW6 to MetaSWAP models. Active cells will have a
recharge rate of 0.0.

At the moment, MetaSWAP can only be coupled to the first layer, as this
is also the case for ``primod``. iMOD Coupler these days supports
coupling to other layers as well, but ``primod`` doesn't. Picking this
up for iMOD Python and ``primod`` is worthy a separate story.

In detail:
- Add ``Recharge.from_imod5_cap_data`` class method, to construct an
empty Recharge package with 0.0 rate.
- Minor refactor: Put ``GridData`` helper functions to
``msw/utilities/imod5_converter.py``, so that they can be reused.

# Checklist

- [x] Links to correct issue
- [x] Update changelog, if changes affect users
- [x] PR title starts with ``Issue #nr``, e.g. ``Issue #737``
- [x] Unit tests were added
- [ ] **If feature added**: Added/extended example
Fixes #1311

# Description

Adds the following:

- ``imod.mf6.LayeredWell.from_imod5_cap_data``, to construct
LayeredWells for MODLOW6 from the CAP package in iMOD5 Data. Throws an
error if data is provided as point data (IPF, which is read as pandas
DataFrame). This has rate 0.0, actual rates will be inserted by in the
coupling scheme of iMOD Coupler.
- ``imod.mf6.GroundwaterFlowModel.from_imod5_data`` adds Sprinkling well
if CAP package present. This does not affect MODFLOW6 model if not
coupled to MetaSWAP: The wells have rates 0.0, so will not affect the
simulation results.
- ``Sprinkling.from_imod5_data`` to construct a Sprinkling package from
iMOD5 data.

# Checklist
<!---
Before requesting review, please go through this checklist:
-->

- [x] Links to correct issue
- [x] Update changelog, if changes affect users
- [x] PR title starts with ``Issue #nr``, e.g. ``Issue #737``
- [x] Unit tests were added
- [ ] **If feature added**: Added/extended example
Fixes #1320

# Description
The iMOD5 projectfile contains an "EXTRA" section, with files to copy.
These files usually contain settings and lookup tables for MetaSWAP,
which have no direct relation to cell data.

This PR adds CopyFiles package to copy these files.

# Checklist
- [x] Links to correct issue
- [x] Update changelog, if changes affect users
- [x] PR title starts with ``Issue #nr``, e.g. ``Issue #737``
- [x] Unit tests were added
- [ ] **If feature added**: Added/extended example
Fixes #1324

# Description
Adds a ``ScalingFactors.from_imod5_data`` method. I think, the final
missing constructor method.
Scaling factors for urban areas are set 1.0, not sure if iMOD5 does this
as well @HendrikKok?

# Checklist
- [x] Links to correct issue
- [ ] Update changelog, if changes affect users
- [x] PR title starts with ``Issue #nr``, e.g. ``Issue #737``
- [x] Unit tests were added
- [ ] **If feature added**: Added/extended example
Fixes #1316

# Description
Adds ``MetaSwapModel.from_imod5_data``, currently only models can be
written by turning off validation, that is still something to pick up.

- Adds ``MetaSwapModel.from_imod5_data``
- Converts ``Imod5DataDict`` TypeAlias to TypedDict, with which we can
avoid a lot of type casting.
- Add masking and broadcasting utilities for MetaSWAP iMOD5 data. I
could not easily make calls to the MODFLOW6 utilities for masking, as
these assumed presence of a layer coordinate and had logic to deal with
that, which is irrelevant for MetaSWAP.
- Adds ``MetaSwapActive`` dataclass to store masks
- Allow user-defined ``settings`` upon initialization, instead of only
supporting default settings.
- Add ``validate`` argument to ``MetaSwapModel.write`` to turn off model
validation upon writing.

# Checklist
- [x] Links to correct issue
- [x] Update changelog, if changes affect users
- [x] PR title starts with ``Issue #nr``, e.g. ``Issue #737``
- [x] Unit tests were added
- [ ] **If feature added**: Added/extended example
Copy link

sonarcloud bot commented Dec 13, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
8.0% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

Copy link
Collaborator

@Manangka Manangka left a comment

Choose a reason for hiding this comment

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

Blind review. Already reviewed changes

@JoerivanEngelen JoerivanEngelen added this pull request to the merge queue Dec 13, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 13, 2024
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.

Add from_imod5_data method to MetaSwapModel
2 participants