Skip to content

Issue #1757 Support linearrings in GEN files and MODFLOW6 HFBs - #1956

Open
LuukBlom wants to merge 11 commits into
masterfrom
feat/hfb-support-for-linearrings
Open

LuukBlom wants to merge 11 commits into
masterfrom
feat/hfb-support-for-linearrings

Conversation

@LuukBlom

@LuukBlom LuukBlom commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Fixes #1757

Description

iMOD5 supported HFBs as linearrings in GEN files, and some models rely on GEN
files with both linestrings and linearrings. MODFLOW6 HFBs only accepted
linestrings. This PR adds the following:

  • GEN reader (imod.gen.read, ASCII): linestrings and closed rings are now
    converted to shapely geometries separately and merged back in file order. This
    fixes reading files with both. Closed rings are read as polygons. A closed
    feature with fewer than 4 vertices stays a linestring.
  • iMOD5 HFB converter
    (SingleLayerHorizontalFlowBarrierResistance.from_imod5_data): polygons are
    converted to LinearRings using the exterior ring. Interior rings are dropped.
    The input GeoDataFrame is not mutated.
  • MODFLOW6: the single-layer HFB classes
    (...Resistance, ...Multiplier, ...HydraulicCharacteristic) accept
    LinearRing geometries, for example for building pits. Polygons are still
    rejected.

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

Executable validation

Since I've just reinstalled everything on my new laptop, I forgot to put the modflow6 bin dir in my PATH.
This was not clear from errors in the tests though, and let to some cryptic subprocess.Popen Errors.

Now, Modflow6Simulation.run resolves the executable through a new _validate_mf6_executable, which does the exact same thing as before when not providing anything, just with better error messages. Precedence is mf6path argument, then the MODFLOW6_EXECUTABLE variable, then mf6 on the PATH. It raises descriptive errors when the executable is missing, is a directory, or is not executable.

Did this while waiting for tests to run, and is somewhat unrelated to this PR, so can also make a separate PR if preferred?

@JoerivanEngelen JoerivanEngelen 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.

This is a very good step, which turns out to be a lot less work than I expected. What I'm still missing is also adding this to the HFB objects which are not assigned to a single layer. This included some complex back-and-forth between Z-polygons to avoid some shapely edge case behavior. I hope this will not cause too much extra trouble.

Comment thread imod/formats/gen/gen.py Resolved
Comment thread imod/mf6/hfb.py

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.

I'm surprised that our snapping functionality supports linearrings, and so little work is required! Long live xugrid, geopandas, and shapely I guess.

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.

Actually, what I'm still missing is the three other HFB packages, the ones which are not assigned to a single layer, but have a Z-coordinate as well. These have a more complex procedure computing the hydraulic characteristic, but I hope this is not a problem?

Comment thread imod/tests/test_mf6/test_mf6_hfb.py Outdated
Comment on lines +1145 to +1146
hfb.cleanup(dis)
assert hfb.line_data.geometry.length.sum() == pytest.approx(160.0)

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.

I think the intention of similar tests I added here was to first clip then call cleanup on the clipped object, which is not what is happening here? I'm not entirely sure what is happening here. It could be that the tests this is derived from are wrong as well, or intended to do this actually.

LuukBlom and others added 4 commits November 3, 2026 14:13
@sonarqubecloud

sonarqubecloud Bot commented Nov 5, 2026

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.

[FEATURE] - HFB support for iMOD5 models with linearrings

2 participants