-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbam.py
More file actions
419 lines (346 loc) · 17.9 KB
/
bam.py
File metadata and controls
419 lines (346 loc) · 17.9 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
#! /usr/bin/env python3
#----------------------------------------------------------------------------
# Name: bam.py
# Purpose: Florida Bay Assessment Model
# Author: J Park
#----------------------------------------------------------------------------
# Python distribution modules
import sys
from argparse import ArgumentParser
from os import getenv, getcwd
from os.path import join as path_join
import tkinter as Tk
# Community modules
from numpy import linspace
# Local modules
import model as bam_model
import gui
from init import InitTimeBasins
#----------------------------------------------------------------------------
# Main module
#----------------------------------------------------------------------------
def main():
'''See Notes.py and model.py'''
args = ParseCmdLine()
if args.DEBUG or args.DEBUG_ALL:
import faulthandler
faulthandler.enable()
# Initialize the root Tk object if gui is used
root = None
if not args.noGUI :
root = Tk.Tk()
root.title( 'Bay Assessment Model' )
# Instantiate and initialize the main Model class and its
# Basins and Shoals maps
model = bam_model.Model( args )
# Create GUI object & model interface objects
model.gui = gui.GUI( root, model )
if not args.noGUI :
model.gui.FloridaBayModel_Tk()
if not args.noThread :
# Call DrawCanvas() after mainloop for modelThread events
root.after( 500, model.DrawCanvas )
InitTimeBasins( model )
model.gui.InitPlotVars() # Set default outputs
if args.noGUI :
model.gui.Message( model.Version )
model.gui.Message( model.args.commandLine + '\n' )
model.Run() # Run the model explicitly in this thread
else :
model.gui.Tk_root.mainloop() # Enter the Tk mainloop
#--------------------------------------------------------------
#
#--------------------------------------------------------------
def ParseCmdLine():
home_dir = getenv( 'HOME', default = getcwd() )
parser = ArgumentParser( description = 'Bay Assessment Model' )
parser.add_argument('-p', '--path',
dest = 'path', type = str,
action = 'store',
default = path_join('.',''),
help = 'Top level BAM path: -p ' + path_join('.',''))
parser.add_argument('-t', '--timestep',
dest = 'timestep', type = int,
action = 'store',
default = 360,
help = 'timestep (s): -t 360')
parser.add_argument('-S', '--start',
dest = 'start', type = str,
action = 'store',
default = '1999-9-1',
help = 'start date time: -S "1999-9-1"')
parser.add_argument('-E', '--end',
dest = 'end', type = str,
action = 'store',
default = '2016-12-31',
help = 'End date time: -E "2016-12-31"')
parser.add_argument('-vt', '--velocity_tolerance',
dest = 'velocity_tol', type = float,
action = 'store',
default = 0.0001,
help = 'velocity iteration tolerance (m/s):' +\
' -vt 0.0001')
parser.add_argument('-it', '--max_iteration',
dest = 'max_iteration', type = int,
action = 'store',
default = 3000,
help = 'velocity iteration limit: -it 3000')
basins_ = path_join('data','GIS','FLBayBasins')
parser.add_argument('-bn', '--basins',
dest = 'basinShapeFile', type = str,
action = 'store',
default = basins_,
help = 'Basins shape file: -bn ' + basins_)
basinDepth_ = path_join('data','init','Basin_Area_Depth.csv')
parser.add_argument('-bd', '--basinDepth',
dest = 'basinDepth', type = str,
action = 'store',
default = basinDepth_,
help = 'Basin area depth input file: -bd ' +\
basinDepth_)
basinParameters_ = path_join('data','init','Basin_Parameters.csv')
parser.add_argument('-bp', '--basinParameter',
dest = 'basinParameters', type = str,
action = 'store',
default = basinParameters_,
help = 'Basin parameters input file: -bp ' +\
basinParameters_)
basinInit_ = path_join('data','init','Basin_Initial_Values.csv')
parser.add_argument('-bi', '--basinInit',
dest = 'basinInit', type = str,
action = 'store',
default = basinInit_,
help = 'Basin initial state variable input file:' +\
'-bi ' + basinInit_)
basinTide_ = path_join('data','Boundary','Basin_Tide_Boundary_2000_2016.csv')
parser.add_argument('-bt', '--basinTide',
dest = 'basinTide', type = str,
action = 'store',
default = basinTide_,
help = 'Basin tide boundary data files: -bt '+basinTide_)
basinRain_ = path_join('data','Rain',
'DailyRainFilled_cm_1999-9-1_2016-12-31.csv')
parser.add_argument('-br', '--basinRain',
dest = 'basinRain', type = str,
action = 'store',
default = basinRain_,
help = 'Daily rain data file: -br ' + basinRain_)
basinBCFile_ = path_join('data','Boundary','Basin_Boundary_Condition.csv')
parser.add_argument('-bc', '--basinBCFile',
dest = 'basinBCFile', type = str,
action = 'store',
default = basinBCFile_,
help = 'Basin boundary condition data files: -bc ' +\
basinBCFile_)
basinFixedBCFile_ = path_join('data','Boundary',
'Basin_Fixed_Boundary_Condition.csv')
parser.add_argument('-bf', '--basinFixedBCFile',
dest = 'basinFixedBCFile', type = str,
action = 'store',
default = basinFixedBCFile_,
help = 'Basin fixed boundary condition data files: -bf '+\
basinFixedBCFile_)
basinOutputDir_ = path_join(home_dir,'BAM.out','')
parser.add_argument('-bo', '--basinOutput',
dest = 'basinOutputDir', type = str,
action = 'store',
default = basinOutputDir_,
help = 'Directory to write basin outputs: -bo ' +\
basinOutputDir_)
basinStageRunoff_ = path_join('data','Runoff','EDEN_Stage_OffsetMSL.csv')
parser.add_argument('-bR', '--basinStageRunoff',
dest = 'basinStageRunoff', type = str,
action = 'store',
default = basinStageRunoff_,
help = 'Daily runoff EDEN stage data file: ' +\
'-bR ' + basinStageRunoff_)
basinStageRunoffMap_ = path_join('data','Boundary',
'Basin_Runoff_Boundary.csv')
parser.add_argument('-bS', '--basinStageRunoffMap',
dest = 'basinStageRunoffMap', type = str,
action = 'store',
default = basinStageRunoffMap_,
help = 'Mapping of EDEN stage to basin: -bS ' +\
basinStageRunoffMap_)
basinStage_ = path_join('data','Stage','DailyStage_1999-9-1_2016-12-31.csv')
parser.add_argument('-bs', '--basinStage',
dest = 'basinStage', type = str,
action = 'store',
default = basinStage_,
help = 'Daily stage data file: -bs ' + basinStage_)
surfaceTemp_ = path_join('data','Temperature',
'MaxTemp_Filled_1999-9-1_2017-6-30.csv')
parser.add_argument('-st', '--temperature',
dest = 'surfaceTemp', type = str,
action = 'store',
default = surfaceTemp_,
help = 'Temperature data file: -st ' + surfaceTemp_)
parser.add_argument('-rt', '--reference_temperature',
dest = 'reference_temperature', type = float,
action = 'store',
default = 15,
help ='Reference temperature for ET amplify: -rt 15')
parser.add_argument('-na', '--noET_Amplify',
dest = 'noET_Amplify', # type = bool,
action = 'store_true', default = False,
help = 'Do not amplify ET from temperature: -na' )
ET_ = path_join('data','ET','PET_1999-9-1_2016-12-31.csv')
parser.add_argument('-et', '--ET',
dest = 'ET', type = str,
action = 'store',
default = ET_,
help = 'PET data file: -et ' + ET_)
parser.add_argument('-es', '--ET scale',
dest = 'ET_scale', type = float,
action = 'store',
default = 1,
help = 'Scale factor on global ET: -es 1' )
shoalShapeFile_ = path_join('data','GIS','FathomLines')
parser.add_argument('-s', '--shoals',
dest = 'shoalShapeFile', type = str,
action = 'store',
default = shoalShapeFile_,
help = 'Shoals shape file: -s ' + shoalShapeFile_)
shoalParameters_ = path_join('data','init','Shoal_Parameters.csv')
parser.add_argument('-sp', '--shoalParameters',
dest = 'shoalParameters', type = str,
action = 'store',
default = shoalParameters_,
help = 'Shoal to basin mapping file: ' +\
shoalParameters_)
shoalLength_ = path_join('data','init','Shoal_Length_Depth.csv')
parser.add_argument('-sl', '--shoalLength',
dest = 'shoalLength', type = str,
action = 'store',
default = shoalLength_,
help = 'Shoal width and length depth input file:' +\
'-sl ' + shoalLength_)
parser.add_argument('-sm', '--shoalManning',
dest = 'shoalManning', type = float,
action = 'store',
default = None,
help = 'Manning friction for all shoals: -sm 0.1' )
salinityFile_ = path_join('data','Salinity',
'DailySalinityFilled_1999-9-1_2016-12-31.csv')
parser.add_argument('-sf', '--salinityFile',
dest = 'salinityFile', type = str,
action = 'store',
default = salinityFile_,
help = 'Daily salinity data file: -sf ' +\
salinityFile_)
seasonalMSL_ = path_join('data','Tide','MSL_Anomaly.csv')
parser.add_argument('-msl', '--seasonalMSL',
dest = 'seasonalMSL', type = str,
action = 'store',
default = seasonalMSL_,
help = 'Seasonal MSL: -msl data/Tide/' +\
seasonalMSL_)
parser.add_argument('-si', '--salinityInit',
dest = 'salinityInit', type = str,
action = 'store', default = 'yes',
help = 'Initialize basin salinity from gauge data.')
parser.add_argument('-gs', '--gaugeSalinity',
dest = 'gaugeSalinity', # type = bool,
action = 'store_true', default = False,
help = 'Impose basin gauge salinity where available.')
parser.add_argument('-e', '--editor',
dest = 'editor', type = str,
action = 'store',
default = 'gedit',
help = 'Editor: -e gedit' )
parser.add_argument('-r', '--runID',
dest = 'runID', type = str,
action = 'store',
default = '',
help = 'Run ID for output files: -r RunID')
parser.add_argument('-rf', '--runInfoFile',
dest = 'runInfoFile', type = str,
action = 'store',
default = 'RunInfo.txt',
help = 'File for model run messages: ' +\
'-rf RunInfo.txt')
parser.add_argument('-oi', '--outputInterval',
dest = 'outputInterval', type = int,
action = 'store',
default = 1,
help = 'Time interval (hr) of output data: ' +\
'-oi 1' )
parser.add_argument('-mi', '--mapInterval',
dest = 'mapInterval', type = int, nargs = '*',
action = 'store',
default = ( 1, 0 ),
help = 'Time interval of display refresh in ' +\
'(days) and [(hr)]: -mi 1 [0]' )
parser.add_argument('-L', '--stageLegend',
dest = 'stageLegendBound', type = float,
action = 'store',
default = 0.5,
help = 'Stage legend bound on map: -L 0.5')
parser.add_argument('-P', '--salinityLegend',
dest = 'salinityLegendBound', type = float,
action = 'store',
default = 50,
help = 'Salinity legend bound on map: -P 50')
parser.add_argument('-fb', '--fixedBoundaryConditions',
dest = 'fixedBoundaryConditions', # type = bool,
action = 'store_true', default = False,
help = 'Enable fixed boundary conditions for basins.')
parser.add_argument('-nb', '--noDynamicBoundaryConditions',
dest = 'noDynamicBoundaryConditions', # type = bool,
action = 'store_true', default = False,
help = 'Disable basin dynamic boundary conditions.')
parser.add_argument('-nr', '--noRain',
dest = 'noRain', # type = bool,
action = 'store_true', default = False,
help = 'Disable rain inputs.')
parser.add_argument('-ne', '--noET',
dest = 'noET', # type = bool,
action = 'store_true', default = False,
help = 'Disable ET inputs.')
parser.add_argument('-nR', '--noStageRunoff',
dest = 'noStageRunoff', # type = bool,
action = 'store_true', default = False,
help = 'Disable EDEN stage runoff inputs.')
parser.add_argument('-nt', '--noTide',
dest = 'noTide', # type = bool,
action = 'store_true', default = False,
help = 'Disable tidal boundary inputs.')
parser.add_argument('-nm', '--noMeanSeaLevel',
dest = 'noMeanSeaLevel', # type = bool,
action = 'store_true', default = False,
help = 'Disable mean sea level inputs.')
parser.add_argument('-ng', '--noGUI',
dest = 'noGUI', # type = bool,
action = 'store_true', default = False,
help = 'Disable GUI.')
parser.add_argument('-nT', '--noThread',
dest = 'noThread', # type = bool,
action = 'store_true', default = False,
help = 'Run simulation loop in local process.')
parser.add_argument('-D', '--DEBUG',
dest = 'DEBUG', # type = bool,
action = 'store_true', default = False )
parser.add_argument('-DA', '--DEBUG_ALL',
dest = 'DEBUG_ALL', # type = bool,
action = 'store_true', default = False )
args = parser.parse_args()
# Ensure path has terminator
args.path = path_join( args.path, '' )
# Add the home directory
args.homeDir = home_dir
# Add the original command line
command_line = ''
for cmd in sys.argv :
command_line = command_line + cmd + ' '
args.commandLine = command_line
# Tick marks for the legend : values corresponding to legend_color_map
# Create stage_legend_bounds
args.stage_legend_bounds = linspace( -args.stageLegendBound,
args.stageLegendBound, 11 )
# Create salinity_legend_bounds
args.salinity_legend_bounds = linspace( 0, args.salinityLegendBound, 11 )
return args
#----------------------------------------------------------------------------
# Provide for cmd line invocation and clean module loading
if __name__ == "__main__":
main()