Skip to content
Permalink
Browse files

[FEATURE] TauDEM provider for SEXTANTE

  • Loading branch information
alexbruy committed Oct 22, 2012
1 parent 4c161c9 commit a45b759e1c6e8f86252144968fc7c664706714fd
Showing with 3,342 additions and 14 deletions.
  1. +1 −0 python/plugins/sextante/CMakeLists.txt
  2. +22 −14 python/plugins/sextante/core/Sextante.py
  3. BIN python/plugins/sextante/images/taudem.png
  4. +7 −0 python/plugins/sextante/taudem/CMakeLists.txt
  5. +131 −0 python/plugins/sextante/taudem/TauDEMAlgorithm.py
  6. +101 −0 python/plugins/sextante/taudem/TauDEMAlgorithmProvider.py
  7. +68 −0 python/plugins/sextante/taudem/TauDEMUtils.py
  8. 0 python/plugins/sextante/taudem/__init__.py
  9. +8 −0 python/plugins/sextante/taudem/description/aread8.txt
  10. +8 −0 python/plugins/sextante/taudem/description/areadinf.txt
  11. +6 −0 python/plugins/sextante/taudem/description/d8flowdir.txt
  12. +9 −0 python/plugins/sextante/taudem/description/d8flowpathextremeup.txt
  13. +7 −0 python/plugins/sextante/taudem/description/d8hdisttostrm.txt
  14. +11 −0 python/plugins/sextante/taudem/description/dinfavalanche.txt
  15. +11 −0 python/plugins/sextante/taudem/description/dinfconclimaccum.txt
  16. +9 −0 python/plugins/sextante/taudem/description/dinfdecayaccum.txt
  17. +6 −0 python/plugins/sextante/taudem/description/dinfflowdir.txt
  18. +7 −0 python/plugins/sextante/taudem/description/dinfrevaccum.txt
  19. +6 −0 python/plugins/sextante/taudem/description/dinfupdependence.txt
  20. +8 −0 python/plugins/sextante/taudem/description/moveoutletstostrm.txt
  21. +5 −0 python/plugins/sextante/taudem/description/pitremove.txt
  22. +6 −0 python/plugins/sextante/taudem/description/slopearearatio.txt
  23. +7 −0 python/plugins/sextante/taudem/description/slopeavedown.txt
  24. +14 −0 python/plugins/sextante/taudem/description/streamnet.txt
  25. +7 −0 python/plugins/sextante/taudem/description/threshold.txt
  26. +123 −0 python/plugins/sextante/taudem/dinfdistdown.py
  27. +120 −0 python/plugins/sextante/taudem/dinfdistup.py
  28. +112 −0 python/plugins/sextante/taudem/dinftranslimaccum.py
  29. +118 −0 python/plugins/sextante/taudem/dinftranslimaccum2.py
  30. +117 −0 python/plugins/sextante/taudem/dropanalysis.py
  31. +112 −0 python/plugins/sextante/taudem/gridnet.py
  32. +73 −0 python/plugins/sextante/taudem/help/aread8.html
  33. +103 −0 python/plugins/sextante/taudem/help/areadinf.html
  34. +69 −0 python/plugins/sextante/taudem/help/d8flowdir.html
  35. +61 −0 python/plugins/sextante/taudem/help/d8flowpathextremeup.html
  36. +45 −0 python/plugins/sextante/taudem/help/d8hdisttostrm.html
  37. +119 −0 python/plugins/sextante/taudem/help/dinfavalanche.html
  38. +100 −0 python/plugins/sextante/taudem/help/dinfconclimaccum.html
  39. +72 −0 python/plugins/sextante/taudem/help/dinfdecayaccum.html
  40. +86 −0 python/plugins/sextante/taudem/help/dinfdistdown.html
  41. +83 −0 python/plugins/sextante/taudem/help/dinfdistup.html
  42. +77 −0 python/plugins/sextante/taudem/help/dinfflowdir.html
  43. +48 −0 python/plugins/sextante/taudem/help/dinfrevaccum.html
  44. +104 −0 python/plugins/sextante/taudem/help/dinftranslimaccum.html
  45. +50 −0 python/plugins/sextante/taudem/help/dinfupdependence.html
  46. +117 −0 python/plugins/sextante/taudem/help/dropanalysis.html
  47. +88 −0 python/plugins/sextante/taudem/help/gridnet.html
  48. +9 −0 python/plugins/sextante/taudem/help/help.css
  49. BIN python/plugins/sextante/taudem/help/img/arexample.gif
  50. BIN python/plugins/sextante/taudem/help/img/claeqn.gif
  51. BIN python/plugins/sextante/taudem/help/img/clafig.gif
  52. BIN python/plugins/sextante/taudem/help/img/d8index.gif
  53. BIN python/plugins/sextante/taudem/help/img/decay.gif
  54. BIN python/plugins/sextante/taudem/help/img/decayeqn.gif
  55. BIN python/plugins/sextante/taudem/help/img/dependence.gif
  56. BIN python/plugins/sextante/taudem/help/img/raccfig.gif
  57. BIN python/plugins/sextante/taudem/help/img/streamdrops.jpg
  58. BIN python/plugins/sextante/taudem/help/img/tardemfig.gif
  59. BIN python/plugins/sextante/taudem/help/img/tlaceqn1.gif
  60. BIN python/plugins/sextante/taudem/help/img/tlaceqn2.gif
  61. BIN python/plugins/sextante/taudem/help/img/tlaceqn3.gif
  62. BIN python/plugins/sextante/taudem/help/img/tlaceqn4.gif
  63. BIN python/plugins/sextante/taudem/help/img/tlaceqn5.gif
  64. BIN python/plugins/sextante/taudem/help/img/tlaeqn.gif
  65. +61 −0 python/plugins/sextante/taudem/help/lengtharea.html
  66. +67 −0 python/plugins/sextante/taudem/help/moveoutletstostrm.html
  67. +56 −0 python/plugins/sextante/taudem/help/peukerdouglas.html
  68. +40 −0 python/plugins/sextante/taudem/help/pitremove.html
  69. +43 −0 python/plugins/sextante/taudem/help/slopearea.html
  70. +38 −0 python/plugins/sextante/taudem/help/slopearearatio.html
  71. +40 −0 python/plugins/sextante/taudem/help/slopeavedown.html
  72. +184 −0 python/plugins/sextante/taudem/help/streamnet.html
  73. +52 −0 python/plugins/sextante/taudem/help/threshold.html
  74. +97 −0 python/plugins/sextante/taudem/lengtharea.py
  75. +96 −0 python/plugins/sextante/taudem/peukerdouglas.py
  76. +97 −0 python/plugins/sextante/taudem/slopearea.py
@@ -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()
Binary file not shown.
@@ -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)
No changes.
@@ -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.
You can’t perform that action at this time.