Skip to content

Commit 188811c

Browse files
committed
feat(com7): add algorithms for regional modeling support
- Added `runCom7RegionalSplitting_algorithm` for regional input splitting. - Added `runCom7RegionalComputation_algorithm` for regional modeling computation. - Registered both algorithms in `avaframeConnector_provider.py`. - Replaced `QgsProcessingParameterMultipleLayers` with `QgsProcessingParameterFeatureSource` for single layer input in `runCom7RegionalSplitting_algorithm`. - Updated command options in subprocess calls to use explicit flags `--split-inputs` and `--run-computations`. - Removed unused code related to multiple layer handling. - Registered updated algorithms in `pb_tool.cfg`.
1 parent e20c3b9 commit 188811c

File tree

4 files changed

+412
-3
lines changed

4 files changed

+412
-3
lines changed

avaframeConnector_provider.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,14 @@ def find_python():
9191
from .getVersion_algorithm import getVersionAlgorithm
9292
from .runCom1DFA_algorithm import runCom1DFAAlgorithm
9393
from .runCom2AB_algorithm import runCom2ABAlgorithm
94-
from .runCom5SnowSlide_algorithm import runCom5SnowSlideAlgorithm
95-
from .runCom6RockAvalanche_algorithm import runCom6RockAvalancheAlgorithm
96-
from .runCom6Scarp_algorithm import runCom6ScarpAlgorithm
9794
from .runAna4ProbAna_algorithm import runAna4ProbAnaAlgorithm
9895
from .runAna4ProbDirOnly_algorithm import runAna4ProbDirOnlyAlgorithm
9996
from .runAna5DFAPathGeneration_algorithm import runAna5DFAPathGenerationAlgorithm
97+
from .runCom5SnowSlide_algorithm import runCom5SnowSlideAlgorithm
98+
from .runCom6RockAvalanche_algorithm import runCom6RockAvalancheAlgorithm
99+
from .runCom7RegionalSplitting_algorithm import runCom7RegionalSplittingAlgorithm
100+
from .runCom7RegionalComputation_algorithm import runCom7RegionalComputationAlgorithm
101+
from .runCom6Scarp_algorithm import runCom6ScarpAlgorithm
100102
from .runIn1RelInfo_algorithm import runIn1RelInfoAlgorithm
101103
from .update_algorithm import updateAlgorithm
102104

@@ -130,6 +132,8 @@ def loadAlgorithms(self):
130132
self.addAlgorithm(runCom5SnowSlideAlgorithm())
131133
self.addAlgorithm(runCom6RockAvalancheAlgorithm())
132134
self.addAlgorithm(runCom6ScarpAlgorithm())
135+
self.addAlgorithm(runCom7RegionalSplittingAlgorithm())
136+
self.addAlgorithm(runCom7RegionalComputationAlgorithm())
133137
self.addAlgorithm(runAna4ProbAnaAlgorithm())
134138
self.addAlgorithm(runAna4ProbDirOnlyAlgorithm())
135139
self.addAlgorithm(runAna5DFAPathGenerationAlgorithm())

pb_tool.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ python_files: __init__.py avaframeConnector.py avaframeConnector_provider.py
6161
runAna4ProbAna_algorithm.py
6262
runAna4ProbDirOnly_algorithm.py
6363
runAna5DFAPathGeneration_algorithm.py
64+
runCom7RegionalSplitting_algorithm.py
65+
runCom7RegionalComputation_algorithm.py
6466
runIn1RelInfo_algorithm.py
6567
avaframeConnector_commonFunc.py
6668

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
/***************************************************************************
5+
AvaFrameRunCom1DFA
6+
A QGIS plugin
7+
Connects to AvaFrame
8+
Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/
9+
-------------------
10+
begin : 2021-08-26
11+
copyright : (C) 2021 by AvaFrame Team
12+
email : felix@avaframe.org
13+
***************************************************************************/
14+
15+
/***************************************************************************
16+
* *
17+
* This program is free software; you can redistribute it and/or modify *
18+
* it under the terms of the GNU General Public License as published by *
19+
* the Free Software Foundation; either version 2 of the License, or *
20+
* (at your option) any later version. *
21+
* *
22+
***************************************************************************/
23+
"""
24+
25+
__author__ = "AvaFrame Team"
26+
__date__ = "2025"
27+
__copyright__ = "(C) 2025 by AvaFrame Team"
28+
29+
# This will get replaced with a git SHA1 when you do a git archive
30+
31+
__revision__ = "$Format:%H$"
32+
33+
34+
import pathlib
35+
36+
37+
from qgis.PyQt.QtCore import QCoreApplication
38+
from qgis.core import (
39+
QgsProcessing,
40+
QgsProcessingAlgorithm,
41+
QgsProcessingParameterFile,
42+
QgsProcessingOutputVectorLayer,
43+
)
44+
45+
46+
class runCom7RegionalComputationAlgorithm(QgsProcessingAlgorithm):
47+
"""
48+
Runs com7Regional computation on a single folder
49+
"""
50+
51+
OUTPUT = "OUTPUT"
52+
SIMFOLDER = "FOLDEST"
53+
54+
def initAlgorithm(self, config):
55+
"""
56+
Here we define the inputs and output of the algorithm, along
57+
with some other properties.
58+
"""
59+
self.addParameter(
60+
QgsProcessingParameterFile(
61+
self.SIMFOLDER,
62+
self.tr("Avalanche directory"),
63+
behavior=QgsProcessingParameterFile.Folder,
64+
)
65+
)
66+
67+
self.addOutput(
68+
QgsProcessingOutputVectorLayer(
69+
self.OUTPUT,
70+
self.tr("Output layer"),
71+
QgsProcessing.TypeVectorAnyGeometry,
72+
)
73+
)
74+
75+
def flags(self):
76+
return super().flags()
77+
# return super().flags() | QgsProcessingAlgorithm.FlagNoThreading
78+
79+
def processAlgorithm(self, parameters, context, feedback):
80+
"""
81+
Here is where the processing itself takes place.
82+
"""
83+
84+
import avaframe.version as gv
85+
from . import avaframeConnector_commonFunc as cF
86+
87+
feedback.pushInfo("AvaFrame Version: " + gv.getVersion())
88+
89+
sourceFOLDEST = self.parameterAsFile(parameters, self.SIMFOLDER, context)
90+
91+
# create folder structure
92+
targetDir = pathlib.Path(sourceFOLDEST)
93+
94+
feedback.pushInfo("Starting the simulations")
95+
feedback.pushInfo("This might take a while")
96+
feedback.pushInfo("See console for progress")
97+
98+
# Generate command and run via subprocess.run
99+
command = [
100+
"python",
101+
"-m",
102+
"avaframe.runCom7Regional",
103+
str(targetDir),
104+
"--run-computations",
105+
]
106+
cF.runAndCheck(command, self, feedback)
107+
108+
feedback.pushInfo("Done, start loading the results")
109+
110+
feedback.pushInfo("\n---------------------------------")
111+
feedback.pushInfo("Done, find results and logs here:")
112+
feedback.pushInfo(str(targetDir.resolve()))
113+
feedback.pushInfo("---------------------------------\n")
114+
115+
return {}
116+
117+
def name(self):
118+
"""
119+
Returns the algorithm name, used for identifying the algorithm. This
120+
string should be fixed for the algorithm, and must not be localised.
121+
The name should be unique within each provider. Names should contain
122+
lowercase alphanumeric characters only and no spaces or other
123+
formatting characters.
124+
"""
125+
return "com7regionalcomputation"
126+
127+
def displayName(self):
128+
"""
129+
Returns the translated algorithm name, which should be used for any
130+
user-visible display of the algorithm name.
131+
"""
132+
return self.tr("Regional modelling computation (com7)")
133+
134+
def group(self):
135+
"""
136+
Returns the name of the group this algorithm belongs to. This string
137+
should be localised.
138+
"""
139+
return self.tr(self.groupId())
140+
141+
def groupId(self):
142+
"""
143+
Returns the unique ID of the group this algorithm belongs to. This
144+
string should be fixed for the algorithm, and must not be localised.
145+
The group id should be unique within each provider. Group id should
146+
contain lowercase alphanumeric characters only and no spaces or other
147+
formatting characters.
148+
"""
149+
return "Experimental"
150+
151+
def tr(self, string):
152+
return QCoreApplication.translate("Processing", string)
153+
154+
def shortHelpString(self) -> str:
155+
hstring = "Runs multiple avalanches as setup via regional input splitting. \n\
156+
AvaFrame Documentation: https://docs.avaframe.org\n\
157+
Homepage: https://avaframe.org\n\
158+
Praxisleitfaden: https://avaframe.org/reports\n"
159+
160+
return self.tr(hstring)
161+
162+
def helpUrl(self):
163+
return "https://docs.avaframe.org/en/latest/connector.html"
164+
165+
def createInstance(self):
166+
return runCom7RegionalComputationAlgorithm()

0 commit comments

Comments
 (0)