forked from dtarb/TauDEM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDinfUpslopeDependence.py
51 lines (40 loc) · 1.44 KB
/
DinfUpslopeDependence.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
# Script Name: DinfUpslopeDependence
#
# Created By: David Tarboton
# Date: 9/29/11
# Import ArcPy site-package and os modules
import arcpy
import os
import subprocess
# Inputs
inlyr = arcpy.GetParameterAsText(0)
desc = arcpy.Describe(inlyr)
ang = str(desc.catalogPath)
arcpy.AddMessage("\nInput D-Infinity Flow Direction Grid: " + ang)
inlyr1 = arcpy.GetParameterAsText(1)
desc = arcpy.Describe(inlyr1)
dg = str(desc.catalogPath)
arcpy.AddMessage("Input Destination Grid: " + dg)
# Input Number of Processes
inputProc = arcpy.GetParameterAsText(2)
arcpy.AddMessage("Number of Processes: " + inputProc)
# Output
dep = arcpy.GetParameterAsText(3)
arcpy.AddMessage("Output Upslope Dependence Grid: " + dep)
# Construct command
cmd = 'mpiexec -n ' + inputProc + ' DinfUpDependence -ang ' + '"' + ang + '"' + ' -dg ' + '"' + dg + \
'"' + ' -dep ' + '"' + dep + '"'
arcpy.AddMessage("\nCommand Line: " + cmd)
# Submit command to operating system
os.system(cmd)
# Capture the contents of shell command and print it to the arcgis dialog box
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 on the output so that it displays properly
arcpy.AddMessage('Calculate Statistics\n')
arcpy.CalculateStatistics_management(dep)