-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModeling_Tab_Script_Template.py
More file actions
107 lines (80 loc) · 3.33 KB
/
Modeling_Tab_Script_Template.py
File metadata and controls
107 lines (80 loc) · 3.33 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
from hec.hecmath import TimeSeriesMath
from hec.io import TimeSeriesContainer
from hec.heclib.dss import HecDss
from hec.heclib.util import HecTime, Heclib
from hec.dssgui import ListSelection
from hec.script import MessageBox, Constants, Plot, AxisMarker
from com.rma.client import Browser
def output(msg="") :
'''
Output to console log
'''
print ("%s : %s" % (progname, msg))
def error(msg) :
'''
Outputs an error message and rasies an exception
'''
output(msg)
raise Exception(msg)
def chktab(tab) :
'''
Checks that the "Modeling" tab is selected
'''
if tab.getTabTitle() != "Modeling" :
msg = "The Modeling tab must be selected"
output("ERROR : %s" % msg)
raise Exception(msg)
def chkfcst(fcst) :
'''
Checks that a forecast is open
'''
if fcst is None :
msg = "A forecast must be open"
output("ERROR : %s" % msg)
raise Exception(msg)
## Uncomment this section to add this script to a progranm order
'''
def computeAlternative(currentAlternative, computeOptions):
return True # success
'''
try :
try :
################## Stection-Start ####################################################################
## This section finds the current forecast.dss file (i.e. active forecast) ##
frame = Browser.getBrowser().getBrowserFrame()
proj = frame.getCurrentProject()
pane = frame.getTabbedPane()
tab = pane.getSelectedComponent()
chktab(tab)
fcst = tab.getForecast()
chkfcst(fcst)
fcstTimeWindowString = str(fcst.getRunTimeWindow())
fcstNames = fcst.getForecastRunNames()
fcstRun = fcst.getForecastRun(fcstNames[0])
fcstRunKey = fcstRun.getKey()
dssfile = fcst.getOutDssPath()
## Open forecast.dss file
cwmsFile = HecDss.open(dssfile)
## Read active forecast times: start of simulation; forecast time; and end of simulation
important_times = [ i.strip(' ') for i in fcstTimeWindowString.split(';') ]
start_time, forecast_time, end_time = important_times[0], important_times[1], important_times[2]
## Set time window for the forecast.dss file. Swap in start_time, forecast_time, end_time.
cwmsFile.setTimeWindow(start_time, end_time)
################## Stection-End ######################################################################
################## Stection-Start ####################################################################
## Enter your script in this section ##
################## Stection-End ######################################################################
except Exception, e :
exc_type, exc_value, exc_traceback = sys.exc_info()
traceback.print_exception(exc_type, exc_value, exc_traceback, limit=None, file=sys.stdout)
formatted_lines = traceback.format_exc().splitlines()
TracebackStr = '\n'.join(formatted_lines)
MessageBox.showError(TracebackStr, 'Python Error')
except java.lang.Exception, e :
exc_type, exc_value, exc_traceback = sys.exc_info()
traceback.print_exception(exc_type, exc_value, exc_traceback, limit=None, file=sys.stdout)
formatted_lines = traceback.format_exc().splitlines()
TracebackStr = '\n'.join(formatted_lines)
MessageBox.showError(TracebackStr, 'Java Error')
finally:
cwmsFile.done()