forked from Shahumyan/ModelPythonWrappers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMEM.py
78 lines (63 loc) · 2.38 KB
/
MEM.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#**********************************************************************
# Description:
# MEM model wrapper
#
#
# Arguments:
# 0 - MEM Model bat file //Cube script (.s) file
# 1 - CUBE Voyager run program
# 2 - Output folder
# 3 - Output 1: AQ_byCty.csv (Air quality for cities)
# 4 - Output 2: AQ_BASE_PM.CSV (Summary of air quality for MD)
#
# Created by: Harutyun Shahumyan
#**********************************************************************
# Standard error handling
try:
import arcpy
import time
import os
import string
start = time.time()
arcpy.AddMessage("")
arcpy.AddMessage("******************************************************")
arcpy.AddMessage("MEM model start time: %s" % time.strftime('%X %x %Z'))
# Get input arguments
in_Program = arcpy.GetParameterAsText(0)
in_CubeVoyager = arcpy.GetParameterAsText(1)
in_OutputFolder = arcpy.GetParameterAsText(2)
# Check that the program exist
if not arcpy.Exists(in_Program):
raise Exception, "Input program does not exist"
# MSTM run parameters
runCommand="\""+in_CubeVoyager+"\" "+in_Program
# Run the model / program
arcpy.AddMessage("")
arcpy.AddMessage("Running %s" % (in_Program))
# arcpy.AddMessage("Running %s" % (runCommand))
desc = arcpy.Describe(in_Program)
sourceFilePath = desc.path
os.chdir(sourceFilePath)
os.system(in_Program)
#os.system(runCommand)
# Export shared files
outputFile1 = "\AQ_byCty.csv"
outputFile2 = "\AQ_BASE_PM.csv"
arcpy.SetParameterAsText(3, in_OutputFolder+outputFile1)
arcpy.SetParameterAsText(4, in_OutputFolder+outputFile2)
elapsed = (time.time() - start)
arcpy.AddMessage("")
arcpy.AddMessage("Model end time: %s" % time.strftime('%X %x %Z'))
arcpy.AddMessage("Processing time in seconds is %s" % str(elapsed ))
arcpy.AddMessage("******************************************************")
arcpy.AddMessage("")
# Handle script errors
except Exception, errMsg:
# If we have messages of severity error (2), we assume a GP tool raised it,
# so we'll output that. Otherwise, we assume we raised the error and the
# information is in errMsg.
#
if arcpy.GetMessages(2):
arcpy.AddError(arcpy.GetMessages(2))
else:
arcpy.AddError(str(errMsg))