[2927] | 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 | |
---|
| 37 | #Read model output |
---|
| 38 | quantities = ['stage', 'elevation', 'xmomentum', 'ymomentum'] |
---|
| 39 | f = file_function(swwfile, |
---|
| 40 | quantities = quantities, |
---|
| 41 | interpolation_points = gauges, |
---|
| 42 | verbose = True, |
---|
| 43 | use_cache = True) |
---|
| 44 | |
---|
| 45 | |
---|
| 46 | lines[0] = lines[0].strip() +\ |
---|
| 47 | ',MAX INUNDATION DEPTH (m)' +\ |
---|
| 48 | ',MAX MOMENTUM (m^2/s)\n' |
---|
| 49 | |
---|
| 50 | from math import sqrt |
---|
| 51 | N = len(gauges) |
---|
| 52 | for k, g in enumerate(gauges): |
---|
| 53 | if k%((N+10)/10)==0: |
---|
| 54 | print 'Doing row %d of %d' %(k, N) |
---|
| 55 | |
---|
| 56 | model_time = [] |
---|
| 57 | stages = [] |
---|
| 58 | elevations = [] |
---|
| 59 | momenta = [] |
---|
| 60 | |
---|
| 61 | max_depth = 0 |
---|
| 62 | max_momentum = 0 |
---|
| 63 | for i, t in enumerate(f.T): |
---|
| 64 | w = f(t, point_id = k)[0] |
---|
| 65 | z = f(t, point_id = k)[1] |
---|
| 66 | uh = f(t, point_id = k)[2] |
---|
| 67 | vh = f(t, point_id = k)[3] |
---|
| 68 | |
---|
| 69 | m = sqrt(uh*uh + vh*vh) #Absolute momentum |
---|
| 70 | |
---|
| 71 | model_time.append(t) |
---|
| 72 | stages.append(w) |
---|
| 73 | elevations.append(z) #Should be constant over time |
---|
| 74 | momenta.append(m) |
---|
| 75 | |
---|
| 76 | if w-z > max_depth: |
---|
| 77 | max_depth = w-z |
---|
| 78 | if m > max_momentum: |
---|
| 79 | max_momentum = m |
---|
| 80 | |
---|
| 81 | #Augment building data |
---|
| 82 | lines[k+1] = lines[k+1].strip() +\ |
---|
| 83 | ',%f' %max_depth +\ |
---|
| 84 | ',%f\n' %max_momentum |
---|
| 85 | |
---|
| 86 | print lines[k] |
---|
| 87 | |
---|
| 88 | #Store new building file with mak depths added |
---|
| 89 | |
---|
| 90 | #FN = 'inundation_augmented_' + project.gauge_filename |
---|
| 91 | FN = project.gauge_outname |
---|
| 92 | fid = open(FN, 'w') |
---|
| 93 | for line in lines: |
---|
| 94 | fid.write(line) |
---|
| 95 | fid.close() |
---|
| 96 | |
---|