Skip to content

Refactor layeringMod.py - #224

Open
mxkpp wants to merge 66 commits into
NGWPC-7625_PI_10_ngen_forcing_refactorfrom
maxkipp-refactor-layeringmod-py
Open

Refactor layeringMod.py#224
mxkpp wants to merge 66 commits into
NGWPC-7625_PI_10_ngen_forcing_refactorfrom
maxkipp-refactor-layeringmod-py

Conversation

@mxkpp

@mxkpp mxkpp commented Aug 19, 2026

Copy link
Copy Markdown

layeringMod.py functions layer_final_forcings and layer_supplemental_forcing each have been refactored into 1 abstract parent class, each implemented by a child class for each discretization type: "gridded", "unstructured", "hydrofabric".

Note on review and testing: the "hydrofabric" case is covered by the ngen-forcing pytest suite, and it was tested. However the "gridded" and "unstructured" cases are not covered by the ngen-forcing pytest suite. For those 2 types, their before-and-after logic was reviewed without testing.

Benefits of This Improvement:

  1. Clearly separate the variations in how the different discretization types are handled: "gridded", "unstructured", "hydrofabric". Previously the logic branching had been implemented via large if / elif / elif blocks.

  2. DRYify repeated logic into shared methods, improving readability and allowing future changes to be done more easily and safely with minimal copy-pasting.

  3. For the "unstructured" case, which interacts with the "*_elem" (element) variants of various forcing engine attributes, the original implementation of those _elem interactions was further copy-pasted blocks of the non-_elem attr handling. In the refactored code, the attr suffix is parameterized to further DRYify and avoid needing an if conditional for the "unstructured" case.

New Classes

_LayeringMod: abstract parent for performing layer_final_forcings operations. Implemented by children:

_LayeringMod_Gridded
_LayeringMod_Unstructured
_LayeringMod_Hydrofabric

_LayeringModSupplemental: abstract parent for performing layer_supplemental_forcing operations. Implemented by children:

_LayeringModSupplemental_Gridded
_LayeringModSupplemental_Unstructured
_LayeringModSupplemental_Hydrofabric

Additions

  • See above

Removals

  • None

Changes

  • See above

Testing

The ngen-forcing pytests ran successfully, confirming that the particular configurations covered by those tests are producing the same numerical and classification outputs as before the refactor. Note that these tests do not cover every possible way of running the forcing engine, and for the choices of discretization types, they only cover the "hydrofabric" case. The tests do not cover the "gridded" case nor the "unstructured" case.

Screenshots

Notes

Todos

Checklist

  • PR has an informative and human-readable title
  • Changes are limited to a single goal (no scope creep)
  • Code can be automatically merged (no conflicts)
  • Code follows project standards (link if applicable)
  • Passes all existing automated tests
  • Any change in functionality is tested
  • New functions are documented (with a description, list of inputs, and expected output)
  • Placeholder code is flagged / future todos are captured in comments
  • Visually tested in supported browsers and devices (see checklist below 👇)
  • Project documentation has been updated (including the "Unreleased" section of the CHANGELOG)
  • Reviewers requested with the Reviewers tool ➡️

Testing checklist

Target Environment support

  • Linux

mxkpp and others added 28 commits August 18, 2026 14:24
…fix namespace error, remove call to `validate_config` (validation occurs automatically in new design)
…ly if rqiMethod is 0 (unused) then rqiThresh property now resolves to None regardless of the value of the RqiThresh key in the config file.
…s tests relative to refactored class structures and new key exclusions in test utils
@mxkpp
mxkpp requested a review from idtodd August 19, 2026 15:22
@mxkpp

mxkpp commented Aug 19, 2026

Copy link
Copy Markdown
Author

I made this branch from the pre_dev branch (#191) since that branch contained updates to the tests that I needed to leverage. This PR therefore effectively starts with commit e65a51a, assuming pre_dev will be merged first.

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.

2 participants