-
Notifications
You must be signed in to change notification settings - Fork 0
feat(com9): add com9MoTVoellmy algorithm and related functionalities
#51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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.
❌ 5 blocking issues (56 total)
|
| frictionString = frictionOptions[frictionOption] | ||
|
|
||
| # Extract raster parameters | ||
| sourceMU = self.parameterAsRasterLayer(parameters, self.MU, context) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
|
||
| # Extract raster parameters | ||
| sourceMU = self.parameterAsRasterLayer(parameters, self.MU, context) | ||
| sourceK = self.parameterAsRasterLayer(parameters, self.K, context) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ) | ||
|
|
||
| # Get entrainment option | ||
| entrainmentOption = self.parameterAsInt(parameters, self.ENTRAINMENT, context) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
|
||
| # Get entrainment option | ||
| entrainmentOption = self.parameterAsInt(parameters, self.ENTRAINMENT, context) | ||
| entrainmentOptions = ["noEntrainment", "tjem"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| # Get entrainment option | ||
| entrainmentOption = self.parameterAsInt(parameters, self.ENTRAINMENT, context) | ||
| entrainmentOptions = ["noEntrainment", "tjem"] | ||
| entrainmentString = entrainmentOptions[entrainmentOption] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| sourceRasterPath = pathlib.Path(raster.source()) | ||
|
|
||
| # Add suffix before file extension | ||
| newFileName = sourceRasterPath.stem + suffix + sourceRasterPath.suffix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
|
||
| # Add suffix before file extension | ||
| newFileName = sourceRasterPath.stem + suffix + sourceRasterPath.suffix | ||
| targetRasterPath = targetDir / newFileName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return globbed | ||
|
|
||
|
|
||
| # TODO: maybe combine this with getLatestPeak |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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") | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| entrainmentOptions = ["noEntrainment", "tjem"] | ||
| entrainmentString = entrainmentOptions[entrainmentOption] | ||
|
|
||
| sourceB0 = self.parameterAsRasterLayer(parameters, self.B0, context) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| sourceFOLDEST = self.parameterAsFile(parameters, self.FOLDEST, context) | ||
|
|
||
| # create folder structure (targetDir is the tmp one) | ||
| finalTargetDir, targetDir = cF.createFolderStructure(sourceFOLDEST) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
|
||
| # Determine -st argument based on FOREST and ENTRAINMENT parameters | ||
| if hasForest and hasEntrainment: | ||
| stValue = "entres" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
|
||
| # Get peakfiles to return to QGIS | ||
| try: | ||
| rasterResults = cF.getLatestPeakCom9(finalTargetDir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| # Get peakfiles to return to QGIS | ||
| try: | ||
| rasterResults = cF.getLatestPeakCom9(finalTargetDir) | ||
| except: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ) | ||
| ) | ||
|
|
||
| allRasterLayers = cF.addStyleToCom1DFAResults(rasterResults) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
feat(com8): Add com8MoTPSA algorithm (addInitialcom8)
refactor(com8): Update parameter descriptions and remove unused friction size option
runCom9MoTVoellmy_algorithmfor dense flow simulations.pb_tool.cfgandavaframeConnector_provider.py.feat(com9) Mock up input data for DI does not work
feat(com9): enhance
com9MoTVoellmyalgorithm with raster supportcopyRasterto handle raster copying with suffixes.mu,k,b0).mu,k,b0,tau_c).fix(com9): adjust
b0raster handling incom9MoTVoellmyalgorithmcopyRastercall forb0to use the correct target directory and suffix.fix(com9): improve parameter handling and validation in
com9MoTVoellmyalgorithmb0andtau_care both provided or omitted together.NGI_Experimental.feat(com9): add new parameter options and add validation in
com9MoTVoellmyalgorithm