Add HFB package builder from dataframes#565
Conversation
dbrakenhoff
left a comment
There was a problem hiding this comment.
Looks good to me!
Seeing this reminds me that flopy now has HFB logic: modflowpy/flopy#2745
So I'm not sure how robust our algorithm is, but it could be worth exploring deferring the logic for building the HFBs to flopy? And on a similar note, I at some point added the line_to_hfb_buffer method that was supposed to be more robust and faster for more complex HFBs. I don't know if I actually succeeded, but it could be worth checking out this method as well...
But feel free to open a new issue to tackle those questions :)
Thanks for the review! And I'm all in favor, but that would require pinning flopy to something recent. Could that cause any issues with other users? As for the linting/formatting, I'll update that. I think I was developing from a different folder so that ruff didn't pick up on the formatting configuration file. |
Good question. I don't really think so since flopy mostly manages I/O and backwards compatibility is something they take very seriously. |
|
Thanks for the pointer to modflowpy/flopy#2745. I updated this PR to use that FloPy logic instead of maintaining nlmod's own line-routing path for the new package-builder workflow. Changes since your review:
Local validation passed with FloPy |
|
As far as I can tell there is no option to disable the trailing comma in multiline calls in the ruff configuration. Apparently, this complies with the standard, but also nlmod's, formatting rules |
|
Hi David and others,
|
|
Yeah, ideally we release this only when flopy releases with the hfb utils and pin nlmod to use the newest flopy? From issues on flopy I gather the next release should happen in the next 1-2 weeks, so we won't have to wait that long? So fine by me to merge this into dev, and hold our next release (which we really should do) until flopy has made theirs. |
There was a problem hiding this comment.
Pull request overview
Implements an end-to-end workflow for creating MODFLOW 6 Horizontal Flow Barrier (HFB) packages from line GeoDataFrames in nlmod, delegating line-to-cell-pair routing to FloPy while keeping nlmod-specific hydchr scaling and inactive/pass-through filtering.
Changes:
- Added
nlmod.gwf.hfb.hfb_from_dfplus supporting helpers, and updatedget_hfb_spdto useflopy.utils.make_hfb_array. - Deprecated legacy line-routing helpers (
line_to_hfb,line2hfb,line_to_hfb_buffer) and updated tests accordingly. - Switched
flopydependency to a VCS URL targeting thedevelopbranch to access the new utility.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
nlmod/gwf/hfb.py |
Adds the DataFrame-to-HFB builder, routes via FloPy make_hfb_array, and introduces deprecation warnings for legacy routing helpers. |
tests/test_023_hfb.py |
Adds/updates tests for hfb_from_df, FloPy routing delegation, scaling behavior, geometry handling, and deprecation warnings. |
pyproject.toml |
Changes flopy dependency to track FloPy develop to obtain the new HFB routing utility. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| requires-python = ">= 3.10" | ||
| dependencies = [ | ||
| "flopy>=3.10.0", | ||
| "flopy @ git+https://github.com/modflowpy/flopy.git@develop", # HFB utility from flopy#2745, to be released in flopy>3.10.0 |
The full workflow from GeoDataFrame line features to a FloPy HFB package is implemented in nlmod, while delegating the horizontal line-to-cell routing to FloPy.
Summary
nlmod.gwf.hfb.hfb_from_dfto build MF6 HFB packages from line GeoDataFramesflopy.utils.make_hfb_arrayfrom Feat(hfb_util): add method for creating HFBs modflowpy/flopy#2745hydchrscaling andidomain <= 0filtering around the FloPy-generated cell pairsdevelopuntil the HFB utility from flopy#2745 is available in a release (flopy>3.10.0)Validation
python -m py_compile nlmod\gwf\hfb.pypython -m ruff format nlmod\gwf\hfb.py tests\test_023_hfb.pypython -m ruff check --fix nlmod\gwf\hfb.py tests\test_023_hfb.pypython -m pytest tests\test_023_hfb.py -vpython -m prospector nlmod\gwf\hfb.py tests\test_023_hfb.pybandit -q -r nlmod\gwf\hfb.pyflopy.utils.make_hfb_array