Skip to content

Fix handling of bounded parameters - #63

Merged
pnorton-usgs merged 13 commits into
developmentfrom
fix/fix_handling_of_bounded_parameters
Aug 14, 2026
Merged

Fix handling of bounded parameters#63
pnorton-usgs merged 13 commits into
developmentfrom
fix/fix_handling_of_bounded_parameters

Conversation

@pnorton-usgs

Copy link
Copy Markdown
Member

Summary

Refactors bounded parameter handling so that the maximum value (a dimension name in metadata) is resolved to a numeric size at parameter creation time rather than requiring a post-load adjustment pass.

Changes

Core bounded parameter handling

  • metadata.py: Add is_bounded flag when parameter min/max is bounded
  • Parameter.py: Resolve bounded maximum from dimension name to numeric size during __init__, moved outside the dimension loop to avoid repeated execution for multi-dimension parameters
  • Parameters.py: Add bounded dimension to global dimensions in add(); remove post-load adjust_bounded_parameters() calls (now deprecated with warning)
  • ParameterFile.py / ParameterNetCDF.py / ParamDb.py: Remove adjust_bounded_parameters() calls; bounded resolution is now automatic

Validation improvements

  • check_values() and outliers(): Skip string-type parameters; raise ValueError if min > max; warn if min == max
  • outlier_ids(): Guard against string datatype and None min/max; report partial outliers with warnings when only one bound is available

Other fixes

  • Cbh.py: Auto-set nhm_id from parameters; fix dict key type for cbh_files
  • test_DataFile.py: Rename TestStreamflow to TestDataFile
  • conftest.py: Add test class ordering
  • Parameters.add(): Fall back to metadata default for nobs when npoigages is missing
  • Use deepcopy for metadata/dimensions to prevent cross-instance contamination

Testing

All 301 tests pass locally (Python 3.13).

- Add 'is_bounded' flag in metadata when parameter min/max is 'bounded'
- Resolve bounded parameter maximum to the actual dimension size in Parameter
- Add bounded dimension to global dimensions in Parameters.add()
- Remove post-load adjust_bounded_parameters() calls from ParameterFile,
  ParameterNetCDF, and ParamDb (now handled at parameter creation time)
- Fix outlier detection to skip string-type parameters instead of
  checking for string min/max values
- Use deepcopy for metadata and dimensions to prevent cross-contamination
- Fix whitespace alignment in ParamDb
- Add test class ordering in conftest.py via pytest_collection_modifyitems
- Add tests for bounded parameter creation with and without global_dims
- Replace basin_solsta (bounded) with non-bounded params (ncol, maxiter_sntemp,
  gwstor_init) in tests that don't require bounded behavior
- Use separate MetaData copies in test_ParameterFile to avoid shared state
- Update expected output strings for new dimension/parameter additions
- Auto-set nhm_id from parameters when available in Cbh constructor
- Fix cbh_files dict key to use string path instead of Path object
- Fix resolve_units docstring formatting
- Pass parameters to Cbh in netcdf test
- Rename TestStreamflow class to TestDataFile in test_DataFile.py
The is_bounded check was inside the 'for cname in dimensions' loop,
causing it to run on every iteration. For multi-dimension bounded
parameters this would fail on the second iteration since maximum
is already resolved to a numeric value. Move the resolution to
run once after all dimensions are added.
The method is no longer called internally since bounded parameters
are now resolved at creation time in Parameter.__init__. Emits a
DeprecationWarning to inform any external callers.
Skip comparison for string-type parameters to avoid TypeError when
comparing string data against numeric min/max bounds. Matches the
guards already present in check_values() and outliers().
Clean up leftover comments from the old bounded handling approach
in check() and check_values(). Remove unused default_val variable.
Previously, adding a bounded parameter that requires nobs would
crash if npoigages was also missing from global dimensions. Now
falls back to adding nobs with its metadata default size (0).
Raise ValueError if minimum > maximum (indicates corrupted metadata).
Emit a warning when minimum == maximum (dimension size is zero,
likely an unpopulated dimension).
Report partial outliers when only one bound is available rather than
returning an empty list. Emit warnings when minimum, maximum, or
both are undefined so the caller knows the check was incomplete.
@pnorton-usgs pnorton-usgs self-assigned this Aug 14, 2026
…ng_of_bounded_parameters

Incorporate latest development fixes
@pnorton-usgs
pnorton-usgs merged commit b910910 into development Aug 14, 2026
7 checks passed
@pnorton-usgs
pnorton-usgs deleted the fix/fix_handling_of_bounded_parameters branch August 14, 2026 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant