1 | """Read in sww file, interpolate at specified locations and plot time series |
---|
2 | Additionally, store augmented building database with max inundation depths |
---|
3 | """ |
---|
4 | # FORMALLY CALLED <process_gauges.py> |
---|
5 | from os import sep |
---|
6 | import project |
---|
7 | from pyvolution.util import file_function |
---|
8 | #from pyvolution.coordinate_transforms.redfearn import degminsec2decimal_degrees, redfearn |
---|
9 | from pylab import * |
---|
10 | from compare_sww import gauge_locations |
---|
11 | |
---|
12 | plot = False |
---|
13 | |
---|
14 | swwfile = project.outputdir + sep + 'Buildings_3662.sww' |
---|
15 | |
---|
16 | #def get_gauges_from_file(filename): |
---|
17 | # fid = open(filename) |
---|
18 | # lines = fid.readlines() |
---|
19 | # fid.close() |
---|
20 | |
---|
21 | # gauges = [] |
---|
22 | # gaugelocation = [] |
---|
23 | # for line in lines[1:]: |
---|
24 | # fields = line.split(',') |
---|
25 | # location = fields[0] |
---|
26 | # easting = float(fields[1]) |
---|
27 | # northing = float(fields[2]) |
---|
28 | |
---|
29 | # gauges.append([easting, northing]) |
---|
30 | # gaugelocation.append(location) |
---|
31 | |
---|
32 | # #Return gauges and raw data for subsequent storage |
---|
33 | # return gauges, lines, gaugelocation |
---|
34 | |
---|
35 | #gauges, lines, locations = get_gauges_from_file(project.gauge_filename) |
---|
36 | |
---|
37 | |
---|
38 | #Read model output |
---|
39 | quantities = ['stage', 'elevation', 'xmomentum', 'ymomentum'] |
---|
40 | f = file_function(swwfile, |
---|
41 | quantities = quantities, |
---|
42 | interpolation_points = gauge_locations, |
---|
43 | verbose = True, |
---|
44 | use_cache = True) |
---|
45 | |
---|
46 | from math import sqrt |
---|
47 | N = len(gauge_locations) |
---|
48 | for k, g in enumerate(gauge_locations): |
---|
49 | if k%((N+10)/10)==0: |
---|
50 | print 'Doing row %d of %d' %(k, N) |
---|
51 | |
---|
52 | model_time = [] |
---|
53 | stages = [] |
---|
54 | elevations = [] |
---|
55 | momenta = [] |
---|
56 | |
---|
57 | max_depth = 0 |
---|
58 | max_momentum = 0 |
---|
59 | for i, t in enumerate(f.T): |
---|
60 | w = f(t, point_id = k)[0] |
---|
61 | z = f(t, point_id = k)[1] |
---|
62 | uh = f(t, point_id = k)[2] |
---|
63 | vh = f(t, point_id = k)[3] |
---|
64 | |
---|
65 | m = sqrt(uh*uh + vh*vh) #Absolute momentum |
---|
66 | |
---|
67 | model_time.append(t) |
---|
68 | stages.append(w) |
---|
69 | elevations.append(z) #Should be constant over time |
---|
70 | momenta.append(m) |
---|
71 | |
---|
72 | if w-z > max_depth: |
---|
73 | max_depth = w-z |
---|
74 | if m > max_momentum: |
---|
75 | max_momentum = m |
---|
76 | |
---|
77 | plot(model_time, stages, 'b') |
---|
78 | |
---|
79 | print |
---|
80 | |
---|
81 | #Store new building file with mak depths added |
---|
82 | |
---|
83 | #FN = 'inundation_augmented_' + project.gauge_filename |
---|
84 | #FN = project.gauge_outname |
---|
85 | #fid = open(FN, 'w') |
---|
86 | #for line in lines: |
---|
87 | # fid.write(line) |
---|
88 | #fid.close() |
---|
89 | |
---|