30
30
from PyQt4 .QtGui import QIcon
31
31
32
32
from processing .core .AlgorithmProvider import AlgorithmProvider
33
- from processing .core .ProcessingConfig import ProcessingConfig
34
- from processing .core .ProcessingConfig import Setting
33
+ from processing .core .ProcessingConfig import ProcessingConfig , Setting
35
34
from processing .core .ProcessingLog import ProcessingLog
35
+
36
36
from TauDEMAlgorithm import TauDEMAlgorithm
37
+ from TauDEMMultifileAlgorithm import TauDEMMultifileAlgorithm
37
38
from TauDEMUtils import TauDEMUtils
39
+
38
40
from peukerdouglas import PeukerDouglas
39
41
from slopearea import SlopeArea
40
42
from lengtharea import LengthArea
45
47
from dinftranslimaccum import DinfTransLimAccum
46
48
from dinftranslimaccum2 import DinfTransLimAccum2
47
49
50
+ from peukerdouglas_multi import PeukerDouglasMulti
51
+ from slopearea_multi import SlopeAreaMulti
52
+ from lengtharea_multi import LengthAreaMulti
53
+ from dropanalysis_multi import DropAnalysisMulti
54
+ from dinfdistdown_multi import DinfDistDownMulti
55
+ from dinfdistup_multi import DinfDistUpMulti
56
+ from gridnet_multi import GridNetMulti
57
+ from dinftranslimaccum_multi import DinfTransLimAccumMulti
58
+ from dinftranslimaccum2_multi import DinfTransLimAccum2Multi
59
+
48
60
49
61
class TauDEMAlgorithmProvider (AlgorithmProvider ):
50
62
51
63
def __init__ (self ):
52
64
AlgorithmProvider .__init__ (self )
53
65
self .activate = False
54
- self .createAlgsList ()
55
66
56
67
def getDescription (self ):
57
68
return self .tr ('TauDEM (hydrologic analysis)' )
@@ -64,10 +75,21 @@ def getIcon(self):
64
75
65
76
def initializeSettings (self ):
66
77
AlgorithmProvider .initializeSettings (self )
78
+
67
79
ProcessingConfig .addSetting (Setting (self .getDescription (),
68
80
TauDEMUtils .TAUDEM_FOLDER ,
69
81
self .tr ('TauDEM command line tools folder' ),
70
82
TauDEMUtils .taudemPath ()))
83
+ ProcessingConfig .addSetting (Setting (self .getDescription (),
84
+ TauDEMUtils .TAUDEM_MULTIFILE_FOLDER ,
85
+ self .tr ('TauDEM multifile command line tools folder' ),
86
+ TauDEMUtils .taudemMultifilePath ()))
87
+ ProcessingConfig .addSetting (Setting (self .getDescription (),
88
+ TauDEMUtils .TAUDEM_USE_SINGLEFILE ,
89
+ self .tr ('Enable singlefile TauDEM tools' ), True ))
90
+ ProcessingConfig .addSetting (Setting (self .getDescription (),
91
+ TauDEMUtils .TAUDEM_USE_MULTIFILE ,
92
+ self .tr ('Enable multifile TauDEM tools' ), False ))
71
93
ProcessingConfig .addSetting (Setting (self .getDescription (),
72
94
TauDEMUtils .MPIEXEC_FOLDER ,
73
95
self .tr ('MPICH2/OpenMPI bin directory' ),
@@ -78,36 +100,65 @@ def initializeSettings(self):
78
100
79
101
def unload (self ):
80
102
AlgorithmProvider .unload (self )
103
+
81
104
ProcessingConfig .removeSetting (TauDEMUtils .TAUDEM_FOLDER )
105
+ ProcessingConfig .removeSetting (TauDEMUtils .TAUDEM_MULTIFILE_FOLDER )
106
+ ProcessingConfig .removeSetting (TauDEMUtils .TAUDEM_USE_SINGLEFILE )
107
+ ProcessingConfig .removeSetting (TauDEMUtils .TAUDEM_USE_MULTIFILE )
82
108
ProcessingConfig .removeSetting (TauDEMUtils .MPIEXEC_FOLDER )
83
109
ProcessingConfig .removeSetting (TauDEMUtils .MPI_PROCESSES )
84
110
85
111
def _loadAlgorithms (self ):
86
- self .algs = self .preloadedAlgs
87
-
88
- def createAlgsList (self ):
89
- self .preloadedAlgs = []
90
- folder = TauDEMUtils .taudemDescriptionPath ()
91
- for descriptionFile in os .listdir (folder ):
92
- if descriptionFile .endswith ('txt' ):
93
- try :
94
- alg = TauDEMAlgorithm (os .path .join (folder ,
95
- descriptionFile ))
96
- if alg .name .strip () != '' :
97
- self .preloadedAlgs .append (alg )
98
- else :
99
- ProcessingLog .addToLog (ProcessingLog .LOG_ERROR ,
100
- self .tr ('Could not open TauDEM algorithm: %s' % descriptionFile ))
101
- except Exception , e :
102
- ProcessingLog .addToLog (ProcessingLog .LOG_ERROR ,
103
- self .tr ('Could not open TauDEM algorithm: %s' % descriptionFile ))
104
-
105
- self .preloadedAlgs .append (PeukerDouglas ())
106
- self .preloadedAlgs .append (SlopeArea ())
107
- self .preloadedAlgs .append (LengthArea ())
108
- self .preloadedAlgs .append (DropAnalysis ())
109
- self .preloadedAlgs .append (DinfDistDown ())
110
- self .preloadedAlgs .append (DinfDistUp ())
111
- self .preloadedAlgs .append (GridNet ())
112
- self .preloadedAlgs .append (DinfTransLimAccum ())
113
- self .preloadedAlgs .append (DinfTransLimAccum2 ())
112
+ self .algs = []
113
+ basePath = TauDEMUtils .taudemDescriptionPath ()
114
+
115
+ if ProcessingConfig .getSetting (TauDEMUtils .TAUDEM_USE_SINGLEFILE ):
116
+ folder = os .path .join (basePath , 'single' )
117
+
118
+ for descriptionFile in os .listdir (folder ):
119
+ if descriptionFile .endswith ('txt' ):
120
+ descriptionFile = os .path .join (folder , descriptionFile )
121
+ self ._algFromDescription (descriptionFile )
122
+
123
+ self .algs .append (PeukerDouglas ())
124
+ self .algs .append (SlopeArea ())
125
+ self .algs .append (LengthArea ())
126
+ self .algs .append (DropAnalysis ())
127
+ self .algs .append (DinfDistDown ())
128
+ self .algs .append (DinfDistUp ())
129
+ self .algs .append (GridNet ())
130
+ self .algs .append (DinfTransLimAccum ())
131
+ self .algs .append (DinfTransLimAccum2 ())
132
+
133
+ if ProcessingConfig .getSetting (TauDEMUtils .TAUDEM_USE_MULTIFILE ):
134
+ folder = os .path .join (basePath , 'multi' )
135
+
136
+ for descriptionFile in os .listdir (folder ):
137
+ if descriptionFile .endswith ('txt' ):
138
+ descriptionFile = os .path .join (folder , descriptionFile )
139
+ self ._algFromDescription (descriptionFile , True )
140
+
141
+ self .algs .append (PeukerDouglasMulti ())
142
+ self .algs .append (SlopeAreaMulti ())
143
+ self .algs .append (LengthAreaMulti ())
144
+ self .algs .append (DropAnalysisMulti ())
145
+ self .algs .append (DinfDistDownMulti ())
146
+ self .algs .append (DinfDistUpMulti ())
147
+ self .algs .append (GridNetMulti ())
148
+ self .algs .append (DinfTransLimAccumMulti ())
149
+ self .algs .append (DinfTransLimAccum2Multi ())
150
+
151
+ def _algFromDescription (self , descriptionFile , multifile = False ):
152
+ try :
153
+ if multifile :
154
+ alg = TauDEMMultifileAlgorithm (descriptionFile )
155
+ else :
156
+ alg = TauDEMAlgorithm (descriptionFile )
157
+ if alg .name .strip () != '' :
158
+ self .algs .append (alg )
159
+ else :
160
+ ProcessingLog .addToLog (ProcessingLog .LOG_ERROR ,
161
+ self .tr ('Could not open TauDEM algorithm: %s' % descriptionFile ))
162
+ except Exception , e :
163
+ ProcessingLog .addToLog (ProcessingLog .LOG_ERROR ,
164
+ self .tr ('Could not open TauDEM algorithm %s:\n %s' % (descriptionFile , str (e ))))
0 commit comments