Skip to content

Mask inactive parent cells from 3D interpolation - #148

Closed
ntdosch wants to merge 16 commits into
DOI-USGS:developfrom
ntdosch:mask_inactive_parent
Closed

ntdosch wants to merge 16 commits into
DOI-USGS:developfrom
ntdosch:mask_inactive_parent

Conversation

@ntdosch

@ntdosch ntdosch commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #139.

Tmr._source_grid_mask previously selected interpolation source points using only the spatial window around the inset boundary. It did not account for the parent model's active-cell array, so inactive parent cells were passed to the 3D interpolator as if they held valid heads. Those cells carry inactive values (HNOFLO/HDRY in MODFLOW-NWT, or 1e30/-1e30 for inactive/dry cells in MODFLOW 6), which get included in the interpolated perimeter boundary heads at nearby inset cells.

This PR intersects the spatial mask with the parent's idomain/ibound so that only active parent cells are used as interpolation source points.

Changes

mfsetup/tmr.py

  • In the _source_mask construction, the 3D spatial mask is now combined with the parent's active-cell array:
    • MODFLOW 6: keep cells where idomain > 0 (excludes idomain == 0 inactive and idomain == -1 pass-through cells, neither of which has valid heads).
    • MODFLOW-NWT: keep cells where ibound != 0 (excludes inactive cells while retaining constant-head cells, ibound == -1, which do hold valid heads).
  • The idomain/ibound array is padded by one layer on top and bottom (edge replication) so it aligns with the existing +2 vertical padding of mask3d.
  • Handles cases where idomain/ibound is None or not a 3D array (i.e., all cells active), so models without an explicit active-cell array are unaffected.

Tests

mfsetup/tests/test_tmr.py:

  • New fixtures parent_model_mf6_with_inactive and parent_model_nwt_with_inactive that build and run parent models with a small inactive cell cluster placed just outside the inset footprint but inside the source-mask buffer, so those cells would be included in interpolation if not masked.
  • test_source_grid_mask_excludes_inactive_mf6: asserts every idomain == 0 cell is excluded from _source_grid_mask, and that the resulting interpolated boundary heads contain no NaNs or unreasonably low (inactive-like) values.
  • test_source_grid_mask_excludes_inactive_nwt: asserts ibound == 0 cells are excluded while a constant-head cell (ibound == -1) inside the spatial window is retained, and that interpolated heads remain physically reasonable.

dependabot Bot and others added 16 commits January 5, 2026 10:56
Bumps [actions/checkout](https://github.com/actions/checkout) from 5 to 6.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](actions/checkout@v5...v6)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 4 to 6.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](actions/upload-artifact@v4...v6)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [JamesIves/github-pages-deploy-action](https://github.com/jamesives/github-pages-deploy-action) from 4.7.2 to 4.7.6.
- [Release notes](https://github.com/jamesives/github-pages-deploy-action/releases)
- [Commits](JamesIves/github-pages-deploy-action@v4.7.2...v4.7.6)

---
updated-dependencies:
- dependency-name: JamesIves/github-pages-deploy-action
  dependency-version: 4.7.6
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Bumps [JamesIves/github-pages-deploy-action](https://github.com/jamesives/github-pages-deploy-action) from 4.7.6 to 4.8.0.
- [Release notes](https://github.com/jamesives/github-pages-deploy-action/releases)
- [Commits](JamesIves/github-pages-deploy-action@v4.7.6...v4.8.0)

---
updated-dependencies:
- dependency-name: JamesIves/github-pages-deploy-action
  dependency-version: 4.8.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
 * re-adjust SFR package layering each time idomain is adjusted, to prevent SFR in inactive cells (SFR reaches with no groundwater connections)
 * write SFR Package shapefiles when MODFLOW input is written, so that the shapefiles reflect the final state of the SFR package
 * fix some lingering pandas delim_whitespace=True args
 * add --no-deps to pip reinstall of flopy from latest release; apparently this was clobbering the conda installs of pandas and other packages on the Windows CI runs
…SourceData.from_config with individual raster input for recharge.
…>.gpkg|layername=<layer name> or filename>.gpkg|layer=<layer name>), for example as a way to specify the active model extent (e.g. in the source_data: idomain: block for Modflow 6 models)
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 6 to 7.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](actions/upload-artifact@v6...v7)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-version: '7'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
…pi.types.is_string_dtype() and other misc fixes
…with --no-deps to prevent reinstall of pandas < 3
Bumps [mamba-org/setup-micromamba](https://github.com/mamba-org/setup-micromamba) from 1 to 3.
- [Release notes](https://github.com/mamba-org/setup-micromamba/releases)
- [Commits](mamba-org/setup-micromamba@v1...v3)

---
updated-dependencies:
- dependency-name: mamba-org/setup-micromamba
  dependency-version: '3'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 98.57143% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.59%. Comparing base (8571531) to head (536fead).

Files with missing lines Patch % Lines
mfsetup/tests/test_tmr.py 98.47% 2 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #148      +/-   ##
===========================================
+ Coverage    89.48%   89.59%   +0.11%     
===========================================
  Files           67       66       -1     
  Lines        13200    13332     +132     
===========================================
+ Hits         11812    11945     +133     
+ Misses        1388     1387       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@aleaf

aleaf commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

thanks @ntdosch! I folded this in using the command line.

@aleaf aleaf closed this Oct 27, 2026
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.

Tmr._source_grid_mask does not exclude inactive parent cells

3 participants