Skip to content

Issue #1787 mask topsystem packages - #1918

Open
JoerivanEngelen wants to merge 29 commits into
masterfrom
issue_#1787_mask_topsystem_packages
Open

JoerivanEngelen wants to merge 29 commits into
masterfrom
issue_#1787_mask_topsystem_packages

Conversation

@JoerivanEngelen

@JoerivanEngelen JoerivanEngelen commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1787

Description

Context
iMOD5 masked topsystem packages (Recharge, Drainage, River, and GeneralHeadBoundary) and MetaSWAP models, wherever the IBOUND array was < 0. In these cells, ConstantHead packages are added, which can lead to short-circuits if two of these boundary conditions are placed in the cell.

This PR:

  • Masks topsystem packages where IBOUND < 0.
  • Masks MetaSWAP model where IBOUND < 0, for this I also had to make sure that the IBOUND array was also pre-processed as the iMOD5 CAP data: namely regridded and ensured that the layer dimension was dropped.
  • While I was at it, I also let the .clip_box method mask topsystem packages where constant head cells are placed, to prevent short-circuits there as well.
  • Adds convenience method Modflow6Model.mask_packages to public API, which allows providing a list of packages to be masked
  • Adds a ITopSystemBoundaryCondition interface, to allow instance checks in utility functions without circular imports
  • Refactor to declutter: Move boundary condition utility functions on model objects from imod.mf6.model module to imod.mf6.utilities.clipped_bc_creator module.

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

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.

Copilot review overview

🟡 Changes recommended

Unresolved critical and moderate findings remain in conversion, masking, and test integration.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 5 High severity · 1 Medium severity

Open (6)
What changed in this PR

Adds IBOUND-based masking for topsystem and MetaSWAP packages, selective package masking, and clipped-boundary refactoring.

Changes:

  • Regrids and applies IBOUND masks.
  • Adds mask_packages and topsystem interfaces.
  • Updates conversion, clipping, tests, fixtures, and documentation.
File Summary
imod/​util/​dims.py Handles BND layer dimensions.
imod/​typing/​__init__.py Adds BND typing.
imod/​tests/​test_msw/​test_utilities/​test_msw_mask_util.py Tests MetaSWAP masking.
imod/​tests/​test_msw/​test_grid_data.py Tests IBOUND-based activity.
imod/​tests/​test_mf6/​test_utilities/​test_mf6_mask_util.py Tests topsystem masking.
imod/​tests/​test_mf6/​test_utilities/​test_mf6_clipped_boundary_condition_creator.py Updates clipped-boundary tests.
imod/​tests/​test_mf6/​test_mf6_simulation.py Tests imported topsystem masking.
imod/​tests/​test_mf6/​test_mf6_model.py Updates clipping tests; critical finding (2 votes): references the removed helper.
imod/​tests/​test_mf6/​test_ex01_twri.py Tests clipping-related masking.
imod/​tests/​fixtures/​msw_imod5_cap_fixture.py Adds BND fixture data.
imod/​tests/​fixtures/​imod5_cap_data.py Adds BND fixture data.
imod/​msw/​utilities/​imod5_converter.py Applies IBOUND masking; nit (1 vote): incorrect BND annotation.
imod/​msw/​regrid/​regrid_schemes.py Adds IBOUND regridding.
imod/​msw/​grid_data.py Uses BND data for active-cell determination.
imod/​mf6/​utilities/​mask.py Adds topsystem masking; critical finding (4 votes): optional purge flag lacks a default.
imod/​mf6/​utilities/​imod5_converter.py Masks imported topsystem packages; critical finding (1 vote): default regrid method lacks ibound.
imod/​mf6/​utilities/​clipped_bc_creator.py Refactors clipped-boundary creation.
imod/​mf6/​topsystem.py Implements the topsystem interface.
imod/​mf6/​regrid/​regrid_schemes.py Adds BND regridding settings.
imod/​mf6/​rch.py Incorporates BND data in recharge conversion.
imod/​mf6/​model.py Adds selective masking and clipping integration; critical finding (1 vote) concerns the removed helper, and moderate findings (2 and 1 votes) concern incomplete purging and only evaluating time zero.
imod/​mf6/​model_gwf.py Applies IBOUND masking during import.
imod/​common/​utilities/​regrid.py Regrids CAP and BND data; critical finding (3 votes): unconditional BND lookup breaks CAP-only inputs.
imod/​common/​utilities/​mask.py Supports package-specific masking.
imod/​common/​interfaces/​itopsystembc.py Adds the topsystem interface.
imod/​common/​interfaces/​imodel.py Extends the model interface.
docs/​api/​mf6.rst Documents selective masking.
docs/​api/​changelog.rst Documents behavior and API changes.

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

Comment thread imod/common/utilities/regrid.py
Comment thread imod/mf6/model.py
Comment thread imod/mf6/utilities/imod5_converter.py
Comment thread imod/mf6/utilities/mask.py
Comment thread imod/tests/test_mf6/test_mf6_model.py
Comment thread imod/mf6/model.py
@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

No deployments
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.

Mask topsystem packages where IBOUND == -1

2 participants