Skip to content

Conversation

@fso42
Copy link
Contributor

@fso42 fso42 commented Oct 21, 2025

feat(com8): Add com8MoTPSA algorithm (addInitialcom8)

refactor(com8): Update parameter descriptions and remove unused friction size option

  • Introduced runCom9MoTVoellmy_algorithm for dense flow simulations.
  • Added support for processing DEM, release layers, entrainment, resistance, and secondary release files.
  • Integrated the new algorithm into pb_tool.cfg and avaframeConnector_provider.py.

feat(com9) Mock up input data for DI does not work

feat(com9): enhance com9MoTVoellmy algorithm with raster support

  • Added copyRaster to handle raster copying with suffixes.
  • Updated parameter names and descriptions for clarity (e.g., mu, k, b0).
  • Added support for raster release layers and handling of raster input parameters (mu, k, b0, tau_c).
  • Improved error handling to ensure either shapefile or raster release layers are provided, not both.

fix(com9): adjust b0 raster handling in com9MoTVoellmy algorithm

  • Updated copyRaster call for b0 to use the correct target directory and suffix.

fix(com9): improve parameter handling and validation in com9MoTVoellmy algorithm

  • parameter description for readability and clarity.
  • Add validation to ensure b0 and tau_c are both provided or omitted together.
  • Update algorithm version string to NGI_Experimental.

feat(com9): add new parameter options and add validation in com9MoTVoellmy algorithm

  • Introduce new friction, entrainment, and forest parameter options.
  • Add validation for friction, entrainment, and forest-related parameters.
  • Update parameter descriptions
  • Refactor simulation command to handle new parameter-related configurations.

feat(com8): Add com8MoTPSA algorithm (addInitialcom8)

refactor(com8): Update parameter descriptions and remove unused friction size option

- Introduced `runCom9MoTVoellmy_algorithm` for dense flow simulations.
- Added support for processing DEM, release layers, entrainment, resistance, and secondary release files.
- Integrated the new algorithm into `pb_tool.cfg` and `avaframeConnector_provider.py`.

feat(com9) Mock up input data for DI does not work

feat(com9): enhance `com9MoTVoellmy` algorithm with raster support

- Added `copyRaster` to handle raster copying with suffixes.
- Updated parameter names and descriptions for clarity (e.g., `mu`, `k`, `b0`).
- Added support for raster release layers and handling of raster input parameters (`mu`, `k`, `b0`, `tau_c`).
- Improved error handling to ensure either shapefile or raster release layers are provided, not both.

fix(com9): adjust `b0` raster handling in `com9MoTVoellmy` algorithm

- Updated `copyRaster` call for `b0` to use the correct target directory and suffix.

fix(com9): improve parameter handling and validation in `com9MoTVoellmy` algorithm

- parameter description for readability and clarity.
- Add validation to ensure `b0` and `tau_c` are both provided or omitted together.
- Update algorithm version string to `NGI_Experimental`.

feat(com9): add new parameter options and add validation in `com9MoTVoellmy` algorithm

- Introduce new friction, entrainment, and forest parameter options.
- Add validation for friction, entrainment, and forest-related parameters.
- Update parameter descriptions
- Refactor simulation command to handle new parameter-related configurations.
@fso42 fso42 self-assigned this Oct 21, 2025
@fso42 fso42 added the enhancement New feature or request label Oct 21, 2025
@qltysh
Copy link

qltysh bot commented Oct 21, 2025

❌ 5 blocking issues (56 total)

Tool Category Rule Count
ruff Lint qgis\.core\.QgsProcessingContext imported but unused 3
ruff Lint Do not use bare except 2
radarlint-python Lint Rename this local variable "targetADDTONAME" to match the regular expression ^[_a-z][a-z0-9_]*$. 42
radarlint-python Lint Remove this commented out code. 4
radarlint-python Lint Specify an exception class to catch or reraise the exception 2
radarlint-python Lint Rename class "runCom9MoTVoellmyAlgorithm" to match the regular expression ^_?([A-Z_][a-zA-Z0-9]*|[a-z_][a-z0-9_]*)$. 1
qlty Structure Function with high complexity (count = 35): processAlgorithm 1
radarlint-python Lint Refactor this function to reduce its Cognitive Complexity from 36 to the 15 allowed. 1

frictionString = frictionOptions[frictionOption]

# Extract raster parameters
sourceMU = self.parameterAsRasterLayer(parameters, self.MU, context)
Copy link

Choose a reason for hiding this comment

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

Rename this local variable "sourceMU" to match the regular expression ^[_a-z][a-z0-9_]*$. [radarlint-python:python:S117]


# Extract raster parameters
sourceMU = self.parameterAsRasterLayer(parameters, self.MU, context)
sourceK = self.parameterAsRasterLayer(parameters, self.K, context)
Copy link

Choose a reason for hiding this comment

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

Rename this local variable "sourceK" to match the regular expression ^[_a-z][a-z0-9_]*$. [radarlint-python:python:S117]

)

# Get entrainment option
entrainmentOption = self.parameterAsInt(parameters, self.ENTRAINMENT, context)
Copy link

Choose a reason for hiding this comment

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

Rename this local variable "entrainmentOption" to match the regular expression ^[_a-z][a-z0-9_]*$. [radarlint-python:python:S117]


# Get entrainment option
entrainmentOption = self.parameterAsInt(parameters, self.ENTRAINMENT, context)
entrainmentOptions = ["noEntrainment", "tjem"]
Copy link

Choose a reason for hiding this comment

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

Rename this local variable "entrainmentOptions" to match the regular expression ^[_a-z][a-z0-9_]*$. [radarlint-python:python:S117]

# Get entrainment option
entrainmentOption = self.parameterAsInt(parameters, self.ENTRAINMENT, context)
entrainmentOptions = ["noEntrainment", "tjem"]
entrainmentString = entrainmentOptions[entrainmentOption]
Copy link

Choose a reason for hiding this comment

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

Rename this local variable "entrainmentString" to match the regular expression ^[_a-z][a-z0-9_]*$. [radarlint-python:python:S117]

sourceRasterPath = pathlib.Path(raster.source())

# Add suffix before file extension
newFileName = sourceRasterPath.stem + suffix + sourceRasterPath.suffix
Copy link

Choose a reason for hiding this comment

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

Rename this local variable "newFileName" to match the regular expression ^[_a-z][a-z0-9_]*$. [radarlint-python:python:S117]


# Add suffix before file extension
newFileName = sourceRasterPath.stem + suffix + sourceRasterPath.suffix
targetRasterPath = targetDir / newFileName
Copy link

Choose a reason for hiding this comment

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

Rename this local variable "targetRasterPath" to match the regular expression ^[_a-z][a-z0-9_]*$. [radarlint-python:python:S117]

return globbed


# TODO: maybe combine this with getLatestPeak
Copy link

Choose a reason for hiding this comment

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

Found 2 issues:

1. Complete the task associated to this "TODO" comment. [radarlint-python:python:S1135]


2. # TODO: maybe combine this with getLatestPeak [ripgrep:TODO]

Comment on lines +223 to +412
def processAlgorithm(self, parameters, context, feedback):
"""
Here is where the processing itself takes place.
"""

import avaframe.version as gv
from . import avaframeConnector_commonFunc as cF

feedback.pushInfo("AvaFrame Version: " + gv.getVersion())

targetADDTONAME = ""

sourceDEM = self.parameterAsRasterLayer(parameters, self.DEM, context)
if sourceDEM is None:
raise QgsProcessingException(self.invalidSourceError(parameters, self.DEM))

# Release files - check both shapefile and raster options
allRELSHP = self.parameterAsLayerList(parameters, self.RELSHP, context)
allRELRAS = self.parameterAsLayerList(parameters, self.RELRAS, context)

# Check that only one release type is provided
if allRELSHP and allRELRAS:
raise QgsProcessingException(
self.tr(
"Error: Please provide EITHER release layers as shapefile OR as raster, not both"
)
)

relShpDict = {}
if allRELSHP:
relShpDict = {lyr.source(): lyr for lyr in allRELSHP}

relRasDict = {}
if allRELRAS:
relRasDict = {lyr.source(): lyr for lyr in allRELRAS}

# Get friction option
frictionOption = self.parameterAsInt(parameters, self.FRICTION, context)
frictionOptions = ["constant", "variable"]
frictionString = frictionOptions[frictionOption]

# Extract raster parameters
sourceMU = self.parameterAsRasterLayer(parameters, self.MU, context)
sourceK = self.parameterAsRasterLayer(parameters, self.K, context)

# Validate friction-related parameters
if frictionString == "variable":
# Variable friction requires MU and K
if sourceMU is None:
raise QgsProcessingException(
self.tr("Error: Variable friction requires mu (dry friction coeff) to be provided")
)
if sourceK is None:
raise QgsProcessingException(
self.tr("Error: Variable friction requires k (turbulent friction coeff) to be provided")
)

# Get entrainment option
entrainmentOption = self.parameterAsInt(parameters, self.ENTRAINMENT, context)
entrainmentOptions = ["noEntrainment", "tjem"]
entrainmentString = entrainmentOptions[entrainmentOption]

sourceB0 = self.parameterAsRasterLayer(parameters, self.B0, context)
sourceTAUC = self.parameterAsRasterLayer(parameters, self.TAUC, context)

# Validate entrainment-related parameters
hasEntrainment = 0
if entrainmentString == "tjem":
# TJEM requires K and B0
if sourceTAUC is None:
raise QgsProcessingException(
self.tr("Error: TJEM entrainment requires tau_c (snow shear strength ) to be provided")
)
if sourceB0 is None:
raise QgsProcessingException(
self.tr("Error: TJEM entrainment requires b0 (erodible snow depth) to be provided")
)
hasEntrainment = 1

# Get forest option
forestOption = self.parameterAsInt(parameters, self.FOREST, context)
forestOptions = ["noForest", "forest"]
forestString = forestOptions[forestOption]

sourceND = self.parameterAsRasterLayer(parameters, self.ND, context)
sourceBHD = self.parameterAsRasterLayer(parameters, self.BHD, context)

# Validate forest-related parameters
hasForest = 0
if forestString == "forest":
# Forest requires ND and BHD
if sourceND is None:
raise QgsProcessingException(
self.tr("Error: Forest requires nd (forest density) to be provided")
)
if sourceBHD is None:
raise QgsProcessingException(
self.tr("Error: Forest requires bhd (tree diameter) to be provided")
)
hasForest = 1

sourceFOLDEST = self.parameterAsFile(parameters, self.FOLDEST, context)

# create folder structure (targetDir is the tmp one)
finalTargetDir, targetDir = cF.createFolderStructure(sourceFOLDEST)

feedback.pushInfo(sourceDEM.source())

# copy DEM
cF.copyDEM(sourceDEM, targetDir)

# copy all release shapefile parts
if relShpDict:
cF.copyMultipleShp(
relShpDict, targetDir / "Inputs" / "REL", targetADDTONAME
)

# copy all release raster parts
if relRasDict:
for source in relRasDict:
cF.copyRaster(relRasDict[source], targetDir / "Inputs" / "REL", "")

# copy raster parameter files to RASTERS folder with suffixes
if sourceMU is not None:
cF.copyRaster(sourceMU, targetDir / "Inputs" / "RASTERS", "_mu")

if sourceK is not None:
cF.copyRaster(sourceK, targetDir / "Inputs" / "RASTERS", "_k")

if sourceB0 is not None:
cF.copyRaster(sourceB0, targetDir / "Inputs" / "ENT", "")

if sourceTAUC is not None:
cF.copyRaster(sourceTAUC, targetDir / "Inputs" / "RASTERS", "_tauc")

if sourceND is not None:
cF.copyRaster(sourceND, targetDir / "Inputs" / "RASTERS", "_nd")

if sourceBHD is not None:
cF.copyRaster(sourceBHD, targetDir / "Inputs" / "RASTERS", "_bhd")

feedback.pushInfo("Starting the simulations")
feedback.pushInfo("This might take a while")
feedback.pushInfo("See console for progress")

# Determine -st argument based on FOREST and ENTRAINMENT parameters
if hasForest and hasEntrainment:
stValue = "entres"
elif hasForest:
stValue = "res"
elif hasEntrainment:
stValue = "ent"
else:
stValue = "null"

# Generate command and run via subprocess.run
command = [
"python",
"-m",
"avaframe.com9MoTVoellmy.runCom9MoTVoellmy",
str(targetDir),
"-st",
stValue,
]
cF.runAndCheck(command, self, feedback)

feedback.pushInfo("Done, start loading the results")

# Move input, log and output folders to finalTargetDir
cF.moveInputAndOutputFoldersToFinal(targetDir, finalTargetDir)

# Get peakfiles to return to QGIS
try:
rasterResults = cF.getLatestPeakCom9(finalTargetDir)
except:
raise QgsProcessingException(
self.tr(
"Something went wrong with com9MoTVoellmy, please check log files"
)
)

allRasterLayers = cF.addStyleToCom1DFAResults(rasterResults)

context = cF.addLayersToContext(context, allRasterLayers, self.OUTPPR)

feedback.pushInfo("\n---------------------------------")
feedback.pushInfo("Done, find results and logs here:")
feedback.pushInfo(str(finalTargetDir.resolve()))
feedback.pushInfo("---------------------------------\n")

Copy link

Choose a reason for hiding this comment

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

Found 2 issues:

1. Function with high complexity (count = 35): processAlgorithm [qlty:function-complexity]


2. Refactor this function to reduce its Cognitive Complexity from 36 to the 15 allowed. [radarlint-python:python:S3776]

entrainmentOptions = ["noEntrainment", "tjem"]
entrainmentString = entrainmentOptions[entrainmentOption]

sourceB0 = self.parameterAsRasterLayer(parameters, self.B0, context)
Copy link

Choose a reason for hiding this comment

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

Rename this local variable "sourceB0" to match the regular expression ^[_a-z][a-z0-9_]*$. [radarlint-python:python:S117]

sourceFOLDEST = self.parameterAsFile(parameters, self.FOLDEST, context)

# create folder structure (targetDir is the tmp one)
finalTargetDir, targetDir = cF.createFolderStructure(sourceFOLDEST)
Copy link

Choose a reason for hiding this comment

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

Found 2 issues:

1. Rename this local variable "finalTargetDir" to match the regular expression ^[_a-z][a-z0-9_]*$. [radarlint-python:python:S117]


2. Rename this local variable "targetDir" to match the regular expression ^[_a-z][a-z0-9_]*$. [radarlint-python:python:S117]


# Determine -st argument based on FOREST and ENTRAINMENT parameters
if hasForest and hasEntrainment:
stValue = "entres"
Copy link

Choose a reason for hiding this comment

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

Rename this local variable "stValue" to match the regular expression ^[_a-z][a-z0-9_]*$. [radarlint-python:python:S117]


# Get peakfiles to return to QGIS
try:
rasterResults = cF.getLatestPeakCom9(finalTargetDir)
Copy link

Choose a reason for hiding this comment

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

Rename this local variable "rasterResults" to match the regular expression ^[_a-z][a-z0-9_]*$. [radarlint-python:python:S117]

# Get peakfiles to return to QGIS
try:
rasterResults = cF.getLatestPeakCom9(finalTargetDir)
except:
Copy link

Choose a reason for hiding this comment

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

Found 2 issues:

1. Do not use bare except [ruff:E722]


2. Specify an exception class to catch or reraise the exception [radarlint-python:python:S5754]

)
)

allRasterLayers = cF.addStyleToCom1DFAResults(rasterResults)
Copy link

Choose a reason for hiding this comment

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

Rename this local variable "allRasterLayers" to match the regular expression ^[_a-z][a-z0-9_]*$. [radarlint-python:python:S117]

@fso42 fso42 merged commit 5cf3eb0 into main Oct 21, 2025
3 checks passed
@fso42 fso42 deleted the addInitialcom8 branch October 21, 2025 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants