[ana5]: add general thalweg extension & resampling - #1323
Conversation
Analysis for project
|
| Tool | Category | Rule | Count | |
|---|---|---|---|---|
| ripgrep | Lint | # TODO: for option 2, the code is very similar as in extendProfileBottom, should we summarize both in one function with options/different handling for top nd bottom extension? | 4 | ❌ |
| ruff | Style | Incorrect formatting, autoformat by running qlty fmt. |
3 | ❌ |
| ruff | Lint | Do not use bare except |
2 | ❌ |
| ruff | Lint | Ambiguous variable name: l |
2 | ❌ |
| ruff | Lint | f-string without any placeholders | 1 | ❌ |
| qlty | Structure | Function with high complexity (count = 34): extendProfileTop | 1 | |
| qlty | Structure | Deeply nested control flow (level = 4) | 1 |
@qltysh one-click actions:
- Auto-fix formatting (
qlty fmt && git push)
| profile["z"] = np.append(zExtTop, profile["z"]) | ||
| profile["s"] = np.append(0, profile["s"] + ds) | ||
| if debugPlot: | ||
| debPlot.plotPathExtTop(profile, particlesIni, xFirst, yFirst, zFirst, dz1) |
| log.warning("Skip top extension of thalweg since profile contains only one point.") | ||
| return profile | ||
|
|
||
| # TODO: for option 2, the code is very similar as in extendProfileBottom, should we summarize both in one function with options/different handling for top nd bottom extension? |
| log.error(message) | ||
| raise ValueError(message) | ||
| if cfg is None: | ||
| message = f"If extTopOption = 2, the cfg needs to be provided" |
| else: | ||
| # remember last point found inside | ||
| factFirst = factExt | ||
| factExt = factExt + stepSize |
| title = ('com3HybRasterPlot') | ||
| l = ax.legend(loc='lower left') | ||
| title = "com3HybRasterPlot" | ||
| l = ax.legend(loc="lower left") |
| else: | ||
| extentPlot = extent | ||
|
|
||
| # TODO: restore changes and rebase master! |
| @@ -0,0 +1,205 @@ | |||
| """Tests for module preparePathGeneral""" | |||
|
Coverage Impact This PR will not change total coverage. Modified Components (1)
Modified Files with Diff Coverage (3)
🤖 Increase coverage with AI coding...🚦 See full report on Qlty Cloud » 🛟 Help
|
7c42103 to
ea6399c
Compare
resample path
ea6399c to
da66642
Compare
| ) | ||
|
|
||
| # extend the bottom | ||
| profile = DFAPathGeneration.extendProfileBottom(cfgPathGen["PATH"], demDict, profile, considerLLC=True) |
There was a problem hiding this comment.
I'm not 100 % sure if the indices that come out are correct or whether they are shifted by one. Can you check?
- pathExtension sets indStartMassAverage = 1 and indEndMassAverage = size(x) - 2 before the extension calls
(preparePathGeneral.py:119-120) - extendProfileTop (option 2) prepends a single point and extendProfileBottom appends a single one, at least in
the normal case - The indices are consumed later by resamplePath on the post-extension profile, via s0 and sEnd
And that's then shifted by one? But maybe I did not follow correctly?
| indEndCandidates = np.argwhere(avaProfile["s"] >= sEnd + resampleDistance / 3) | ||
| indEnd = indEndCandidates[0][0] - 1 if len(indEndCandidates) > 0 else np.size(avaProfile["s"]) - 1 | ||
| avaProfile['indEndMassAverage'] = indEnd | ||
| except: |
There was a problem hiding this comment.
What are you trying to catch here? If there's a real error, it will be masked here...
| return outPath | ||
|
|
||
|
|
||
| def avalancheThalwegPlot(ax, fieldRaster, dem, avaProfileMass, splitPoint=None, avalancheDir="", cmapHS=None): |
| for inputPara in ["alpha", "exponent", "zDeltaMax"]: | ||
| try: | ||
| profileExtended[inputPara] = profile[inputPara] | ||
| except: |
There was a problem hiding this comment.
Should this be a except KeyError? since real error should be shown
| # skip profile that only contains one point | ||
| if len(profileAveraged["x"]) <= 2: | ||
| profileExtended["indStartMassAverage"] = 0 | ||
| profileExtended["indEndMassAverage"] = max(len(profileExtended["x"]) - 1, 1) |
There was a problem hiding this comment.
Single Points gets '1', but he profile Array only has 0. Do we need to catch this?
| return profileAveraged, profileExtended | ||
|
|
||
|
|
||
| def replaceResampledProfileCore(profile, profileResample): |
There was a problem hiding this comment.
Remove, it's dead code an in git anyways

The goal is to derive a thalweg profile from very general thalweg data (containing x and y coordinates).
This changed in each file:
ana5Utils/DFAPathGeneration.py:
(for option 2, the code is very similar as in extendProfileBottom, should we summarize both in one function with options/different handling for top nd bottom extension?)
ana5Utils/DFAPathGenerationCfg.ini:
ana5Utils/preparePathGeneral.py
functions to prepare a path/thalweg that has only x and y coordinates:
out3Plot/outCom3Plots.py
PR Checklist
Please confirm before requesting review:
pytestlocally without failsConfirm before the final merge/rebase into master