Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[processing] TauDEM provider overhaul
- add new TauDEM 5.1.2/5.2 tools: Gage watershed, TWI and Select GT Threshold - implement support for multifile TauDEM version - allow to use single- and multifile versions simultaneously Work done for Faunalia (http://faunalia.eu) (cherry-picked from 427adf7)
- Loading branch information
Showing
56 changed files
with
1,432 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,5 +1,7 @@ | |||
FILE(GLOB PY_FILES *.py) | FILE(GLOB PY_FILES *.py) | ||
FILE(GLOB DESCR_FILES description/*.txt) | FILE(GLOB SINGLE_DESCR_FILES description/single/*.txt) | ||
FILE(GLOB MULTI_DESCR_FILES description/multi/*.txt) | |||
|
|
||
PLUGIN_INSTALL(processing algs/taudem ${PY_FILES}) | PLUGIN_INSTALL(processing algs/taudem ${PY_FILES}) | ||
PLUGIN_INSTALL(processing algs/taudem/description ${DESCR_FILES}) | PLUGIN_INSTALL(processing algs/taudem/description/single ${SINGLE_DESCR_FILES}) | ||
PLUGIN_INSTALL(processing algs/taudem/description/multi ${MULTI_DESCR_FILES}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
python/plugins/processing/algs/taudem/TauDEMMultifileAlgorithm.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,122 @@ | |||
# -*- coding: utf-8 -*- | |||
|
|||
""" | |||
*************************************************************************** | |||
TauDEMMultifileAlgorithm.py | |||
--------------------- | |||
Date : March 2015 | |||
Copyright : (C) 2012 by Alexander Bruy | |||
Email : alexander dot bruy at gmail dot com | |||
*************************************************************************** | |||
* * | |||
* This program is free software; you can redistribute it and/or modify * | |||
* it under the terms of the GNU General Public License as published by * | |||
* the Free Software Foundation; either version 2 of the License, or * | |||
* (at your option) any later version. * | |||
* * | |||
*************************************************************************** | |||
""" | |||
|
|||
__author__ = 'Alexander Bruy' | |||
__date__ = 'March 2015' | |||
__copyright__ = '(C) 2015, Alexander Bruy' | |||
|
|||
# This will get replaced with a git SHA1 when you do a git archive | |||
|
|||
__revision__ = '$Format:%H$' | |||
|
|||
import os | |||
from PyQt4.QtGui import QIcon | |||
|
|||
from processing.core.GeoAlgorithm import GeoAlgorithm | |||
from processing.core.ProcessingLog import ProcessingLog | |||
from processing.core.ProcessingConfig import ProcessingConfig | |||
from processing.core.GeoAlgorithmExecutionException import \ | |||
GeoAlgorithmExecutionException | |||
|
|||
from processing.core.parameters import ParameterFile | |||
from processing.core.parameters import ParameterVector | |||
from processing.core.parameters import ParameterBoolean | |||
from processing.core.parameters import ParameterString | |||
from processing.core.parameters import ParameterNumber | |||
from processing.core.parameters import getParameterFromString | |||
from processing.core.outputs import getOutputFromString | |||
|
|||
from TauDEMUtils import TauDEMUtils | |||
|
|||
|
|||
class TauDEMMultifileAlgorithm(GeoAlgorithm): | |||
|
|||
def __init__(self, descriptionfile): | |||
GeoAlgorithm.__init__(self) | |||
self.descriptionFile = descriptionfile | |||
self.defineCharacteristicsFromFile() | |||
|
|||
def getCopy(self): | |||
newone = TauDEMMultifileAlgorithm(self.descriptionFile) | |||
newone.provider = self.provider | |||
return newone | |||
|
|||
def getIcon(self): | |||
return QIcon(os.path.dirname(__file__) + '/../../images/taudem.png') | |||
|
|||
def defineCharacteristicsFromFile(self): | |||
lines = open(self.descriptionFile) | |||
line = lines.readline().strip('\n').strip() | |||
self.name = line | |||
line = lines.readline().strip('\n').strip() | |||
self.cmdName = line | |||
line = lines.readline().strip('\n').strip() | |||
self.group = line | |||
|
|||
line = lines.readline().strip('\n').strip() | |||
while line != '': | |||
try: | |||
line = line.strip('\n').strip() | |||
if line.startswith('Parameter'): | |||
param = getParameterFromString(line) | |||
self.addParameter(param) | |||
else: | |||
self.addOutput(getOutputFromString(line)) | |||
line = lines.readline().strip('\n').strip() | |||
except Exception, e: | |||
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, | |||
self.tr('Could not load TauDEM algorithm: %s\n%s' % (self.descriptionFile, line))) | |||
raise e | |||
lines.close() | |||
|
|||
def processAlgorithm(self, progress): | |||
commands = [] | |||
commands.append(os.path.join(TauDEMUtils.mpiexecPath(), 'mpiexec')) | |||
|
|||
processNum = int(ProcessingConfig.getSetting(TauDEMUtils.MPI_PROCESSES)) | |||
if processNum <= 0: | |||
raise GeoAlgorithmExecutionException( | |||
self.tr('Wrong number of MPI processes used. Please set ' | |||
'correct number before running TauDEM algorithms.')) | |||
|
|||
commands.append('-n') | |||
commands.append(str(processNum)) | |||
commands.append(os.path.join(TauDEMUtils.taudemMultifilePath(), self.cmdName)) | |||
|
|||
for param in self.parameters: | |||
if param.value is None or param.value == '': | |||
continue | |||
if isinstance(param, ParameterNumber): | |||
commands.append(param.name) | |||
commands.append(str(param.value)) | |||
if isinstance(param, (ParameterFile, ParameterVector)): | |||
commands.append(param.name) | |||
commands.append(param.value) | |||
elif isinstance(param, ParameterBoolean): | |||
if param.value and str(param.value).lower() == 'false': | |||
commands.append(param.name) | |||
elif isinstance(param, ParameterString): | |||
commands.append(param.name) | |||
commands.append(str(param.value)) | |||
|
|||
for out in self.outputs: | |||
commands.append(out.name) | |||
commands.append(out.value) | |||
|
|||
TauDEMUtils.executeTauDEM(commands, progress) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
python/plugins/processing/algs/taudem/description/multi/aread8.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,8 @@ | |||
D8 Contributing Area (multifile) | |||
aread8 | |||
Basic Grid Analysis tools | |||
ParameterFile|-p|D8 Flow Direction Grid|True|False | |||
ParameterVector|-o|Outlets Shapefile|0|True | |||
ParameterFile|-wg|Weight Grid|True|True | |||
ParameterBoolean|-nc|Check for edge contamination|True | |||
OutputDirectory|-ad8|D8 Contributing Area Grid |
8 changes: 8 additions & 0 deletions
8
python/plugins/processing/algs/taudem/description/multi/areadinf.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,8 @@ | |||
D-Infinity Contributing Area (multifile) | |||
areadinf | |||
Basic Grid Analysis tools | |||
ParameterFile|-ang|D-Infinity Flow Direction Grid|True|False | |||
ParameterVector|-o|Outlets Shapefile|0|True | |||
ParameterFile|-wg|Weight Grid|True|True | |||
ParameterBoolean|-nc|Check for edge contamination|True | |||
OutputDirectory|-sca|D-Infinity Specific Catchment Area Grid |
6 changes: 6 additions & 0 deletions
6
python/plugins/processing/algs/taudem/description/multi/d8flowdir.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,6 @@ | |||
D8 Flow Directions (multifile) | |||
d8flowdir | |||
Basic Grid Analysis tools | |||
ParameterFile|-fel|Pit Filled Elevation Grid|True|False | |||
OutputDirectory|-p|D8 Flow Direction Grid | |||
OutputDirectory|-sd8|D8 Slope Grid |
Oops, something went wrong.