Skip to content
Permalink
Browse files
[FEATURE] TauDEM provider for SEXTANTE
  • Loading branch information
alexbruy committed Oct 22, 2012
1 parent 4c161c9 commit a45b759
Show file tree
Hide file tree
Showing 76 changed files with 3,342 additions and 14 deletions.
@@ -19,6 +19,7 @@ ADD_SUBDIRECTORY(pymorph)
ADD_SUBDIRECTORY(r)
ADD_SUBDIRECTORY(saga)
ADD_SUBDIRECTORY(script)
ADD_SUBDIRECTORY(taudem)
#ADD_SUBDIRECTORY(tests)

FILE(GLOB OTHER_FILES metadata.txt)
@@ -26,30 +26,37 @@

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from sextante.saga.SagaAlgorithmProvider import SagaAlgorithmProvider
from sextante.script.ScriptAlgorithmProvider import ScriptAlgorithmProvider

from sextante.core.QGisLayers import QGisLayers
from sextante.gui.AlgorithmExecutor import AlgorithmExecutor
from sextante.core.SextanteConfig import SextanteConfig
from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.core.SextanteLog import SextanteLog
from sextante.modeler.ModelerAlgorithmProvider import ModelerAlgorithmProvider
from sextante.ftools.FToolsAlgorithmProvider import FToolsAlgorithmProvider

from sextante.gui.AlgorithmExecutor import AlgorithmExecutor
from sextante.gui.RenderingStyles import RenderingStyles
from sextante.gui.SextantePostprocessing import SextantePostprocessing
from sextante.gui.UnthreadedAlgorithmExecutor import UnthreadedAlgorithmExecutor,\
SilentProgress

from sextante.modeler.Providers import Providers
from sextante.r.RAlgorithmProvider import RAlgorithmProvider
from sextante.parameters.ParameterSelection import ParameterSelection
from sextante.grass.GrassAlgorithmProvider import GrassAlgorithmProvider
from sextante.gui.RenderingStyles import RenderingStyles
from sextante.modeler.ModelerAlgorithmProvider import ModelerAlgorithmProvider
from sextante.modeler.ModelerOnlyAlgorithmProvider import ModelerOnlyAlgorithmProvider

from sextante.algs.SextanteAlgorithmProvider import SextanteAlgorithmProvider

from sextante.parameters.ParameterSelection import ParameterSelection

from sextante.ftools.FToolsAlgorithmProvider import FToolsAlgorithmProvider
from sextante.gdal.GdalAlgorithmProvider import GdalAlgorithmProvider
from sextante.grass.GrassAlgorithmProvider import GrassAlgorithmProvider
from sextante.lidar.LidarToolsAlgorithmProvider import LidarToolsAlgorithmProvider
from sextante.mmqgisx.MMQGISXAlgorithmProvider import MMQGISXAlgorithmProvider
from sextante.otb.OTBAlgorithmProvider import OTBAlgorithmProvider
from sextante.algs.SextanteAlgorithmProvider import SextanteAlgorithmProvider
from sextante.pymorph.PymorphAlgorithmProvider import PymorphAlgorithmProvider
from sextante.mmqgisx.MMQGISXAlgorithmProvider import MMQGISXAlgorithmProvider
from sextante.lidar.LidarToolsAlgorithmProvider import LidarToolsAlgorithmProvider
from sextante.gui.UnthreadedAlgorithmExecutor import UnthreadedAlgorithmExecutor,\
SilentProgress
from sextante.r.RAlgorithmProvider import RAlgorithmProvider
from sextante.saga.SagaAlgorithmProvider import SagaAlgorithmProvider
from sextante.script.ScriptAlgorithmProvider import ScriptAlgorithmProvider
from sextante.taudem.TauDEMAlgorithmProvider import TauDEMAlgorithmProvider

class Sextante:

@@ -122,6 +129,7 @@ def initialize():
Sextante.addProvider(SagaAlgorithmProvider())
Sextante.addProvider(GrassAlgorithmProvider())
Sextante.addProvider(ScriptAlgorithmProvider())
Sextante.addProvider(TauDEMAlgorithmProvider())
Sextante.modeler.initializeSettings();
#and initialize
SextanteLog.startLogging()
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,7 @@
FILE(GLOB PY_FILES *.py)
FILE(GLOB DESCR_FILES description/*.txt)
FILE(GLOB HELP_FILES help/*.html)

INSTALL(FILES ${PY_FILES} DESTINATION ${SEXTANTE_PLUGIN_DIR}/taudem)
INSTALL(FILES ${DESCR_FILES} DESTINATION ${SEXTANTE_PLUGIN_DIR}/taudem/description)
INSTALL(FILES ${HELP_FILES} DESTINATION ${SEXTANTE_PLUGIN_DIR}/taudem/help)
@@ -0,0 +1,131 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
TauDEMAlgorithm.py
---------------------
Date : October 2012
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__ = 'October 2012'
__copyright__ = '(C) 2012, Alexander Bruy'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os

from PyQt4.QtCore import *
from PyQt4.QtGui import *

from qgis.core import *

from sextante.core.GeoAlgorithm import GeoAlgorithm
from sextante.core.SextanteLog import SextanteLog
from sextante.core.SextanteUtils import SextanteUtils
from sextante.core.SextanteConfig import SextanteConfig
from sextante.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException

from sextante.parameters.ParameterFactory import ParameterFactory
from sextante.parameters.ParameterRaster import ParameterRaster
from sextante.parameters.ParameterVector import ParameterVector
from sextante.parameters.ParameterBoolean import ParameterBoolean
from sextante.parameters.ParameterString import ParameterString
from sextante.parameters.ParameterNumber import ParameterNumber

from sextante.outputs.OutputFactory import OutputFactory
from sextante.outputs.OutputRaster import OutputRaster
from sextante.outputs.OutputVector import OutputVector
from sextante.outputs.OutputFile import OutputFile

from sextante.taudem.TauDEMUtils import TauDEMUtils

class TauDEMAlgorithm(GeoAlgorithm):

def __init__(self, descriptionfile):
GeoAlgorithm.__init__(self)
self.descriptionFile = descriptionfile
self.defineCharacteristicsFromFile()

def getCopy(self):
newone = TauDEMAlgorithm(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
while line != "":
try:
line = line.strip("\n").strip()
if line.startswith("Parameter"):
param = ParameterFactory.getFromString(line)
self.addParameter(param)
else:
self.addOutput(OutputFactory.getFromString(line))
line = lines.readline().strip("\n").strip()
except Exception, e:
SextanteLog.addToLog(SextanteLog.LOG_ERROR, "Could not load TauDEM algorithm: " + self.descriptionFile + "\n" + line)
raise e
lines.close()

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

processNum = SextanteConfig.getSetting(TauDEMUtils.MPI_PROCESSES)
if processNum <= 0:
raise GeoAlgorithmExecutionException("Wrong number of MPI processes used.\nPlease set correct number before running TauDEM algorithms.")

commands.append("-n")
commands.append(str(processNum))
commands.append(os.path.join(TauDEMUtils.taudemPath(), self.cmdName))

for param in self.parameters:
if param.value == None or param.value == "":
continue
if isinstance(param, ParameterNumber):
commands.append(param.name)
commands.append(str(param.value))
if isinstance(param, (ParameterRaster, 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)

loglines = []
loglines.append("TauDEM execution command")
for line in commands:
loglines.append(line)
SextanteLog.addToLog(SextanteLog.LOG_INFO, loglines)
TauDEMUtils.executeTauDEM(commands, progress)

def helpFile(self):
return os.path.join(os.path.dirname(__file__), "help", self.cmdName + ".html")
@@ -0,0 +1,101 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
TauDEMAlgorithmProvider.py
---------------------
Date : October 2012
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__ = 'October 2012'
__copyright__ = '(C) 2012, 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 *

from sextante.core.AlgorithmProvider import AlgorithmProvider
from sextante.core.SextanteConfig import SextanteConfig
from sextante.core.SextanteConfig import Setting
from sextante.core.SextanteLog import SextanteLog

from sextante.taudem.TauDEMAlgorithm import TauDEMAlgorithm
from sextante.taudem.TauDEMUtils import TauDEMUtils

from sextante.taudem.peukerdouglas import PeukerDouglas
from sextante.taudem.slopearea import SlopeArea
from sextante.taudem.lengtharea import LengthArea
from sextante.taudem.dropanalysis import DropAnalysis
from sextante.taudem.dinfdistdown import DinfDistDown
from sextante.taudem.dinfdistup import DinfDistUp
from sextante.taudem.gridnet import GridNet
from sextante.taudem.dinftranslimaccum import DinfTransLimAccum
from sextante.taudem.dinftranslimaccum2 import DinfTransLimAccum2

class TauDEMAlgorithmProvider(AlgorithmProvider):

def __init__(self):
AlgorithmProvider.__init__(self)
self.createAlgsList()

def getDescription(self):
return "TauDEM (hydrologic analysis)"

def getName(self):
return "taudem"

def getIcon(self):
return QIcon(os.path.dirname(__file__) + "/../images/taudem.png")

def initializeSettings(self):
AlgorithmProvider.initializeSettings(self)
SextanteConfig.addSetting(Setting(self.getDescription(), TauDEMUtils.TAUDEM_FOLDER, "TauDEM command line tools folder", TauDEMUtils.taudemPath()))
SextanteConfig.addSetting(Setting(self.getDescription(), TauDEMUtils.MPIEXEC_FOLDER, "MPICH2/OpenMPI bin directory", TauDEMUtils.mpiexecPath()))
SextanteConfig.addSetting(Setting(self.getDescription(), TauDEMUtils.MPI_PROCESSES, "Number of MPI parallel processes to use", 2))

def unload(self):
AlgorithmProvider.unload(self)
SextanteConfig.removeSetting(TauDEMUtils.TAUDEM_FOLDER)
SextanteConfig.removeSetting(TauDEMUtils.MPIEXEC_FOLDER)
SextanteConfig.removeSetting(TauDEMUtils.MPI_PROCESSES)

def _loadAlgorithms(self):
self.algs = self.preloadedAlgs

def createAlgsList(self):
self.preloadedAlgs = []
folder = TauDEMUtils.taudemDescriptionPath()
for descriptionFile in os.listdir(folder):
if descriptionFile.endswith("txt"):
try:
alg = TauDEMAlgorithm(os.path.join(folder, descriptionFile))
if alg.name.strip() != "":
self.preloadedAlgs.append(alg)
else:
SextanteLog.addToLog(SextanteLog.LOG_ERROR, "Could not open TauDEM algorithm: " + descriptionFile)
except Exception, e:
SextanteLog.addToLog(SextanteLog.LOG_ERROR, "Could not open TauDEM algorithm: " + descriptionFile)

self.preloadedAlgs.append(PeukerDouglas())
self.preloadedAlgs.append(SlopeArea())
self.preloadedAlgs.append(LengthArea())
self.preloadedAlgs.append(DropAnalysis())
self.preloadedAlgs.append(DinfDistDown())
self.preloadedAlgs.append(DinfDistUp())
self.preloadedAlgs.append(GridNet())
self.preloadedAlgs.append(DinfTransLimAccum())
self.preloadedAlgs.append(DinfTransLimAccum2())
@@ -0,0 +1,68 @@
# -*- coding: utf-8 -*-

"""
***************************************************************************
TauDEMUtils.py
---------------------
Date : October 2012
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__ = 'October 2012'
__copyright__ = '(C) 2012, Alexander Bruy'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os
import subprocess

from sextante.core.SextanteConfig import SextanteConfig
from sextante.core.SextanteLog import SextanteLog
from sextante.core.SextanteUtils import SextanteUtils

class TauDEMUtils:

TAUDEM_FOLDER = "TAUDEM_FOLDER"
MPIEXEC_FOLDER = "MPIEXEC_FOLDER"
MPI_PROCESSES = "MPI_PROCESSES"

@staticmethod
def taudemPath():
folder = SextanteConfig.getSetting(TauDEMUtils.TAUDEM_FOLDER)
if folder == None:
folder = ""

return folder

@staticmethod
def mpiexecPath():
folder = SextanteConfig.getSetting(TauDEMUtils.MPIEXEC_FOLDER)
if folder == None:
folder = ""

return folder

@staticmethod
def taudemDescriptionPath():
return os.path.normpath(os.path.join(os.path.dirname(__file__), "description"))

@staticmethod
def executeTauDEM(command, progress):
loglines = []
loglines.append("TauDEM execution console output")
fused_command = ''.join(['"%s" ' % c for c in command])
proc = subprocess.Popen(fused_command, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True).stdout
for line in iter(proc.readline, ""):
loglines.append(line)
SextanteLog.addToLog(SextanteLog.LOG_INFO, loglines)
Empty file.
@@ -0,0 +1,8 @@
D8 Contributing Area
aread8
Basic Grid Analysis tools
ParameterRaster|-p|D8 Flow Direction Grid|False
ParameterVector|-o|Outlets Shapefile|0|True
ParameterRaster|-wg|Weight Grid|True
ParameterBoolean|-nc|Check for edge contamination|True
OutputRaster|-ad8|D8 Contributing Area Grid
@@ -0,0 +1,8 @@
D-Infinity Contributing Area
areadinf
Basic Grid Analysis tools
ParameterRaster|-ang|D-Infinity Flow Direction Grid|False
ParameterVector|-o|Outlets Shapefile|0|True
ParameterRaster|-wg|Weight Grid|True
ParameterBoolean|-nc|Check for edge contamination|True
OutputRaster|-sca|D-Infinity Specific Catchment Area Grid

0 comments on commit a45b759

Please sign in to comment.