Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modflowusg #1246

Closed
wants to merge 18 commits into from
Closed

modflowusg #1246

wants to merge 18 commits into from

Conversation

swfwmd
Copy link
Contributor

@swfwmd swfwmd commented Sep 24, 2021

Created new folder modflowusg.
Created mfusg.py file for ModflowUsg class
Created mfusgbcf.py file for ModflowUsgBcf class
Created mfusgcln.py file for ModflowUsgCln class
Created mfusggnc.py file for ModflowUsgGnc class
Created mfusglpf.py file for ModflowUsgLpf class
Created mfusgsms.py file for ModflowUsgSms class
Created mfusgwel.py file for ModflowUsgWel class

@langevin-usgs
Copy link
Contributor

@cnicol-gwlogic, can you help with this?

@cnicol-gwlogic
Copy link
Contributor

@langevin-usgs Yep I can help, apologies I did not get on to it earlier. I had been thinking through a plan for usg the last few days. I'll take a look at this today.

* move modflowdisu to modflowusg
* add deprecation warning to flopy.Modflow.load() for modflowusg models
* removed some modflowusg bits from flopy.Modflow; now in flopy.ModflowUsg instead
* utils.gridgen updated for this refactor
* several bug fixes so autotests will run
* autotests t005_test, t016_test, t038_test, t061_test_gridgen, t506_test updated for this
  refactoring

ModflowUsgLpf and ModflowUsgBcf still need refactoring / superclassing (from ModflowLpf
and ModflowBcf) to minimise code duplication. Possibly ModflowUsgWel too.
@cnicol-gwlogic
Copy link
Contributor

cnicol-gwlogic commented Sep 29, 2021

@langevin-usgs I've refactored a fair bit of this by inheriting from the modflow LPF/BFC/WEL classes from modflowusg - hopefully @swfwmd accepts my PR swfwmd/flopy#2. The tests should all run fine then. I think this leaves it all a bit cleaner if people want to add more exotic mfusg funcitionality.

Cheers. Happy to take suggestions for mods if anyone has them too.

@codecov
Copy link

codecov bot commented Sep 29, 2021

Codecov Report

Merging #1246 (ef4ef94) into develop (658bf2c) will increase coverage by 0.843%.
The diff coverage is 75.120%.

❗ Current head ef4ef94 differs from pull request most recent head 5326bdc. Consider uploading reports for the commit 5326bdc to get more accurate results

@@              Coverage Diff              @@
##           develop     #1246       +/-   ##
=============================================
+ Coverage   73.498%   74.341%   +0.843%     
=============================================
  Files          230       232        +2     
  Lines        50389     50900      +511     
=============================================
+ Hits         37035     37840      +805     
+ Misses       13354     13060      -294     
Impacted Files Coverage Δ
flopy/modflow/__init__.py 100.000% <ø> (ø)
flopy/mbase.py 70.552% <62.500%> (+0.168%) ⬆️
flopy/modflowusg/mfusgcln.py 65.349% <65.349%> (ø)
flopy/modflowusg/mfusg.py 74.157% <74.157%> (ø)
flopy/modflowusg/mfusgwel.py 74.242% <74.242%> (ø)
flopy/modflow/mf.py 68.526% <75.000%> (-0.363%) ⬇️
flopy/modflowusg/mfusgbcf.py 75.688% <75.688%> (ø)
flopy/modflowusg/mfusglpf.py 79.844% <79.844%> (ø)
flopy/modflowusg/mfusggnc.py 81.666% <81.666%> (ø)
flopy/utils/utils_def.py 86.666% <90.476%> (+1.159%) ⬆️
... and 25 more

@langevin-usgs
Copy link
Contributor

@swfwmd and @cnicol-gwlogic, nice job with this! I like how you override the structured modflow packages. This is wayyy cleaner, and gives you full control to support additional mfusg functionality without disturbing the modflow flopy code base. Looks like there is still some work to do with the test failures, but hopefully those won't be too hard to handle.

And one thing, I'd like to suggest. I see how you've shut off the add_package method for mfusg models for bcf, lpf, wel, etc. Could you make that more general by adding an add_package=True argument to those classes. Then when you call super() on those, you can set add_package=False. This keeps the add_package functionality generic and not specific to mfusg. Minor detail.

@mwtoews
Copy link
Contributor

mwtoews commented Oct 5, 2021

See #1238 which caused the conflicts, and introduced a pattern of simpler subclassing that should also apply to this PR.

@cnicol-gwlogic
Copy link
Contributor

Thanks @mwtoews. I've merged your latest stuff in and made the relevant changes in the mfusg files too as you suggest. @swfwmd just needs to pull my stuff in, then this PR should update.

Copy link
Contributor

@mwtoews mwtoews left a comment

Choose a reason for hiding this comment

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

Had a very quick skim, and found a few changes.

__all__ = [
" __version__",
"__author__",
"__author_email__" "modflow",
Copy link
Contributor

Choose a reason for hiding this comment

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

missing a , here, and on L47

Overrides the parent ModflowBcf object."""
msg = (
"Model object must be of type flopy.modflowusg.ModflowUsg\n"
+ "but received type: {type(model)}."
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
+ "but received type: {type(model)}."
f"but received type: {type(model)}."

this same edit applies 14 other times in this PR

raise Exception("mfcln: ja_cln must be provided")
if abs(self.ja_cln[0]) != 1:
raise Exception(
"mfcln: first ja_cln entry (node 1) is " "not 1 or -1."
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"mfcln: first ja_cln entry (node 1) is " "not 1 or -1."
"mfcln: first ja_cln entry (node 1) is not 1 or -1."

self.filenames.append(None)

# Fill namefile items
name = [ModflowUsgCln._ftype()]
Copy link
Contributor

@mwtoews mwtoews Oct 6, 2021

Choose a reason for hiding this comment

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

Within class methods like __init__(self, ..., this can simply be self._ftype(). Classmethods like load(cls, ...) it can be cls._ftype(). There ~17 "._ftype()" matches here that could potentially be simplified.

@langevin-usgs
Copy link
Contributor

Looks like there are some merge conflicts and codacy issues with this PR. I think it's getting close, though. Thanks @swfwmd, @cnicol-gwlogic, and @mwtoews. Not sure of the best path forward here. If you think the mfusg changes are clean and almost ready, then perhaps it's better to rebase or try fresh? The merged changes from other PRs are diluting the changes mfusg here.

@cnicol-gwlogic
Copy link
Contributor

Hi @langevin-usgs thanks and apologies, it's gettting a bit painful (and messy). Two questions on codacy: 1) is it only the critical issues that cause a fail? And 2) can I replicate those tests locally so I can check before I push? I tried running flake8 and pylint using the two commands from ci.yml but they give different outcomes. But yes, might be time for a fresh PR. Ta.

@langevin-usgs
Copy link
Contributor

So codacy seems to be overdoing things at the moment. I think you should try and fix what it finds, if possible. But ultimately, when you get to a point where you think the PR is ready to go, just let us know, and we can overlook minor codacy complaints. I would imagine there is a way to run codacy locally, but I'm not aware of how we would do it. We will probably have to have a discussion on our end on how to handle codacy issues in the future.

@jdhughes-usgs
Copy link
Contributor

I have revised the codacy failure criteria to only fail for major issues. So you can ignore anything that isn't major in the classes you have added (but it would be good to clean up any easily resolved issues).

@jdhughes-usgs
Copy link
Contributor

@cnicol-gwlogic @swfwmd what is the status of this PR? Should it be closed or is it still a work in progress?

@cnicol-gwlogic
Copy link
Contributor

@jdhughes-usgs - this can be closed, covered in #1261. Thanks.

@jdhughes-usgs
Copy link
Contributor

changes in PR #1261

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.

5 participants