Skip to content

Issue #1835 sprinkling from ipf - #1883

Open
JoerivanEngelen wants to merge 51 commits into
masterfrom
issue_#1835_sprinkling_from_ipf
Open

Issue #1835 sprinkling from ipf#1883
JoerivanEngelen wants to merge 51 commits into
masterfrom
issue_#1835_sprinkling_from_ipf

Conversation

@JoerivanEngelen

@JoerivanEngelen JoerivanEngelen commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Fixes #1835

Description

Adds experimental support for SprinklingPoints class

Changes the following things:

  • Add SprinklingPoints class, to specify a n:1 coupling of grid cells to points.
  • Rename Sprinkling class to SprinklingGrid class, deprecate Sprinkling class. I had to keep the API stable as primod relies on the existence of the Sprinkling class.
  • As primod relies on a call to MetaSwapModel.get_pkg_type(Sprinkling), I had to modify the code somewhat, so that it returns the key of the sprinkling package regardless whether it is a SprinklingPoints or a SprinklingGrid
  • Add LayeredWell.from_imod5_cap_data to construct a MODFLOW6 well package from the iMOD5 data under the CAP header.
  • Pass on well id to the Mf6Wel class' dataset. This is used to map MODFLOW6 wells to MetaSWAP wells. It can furthermore be used in the future to add as auxiliary variable in well files in the future to have some metadata in the MODFLOW6 well file.
  • Refactor of the test module imod/tests/test_msw/test_sprinkling.py: Separate the test cases from the tests.
  • Boyscouting: Replace some calls of .values to to_numpy()
  • Boyscouting: Replace some calls of .values[()] to the safer enforce_scalar_data

This still has to be tested whether it works with the Peelvenen model, I'll do that in follow-up issue #1908 , where I'll also add a larger regression/user_acceptance test for our Weekly tests.

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
  • If feature added: Added feature to API documentation
  • If pixi.lock was changed: Ran pixi run generate-sbom and committed changes

@JoerivanEngelen
JoerivanEngelen marked this pull request as ready for review August 20, 2026 14:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds experimental MetaSWAP “sprinkling from IPF” support by introducing a point-based sprinkling package, while keeping the legacy Sprinkling API stable via deprecation and a new SprinklingGrid implementation. This also extends MF6 well conversion from iMOD5 CAP point data and threads stable well IDs through Mf6Wel to support coupling.

Changes:

  • Introduce msw.SprinklingPoints (IPF-based n:1 coupling) and msw.SprinklingGrid; deprecate msw.Sprinkling.
  • Extend iMOD5 CAP → MF6 well conversion to support point (IPF) inputs and propagate well id into Mf6Wel.
  • Refactor/expand sprinkling-related tests and modernize some .values usage to .to_numpy() / scalar enforcement.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
imod/tests/test_msw/test_sprinkling.py Refactors/expands sprinkling tests to cover grid + new point-based sprinkling and updated API names.
imod/tests/test_msw/test_coupler_mapping.py Updates helper to construct Mf6Wel with the new id argument.
imod/tests/test_mf6/test_mf6_wel.py Updates CAP point-data test to validate LayeredWell.from_imod5_cap_data() now supports IPF.
imod/tests/test_mf6/test_mf6_wel_lowlvl.py Updates low-level Mf6Wel tests to pass id.
imod/tests/fixtures/msw_model_fixture.py Switches fixture sprinkling package to SprinklingGrid and passes well IDs to Mf6Wel.
imod/tests/fixtures/imod5_cap_data.py Adjusts CAP sprinkling point fixture contents/column ordering.
imod/msw/utilities/imod5_converter.py Adds typed helpers and conversion logic for sprinkling-from-points vs sprinkling-from-grids.
imod/msw/sprinkling.py Introduces SprinklingBase, implements SprinklingGrid + new SprinklingPoints, and deprecates Sprinkling.
imod/msw/regrid/regrid_schemes.py Adds SprinklingPointsRegridMethod for regridding the points-based sprinkling mapping grid.
imod/msw/model.py Dispatches sprinkling import based on grid vs points and adjusts package-key resolution to remain compatible with legacy Sprinkling type usage.
imod/msw/init.py Exposes SprinklingGrid/SprinklingPoints and keeps deprecated Sprinkling in the public API.
imod/mf6/wel.py Replaces some .values usages, enforces scalar settings safely, and makes from_imod5_cap_data target discretization optional for point inputs.
imod/mf6/utilities/imod5_converter.py Implements CAP point-data well extraction and makes target_dis optional (required only for grid inputs).
imod/mf6/mf6_wel_adapter.py Adds id as optional/extra dataset data for Mf6Wel to support downstream well-to-sprinkling mapping.
docs/api/msw.rst Updates MSW API docs to list SprinklingGrid and SprinklingPoints.
docs/api/changelog.rst Adds changelog entries for new sprinkling-from-points support and sprinkling deprecation/rename.
Suppressed comments (1)

imod/msw/sprinkling.py:506

  • The TypeError message still directs users to imod.msw.Sprinkling.from_imod5_data(), but the correct non-point entry point is SprinklingGrid.from_imod5_data() (with Sprinkling being deprecated).
                Unsupported format for artificial_recharge_layer: expected a
                DataFrame for point data (IPF), got a grid (IDF). Call
                imod.msw.Sprinkling.from_imod5_data() instead.
                """

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread imod/msw/sprinkling.py
Comment on lines +88 to 90
sprinkling_points_df = (
sprinkling_dataset[points_keys].drop_vars(["dx", "dy"]).to_dataframe()
)
Comment thread imod/msw/sprinkling.py Outdated
Comment thread imod/msw/sprinkling.py Outdated
Comment thread imod/mf6/mf6_wel_adapter.py
Comment thread imod/msw/regrid/regrid_schemes.py
Comment thread docs/api/changelog.rst Outdated
Comment thread docs/api/changelog.rst Outdated
JoerivanEngelen and others added 5 commits August 20, 2026 17:40
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@sonarqubecloud

Copy link
Copy Markdown

❌ The last analysis has failed.

See analysis details on SonarQube Cloud

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.

[FEATURE] - MetaSwapModel.from_imod5_data sprinkling from IPF files

2 participants