Skip to content

Commit

Permalink
[processing] i18n support for TauDEM provider
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy committed Jan 17, 2015
1 parent 321ff1b commit e1d8710
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 186 deletions.
15 changes: 4 additions & 11 deletions python/plugins/processing/algs/taudem/TauDEMAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ def defineCharacteristicsFromFile(self):
line = lines.readline().strip('\n').strip()
except Exception, e:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
'Could not load TauDEM algorithm: '
+ self.descriptionFile + '\n' + line)
self.tr('Could not load TauDEM algorithm: %s\n%s' % (self.descriptionFile, line)))
raise e
lines.close()

Expand All @@ -92,10 +91,9 @@ def processAlgorithm(self, progress):

processNum = int(ProcessingConfig.getSetting(TauDEMUtils.MPI_PROCESSES))
if processNum <= 0:
raise GeoAlgorithmExecutionException('Wrong number of MPI \
processes used.\nPlease set correct number before running \
TauDEM algorithms.'
)
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))
Expand All @@ -121,9 +119,4 @@ def processAlgorithm(self, progress):
commands.append(out.name)
commands.append(out.value)

loglines = []
loglines.append('TauDEM execution command')
for line in commands:
loglines.append(line)
ProcessingLog.addToLog(ProcessingLog.LOG_INFO, loglines)
TauDEMUtils.executeTauDEM(commands, progress)
23 changes: 10 additions & 13 deletions python/plugins/processing/algs/taudem/TauDEMAlgorithmProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,16 @@ def getIcon(self):
def initializeSettings(self):
AlgorithmProvider.initializeSettings(self)
ProcessingConfig.addSetting(Setting(self.getDescription(),
TauDEMUtils.TAUDEM_FOLDER,
'TauDEM command line tools folder',
TauDEMUtils.taudemPath()))
TauDEMUtils.TAUDEM_FOLDER,
self.tr('TauDEM command line tools folder'),
TauDEMUtils.taudemPath()))
ProcessingConfig.addSetting(Setting(self.getDescription(),
TauDEMUtils.MPIEXEC_FOLDER,
'MPICH2/OpenMPI bin directory',
TauDEMUtils.mpiexecPath()))
TauDEMUtils.MPIEXEC_FOLDER,
self.tr('MPICH2/OpenMPI bin directory'),
TauDEMUtils.mpiexecPath()))
ProcessingConfig.addSetting(Setting(self.getDescription(),
TauDEMUtils.MPI_PROCESSES,
'Number of MPI parallel processes to use',
2))
TauDEMUtils.MPI_PROCESSES,
self.tr('Number of MPI parallel processes to use'), 2))

def unload(self):
AlgorithmProvider.unload(self)
Expand All @@ -98,12 +97,10 @@ def createAlgsList(self):
self.preloadedAlgs.append(alg)
else:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
'Could not open TauDEM algorithm: '
+ descriptionFile)
self.tr('Could not open TauDEM algorithm: %s' % descriptionFile))
except Exception, e:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR,
'Could not open TauDEM algorithm: '
+ descriptionFile)
self.tr('Could not open TauDEM algorithm: %s' % descriptionFile))

self.preloadedAlgs.append(PeukerDouglas())
self.preloadedAlgs.append(SlopeArea())
Expand Down
10 changes: 8 additions & 2 deletions python/plugins/processing/algs/taudem/TauDEMUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ def taudemDescriptionPath():
@staticmethod
def executeTauDEM(command, progress):
loglines = []
loglines.append('TauDEM execution console output')
loglines.append(TauDEMUtils.tr('TauDEM execution console output'))
fused_command = ''.join(['"%s" ' % c for c in command])
progress.setInfo('TauDEM command:')
progress.setInfo(TauDEMUtils.tr('TauDEM command:'))
progress.setCommand(fused_command.replace('" "', ' ').strip('"'))
proc = subprocess.Popen(
fused_command,
Expand All @@ -96,3 +96,9 @@ def executeTauDEM(command, progress):
progress.setConsoleInfo(line)
loglines.append(line)
ProcessingLog.addToLog(ProcessingLog.LOG_INFO, loglines)

@staticmethod
def tr(string, context=''):
if context == '':
context = 'TauDEMUtils'
return QCoreApplication.translate(context, string)
28 changes: 11 additions & 17 deletions python/plugins/processing/algs/taudem/dinfdistdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,32 +77,32 @@ def defineCharacteristics(self):
self.group = 'Specialized Grid Analysis tools'

self.addParameter(ParameterRaster(self.DINF_FLOW_DIR_GRID,
'D-Infinity Flow Direction Grid', False))
self.tr('D-Infinity Flow Direction Grid'), False))
self.addParameter(ParameterRaster(self.PIT_FILLED_GRID,
'Pit Filled Elevation Grid', False))
self.tr('Pit Filled Elevation Grid'), False))
self.addParameter(ParameterRaster(self.STREAM_GRID,
'Stream Raster Grid', False))
self.tr('Stream Raster Grid'), False))
self.addParameter(ParameterRaster(self.WEIGHT_PATH_GRID,
'Weight Path Grid', True))
self.tr('Weight Path Grid'), True))
self.addParameter(ParameterSelection(self.STAT_METHOD,
'Statistical Method', self.STATISTICS, 2))
self.tr('Statistical Method'), self.STATISTICS, 2))
self.addParameter(ParameterSelection(self.DIST_METHOD,
'Distance Method', self.DISTANCE, 1))
self.tr('Distance Method'), self.DISTANCE, 1))
self.addParameter(ParameterBoolean(self.EDGE_CONTAM,
'Check for edge contamination', True))
self.tr('Check for edge contamination'), True))

self.addOutput(OutputRaster(self.DIST_DOWN_GRID,
'D-Infinity Drop to Stream Grid'))
self.tr('D-Infinity Drop to Stream Grid')))

def processAlgorithm(self, progress):
commands = []
commands.append(os.path.join(TauDEMUtils.mpiexecPath(), 'mpiexec'))

processNum = ProcessingConfig.getSetting(TauDEMUtils.MPI_PROCESSES)
if processNum <= 0:
raise GeoAlgorithmExecutionException('Wrong number of MPI \
processes used.\nPlease set correct number before running \
TauDEM algorithms.')
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))
Expand All @@ -127,10 +127,4 @@ def processAlgorithm(self, progress):
commands.append('-dd')
commands.append(self.getOutputValue(self.DIST_DOWN_GRID))

loglines = []
loglines.append('TauDEM execution command')
for line in commands:
loglines.append(line)
ProcessingLog.addToLog(ProcessingLog.LOG_INFO, loglines)

TauDEMUtils.executeTauDEM(commands, progress)
32 changes: 13 additions & 19 deletions python/plugins/processing/algs/taudem/dinfdistup.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,32 +78,32 @@ def defineCharacteristics(self):
self.group = 'Specialized Grid Analysis tools'

self.addParameter(ParameterRaster(self.DINF_FLOW_DIR_GRID,
'D-Infinity Flow Direction Grid', False))
self.tr('D-Infinity Flow Direction Grid'), False))
self.addParameter(ParameterRaster(self.PIT_FILLED_GRID,
'Pit Filled Elevation Grid', False))
self.addParameter(ParameterRaster(self.SLOPE_GRID, 'Slope Grid',
False))
self.tr('Pit Filled Elevation Grid'), False))
self.addParameter(ParameterRaster(self.SLOPE_GRID,
self.tr('Slope Grid'), False))
self.addParameter(ParameterSelection(self.STAT_METHOD,
'Statistical Method', self.STATISTICS, 2))
self.tr('Statistical Method'), self.STATISTICS, 2))
self.addParameter(ParameterSelection(self.DIST_METHOD,
'Distance Method', self.DISTANCE, 1))
self.tr('Distance Method'), self.DISTANCE, 1))
self.addParameter(ParameterNumber(self.THRESHOLD,
'Proportion Threshold', 0, None, 0.5))
self.tr('Proportion Threshold'), 0, None, 0.5))
self.addParameter(ParameterBoolean(self.EDGE_CONTAM,
'Check for edge contamination', True))
self.tr('Check for edge contamination'), True))

self.addOutput(OutputRaster(self.DIST_UP_GRID, 'D-Infinity Distance Up'
))
self.addOutput(OutputRaster(self.DIST_UP_GRID,
self.tr('D-Infinity Distance Up')))

def processAlgorithm(self, progress):
commands = []
commands.append(os.path.join(TauDEMUtils.mpiexecPath(), 'mpiexec'))

processNum = ProcessingConfig.getSetting(TauDEMUtils.MPI_PROCESSES)
if processNum <= 0:
raise GeoAlgorithmExecutionException('Wrong number of MPI \
processes used.\nPlease set correct number before running \
TauDEM algorithms.')
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))
Expand All @@ -124,10 +124,4 @@ def processAlgorithm(self, progress):
commands.append('-du')
commands.append(self.getOutputValue(self.DIST_UP_GRID))

loglines = []
loglines.append('TauDEM execution command')
for line in commands:
loglines.append(line)
ProcessingLog.addToLog(ProcessingLog.LOG_INFO, loglines)

TauDEMUtils.executeTauDEM(commands, progress)
31 changes: 13 additions & 18 deletions python/plugins/processing/algs/taudem/dinftranslimaccum.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,30 +67,31 @@ def defineCharacteristics(self):
self.group = 'Specialized Grid Analysis tools'

self.addParameter(ParameterRaster(self.DINF_FLOW_DIR_GRID,
'D-Infinity Flow Direction Grid', False))
self.addParameter(ParameterRaster(self.SUPPLY_GRID, 'Supply Grid',
False))
self.tr('D-Infinity Flow Direction Grid'), False))
self.addParameter(ParameterRaster(self.SUPPLY_GRID,
self.tr('Supply Grid'), False))
self.addParameter(ParameterRaster(self.CAPACITY_GRID,
'Transport Capacity Grid', False))
self.tr('Transport Capacity Grid'), False))
self.addParameter(ParameterVector(self.OUTLETS_SHAPE,
'Outlets Shapefile',
[ParameterVector.VECTOR_TYPE_POINT], True))
self.tr('Outlets Shapefile'),
[ParameterVector.VECTOR_TYPE_POINT], True))
self.addParameter(ParameterBoolean(self.EDGE_CONTAM,
'Check for edge contamination', True))
self.tr('Check for edge contamination'), True))

self.addOutput(OutputRaster(self.TRANSP_LIM_ACCUM_GRID,
'Transport Limited Accumulation Grid'))
self.addOutput(OutputRaster(self.DEPOSITION_GRID, 'Deposition Grid'))
self.tr('Transport Limited Accumulation Grid')))
self.addOutput(OutputRaster(self.DEPOSITION_GRID,
self.tr('Deposition Grid')))

def processAlgorithm(self, progress):
commands = []
commands.append(os.path.join(TauDEMUtils.mpiexecPath(), 'mpiexec'))

processNum = ProcessingConfig.getSetting(TauDEMUtils.MPI_PROCESSES)
if processNum <= 0:
raise GeoAlgorithmExecutionException('Wrong number of MPI \
processes used.\nPlease set correct number before running \
TauDEM algorithms.')
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))
Expand All @@ -113,10 +114,4 @@ def processAlgorithm(self, progress):
commands.append('-tdep')
commands.append(self.getOutputValue(self.DEPOSITION_GRID))

loglines = []
loglines.append('TauDEM execution command')
for line in commands:
loglines.append(line)
ProcessingLog.addToLog(ProcessingLog.LOG_INFO, loglines)

TauDEMUtils.executeTauDEM(commands, progress)
35 changes: 15 additions & 20 deletions python/plugins/processing/algs/taudem/dinftranslimaccum2.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,34 +67,35 @@ def defineCharacteristics(self):
self.group = 'Specialized Grid Analysis tools'

self.addParameter(ParameterRaster(self.DINF_FLOW_DIR_GRID,
'D-Infinity Flow Direction Grid', False))
self.addParameter(ParameterRaster(self.SUPPLY_GRID, 'Supply Grid',
False))
self.tr('D-Infinity Flow Direction Grid'), False))
self.addParameter(ParameterRaster(self.SUPPLY_GRID,
self.tr('Supply Grid'), False))
self.addParameter(ParameterRaster(self.CAPACITY_GRID,
'Transport Capacity Grid', False))
self.tr('Transport Capacity Grid'), False))
self.addParameter(ParameterRaster(self.IN_CONCENTR_GRID,
'Input Concentration Grid', False))
self.tr('Input Concentration Grid'), False))
self.addParameter(ParameterVector(self.OUTLETS_SHAPE,
'Outlets Shapefile',
[ParameterVector.VECTOR_TYPE_POINT], True))
self.tr('Outlets Shapefile'),
[ParameterVector.VECTOR_TYPE_POINT], True))
self.addParameter(ParameterBoolean(self.EDGE_CONTAM,
'Check for edge contamination', True))
self.tr('Check for edge contamination'), True))

self.addOutput(OutputRaster(self.TRANSP_LIM_ACCUM_GRID,
'Transport Limited Accumulation Grid'))
self.addOutput(OutputRaster(self.DEPOSITION_GRID, 'Deposition Grid'))
self.tr('Transport Limited Accumulation Grid')))
self.addOutput(OutputRaster(self.DEPOSITION_GRID,
self.tr('Deposition Grid')))
self.addOutput(OutputRaster(self.OUT_CONCENTR_GRID,
'Output Concentration Grid'))
self.tr('Output Concentration Grid')))

def processAlgorithm(self, progress):
commands = []
commands.append(os.path.join(TauDEMUtils.mpiexecPath(), 'mpiexec'))

processNum = ProcessingConfig.getSetting(TauDEMUtils.MPI_PROCESSES)
if processNum <= 0:
raise GeoAlgorithmExecutionException('Wrong number of MPI \
processes used.\nPlease set correct number before running \
TauDEM algorithms.')
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))
Expand All @@ -121,10 +122,4 @@ def processAlgorithm(self, progress):
commands.append('-ctpt')
commands.append(self.getOutputValue(self.OUT_CONCENTR_GRID))

loglines = []
loglines.append('TauDEM execution command')
for line in commands:
loglines.append(line)
ProcessingLog.addToLog(ProcessingLog.LOG_INFO, loglines)

TauDEMUtils.executeTauDEM(commands, progress)
34 changes: 14 additions & 20 deletions python/plugins/processing/algs/taudem/dropanalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,35 +71,35 @@ def defineCharacteristics(self):
self.group = 'Stream Network Analysis tools'

self.addParameter(ParameterRaster(self.D8_CONTRIB_AREA_GRID,
'D8 Contributing Area Grid', False))
self.tr('D8 Contributing Area Grid'), False))
self.addParameter(ParameterRaster(self.D8_FLOW_DIR_GRID,
'D8 Flow Direction Grid', False))
self.tr('D8 Flow Direction Grid'), False))
self.addParameter(ParameterRaster(self.PIT_FILLED_GRID,
'Pit Filled Elevation Grid', False))
self.tr('Pit Filled Elevation Grid'), False))
self.addParameter(ParameterRaster(self.ACCUM_STREAM_SOURCE_GRID,
'Accumulated Stream Source Grid', False))
self.tr('Accumulated Stream Source Grid'), False))
self.addParameter(ParameterVector(self.OUTLETS_SHAPE,
'Outlets Shapefile',
[ParameterVector.VECTOR_TYPE_POINT], False))
self.tr('Outlets Shapefile'),
[ParameterVector.VECTOR_TYPE_POINT], False))
self.addParameter(ParameterNumber(self.MIN_TRESHOLD,
'Minimum Threshold', 0, None, 5))
self.tr('Minimum Threshold'), 0, None, 5))
self.addParameter(ParameterNumber(self.MAX_THRESHOLD,
'Maximum Threshold', 0, None, 500))
self.tr('Maximum Threshold'), 0, None, 500))
self.addParameter(ParameterNumber(self.TRESHOLD_NUM,
'Number of Threshold Values', 0, None, 10))
self.tr('Number of Threshold Values'), 0, None, 10))
self.addParameter(ParameterSelection(self.STEP_TYPE,
'Spacing for Threshold Values', self.STEPS, 0))
self.tr('Spacing for Threshold Values'), self.STEPS, 0))
self.addOutput(OutputFile(self.DROP_ANALYSIS_FILE,
'D-Infinity Drop to Stream Grid'))
self.tr('D-Infinity Drop to Stream Grid')))

def processAlgorithm(self, progress):
commands.append(os.path.join(TauDEMUtils.mpiexecPath(), 'mpiexec'))

processNum = ProcessingConfig.getSetting(TauDEMUtils.MPI_PROCESSES)
if processNum <= 0:
raise GeoAlgorithmExecutionException('Wrong number of MPI \
processes used.\nPlease set correct number before running \
TauDEM algorithms.')
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))
Expand All @@ -122,10 +122,4 @@ def processAlgorithm(self, progress):
commands.append('-drp')
commands.append(self.getOutputValue(self.DROP_ANALYSIS_FILE))

loglines = []
loglines.append('TauDEM execution command')
for line in commands:
loglines.append(line)
ProcessingLog.addToLog(ProcessingLog.LOG_INFO, loglines)

TauDEMUtils.executeTauDEM(commands, progress)
Loading

0 comments on commit e1d8710

Please sign in to comment.