Repository navigation
[com4FlowPy] Fix issue #1344 - #1348
ahuber-bfw wants to merge 5 commits into
Conversation
Analysis for project
|
| Tool | Category | Rule | Count | |
|---|---|---|---|---|
| ruff | Lint | Local variable fParams is assigned to but never used |
1 | ❌ |
fso42
left a comment
There was a problem hiding this comment.
This adds backwards incompatible code (checkInputParameterValues now takes an extra argument). Please highlight this in the PR summary, as external calles must update this
| # convert to binary following the > 0 convention used | ||
| fsiMask = (fsi > 0) | ||
| # check if FSI is provided and in correct scaling (0,...,1) | ||
| isValid = validateInputArray(fsiMask, fsi, 1) |
There was a problem hiding this comment.
Mh, what happens if the forest layer exists, but has no forest cells? the mask is empty and np.max(fsi...) might crash, right?
| "Error: (some) provided 'forestFrictionLayer' values are outside the allowed range [0, ..., 90]" | ||
| ) | ||
| raise ValueError( | ||
| "Invalid forest Parameters ('forestFrictionLayer') found in {modelPaths['forestPath']}\n" |
There was a problem hiding this comment.
the f prefix is missing, the literal {modelPaths...} will be printed, that's not wanted, right?
| _dAlphaForMax = np.max(fsi[fsiMask]) | ||
| if (_alphaMax + _dAlphaForMax) >= 90 or (_alphaMax + _dAlphaForMax) < 0: | ||
| raise ValueError( | ||
| "Invalid forest Parameters ('forestFrictionLayer') found in {modelPaths['forestPath']}\n" |
| """ | ||
| test intended behavior of com4FlowPy.checkInputParameterValues() | ||
| """ | ||
| fParams = makeForestParameters( |
| alpha, uMaxLimit/ zDeltaMaxLimit, exponent | ||
| are within a physically sensible range | ||
|
|
||
| Parameters |
| """check if the input parameters are valid | ||
| are valid and within physically sensible limits | ||
| alpha, uMaxLimit/ zDeltaMaxLimit, exponent | ||
| are within a physically sensible range |
There was a problem hiding this comment.
maybe we could update this description to:
check if the input parameters are valid and within a physically sensible range.
| log.info(24*"=") | ||
| log.info(24*"=") | ||
|
|
||
| def checkForestInputParameters(forestParameters, modelParameters, modelPaths): |
There was a problem hiding this comment.
Maybe for all checks it could make sense to write the error messages into the log file?
Similar like:
message = "..."
log.error(message)
raise ValueError(message)
| "unknown value for 'forestFrictionLayerType'\n" | ||
| "must be 'absolute' or 'relative'" | ||
| ) | ||
|
|
There was a problem hiding this comment.
could add also here an else: to check if the forestModule is valid?
PR Summary
com4FlowPy.checkInputParameterValues()for external callers, since the updated function now expects an additional inputforestParamsifmodelParams['forestBool']- ifmodelParams['forestBool'] == Falsethen the legacy behaviour is unchanged.This PR fixes issue #1344 and also applies a Bugfix previously applied in the python engine (PR #1342) to the numba engine (fixed typo in calculation of 3D distances).
Summary of Changes
684ea5cbef93b3afc9c8a69dChanged files:
avaframe/com4FlowPy/com4FlowPy.pyavaframe/com4FlowPy/flowCoreNumba.pyavaframe/tests/test_com4FlowPy.pyavaframe/tests/test_com4FlowPyNumba.py1. Forest input parameter checks (
com4FlowPy.py)added new input data checks for forestModule related input parameters and data to
com4FlowPy.checkInputParameterValues(), that is triggered when 'forestBool' is set.added checks - grouped by
forestModule:skipForestDist >= 0.alphaMaxis taken from the globalalpha, or — whenvarAlphaBoolis true — as themaximum of the variable-alpha raster inside the release-area mask.
forestFriction/forestDetrainment[0, 1](cells withFSI <= 0are masked out, matching theexisting
flowClass.pyconvention).alphaMax + maxAddedFriction < 90(total friction must not reach 90°).velThForFriction >= 0.minAddedFriction <= maxAddedFriction.velThForDetrain >= 0,minDetrainment <= maxDetrainment, and bothdetrainment bounds within
[0, 1].forestFrictionLayervelThForFriction >= 0.forestFrictionLayerType == "absolute": layer values within[0, 90].forestFrictionLayerType == "relative":0 <= alphaMax + max(layer) < 90.ValueError.All failures raise
ValueErrorwith a message naming the offending parameter and config key.On success, a short summary is written to the log.
2. Numba engine bug fix (
flowCoreNumba.py)The 3D minimum-distance calculation in the numba engine
flowCoreNumba.py-_bfs_single()useddytwice(
sqrt(dy² + dy² + dz²)), replicating an upstream Bug offlowClass.calcDistMin().It now uses
sqrt(dx² + dy² + dz²), mirroring the fix already onmasterinflowClass.py(issue #1341). This affects the
skipForestDistgate in the Numba engine.3. Tests (
test_com4FlowPy.py,test_com4FlowPyNumba.py)test_com4FlowPy.pymakeForestParameters(),makeForestModelPaths()and_makeForestReadRaster()to build valid inputs and fakeIOf.readRaster.checkForestInputParameters()covering all three forest modules, bothglobal and variable alpha, all valid branches, and the invalid cases (out-of-range FSI,
friction/detrainment limits, unknown layer type, negative thresholds), using
pytest.mark.parametrize.if __name__ == "__main__":block that re-ran a hand-picked subset of tests.pytesttest_com4FlowPyNumba.pyif __name__ == "__main__":block.pytest4. Main Changes
ValueError()instead of failing silently or producing unintended results.PR Checklist
Please confirm before requesting review:
pytestlocally without failsConfirm before the final merge/rebase into master