forked from dtarb/TauDEM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPitRemove.py
82 lines (51 loc) · 1.82 KB
/
PitRemove.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Script Name: Remove Pits
#
# Created By: David Tarboton
# Date: 9/21/11
# Import ArcPy site-package and os modules
#
import arcpy
import os
import subprocess
# Get and describe the first argument
#
inLyr = arcpy.GetParameterAsText(0)
desc = arcpy.Describe(inLyr)
inZfile = str(desc.catalogPath)
arcpy.AddMessage("\nInput Elevation file: " + inZfile)
considering4way = arcpy.GetParameterAsText(1)
arcpy.AddMessage("Considering4way: " + considering4way)
maskgrid = arcpy.GetParameterAsText(2)
if arcpy.Exists(maskgrid):
desc = arcpy.Describe(maskgrid)
mkgr=str(desc.catalogPath)
arcpy.AddMessage("Input Mask Grid: "+mkgr)
# Get the Input No. of Processes
#
inputProc=arcpy.GetParameterAsText(3)
arcpy.AddMessage(" Number of Processes: "+inputProc)
# Get the output file
#
outFile = arcpy.GetParameterAsText(4)
arcpy.AddMessage("Output Pit Removed Elevation file: " + outFile)
# Construct the taudem command line. Put quotes around file names in case there are spaces
# Construct command
cmd = 'mpiexec -n ' + inputProc + ' pitremove -z ' + '"' + inZfile + '"' + ' -fel ' + '"' + outFile + '"'
if considering4way == 'true':
cmd = cmd + ' -4way '
if arcpy.Exists(maskgrid):
cmd = cmd + ' -depmask ' + '"' + mkgr + '"'
if arcpy.Exists(maskgrid) and considering4way == 'true':
cmd = cmd + ' -depmask ' + '"' + mkgr + '"' + ' -4way '
arcpy.AddMessage("\nCommand Line: "+cmd)
os.system(cmd)
process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
message = "\n"
for line in process.stdout.readlines():
if isinstance(line, bytes): # true in Python 3
line = line.decode()
message = message + line
arcpy.AddMessage(message)
# Calculate statistics so that grids display with correct bounds
arcpy.AddMessage('Calculate Statistics\n')
arcpy.CalculateStatistics_management(outFile)