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