[2069] | 1 | """Read in sww file, interpolate at specified locations and plot time series |
---|
[2083] | 2 | |
---|
[1821] | 3 | """ |
---|
| 4 | |
---|
| 5 | import project |
---|
| 6 | from pyvolution.util import file_function |
---|
[1893] | 7 | from pyvolution.coordinate_transforms.redfearn import degminsec2decimal_degrees, redfearn |
---|
[1987] | 8 | from pylab import * |
---|
[1821] | 9 | |
---|
[1987] | 10 | |
---|
[2069] | 11 | |
---|
[1921] | 12 | swwfile = project.outputname + '.sww' |
---|
[1821] | 13 | |
---|
[1896] | 14 | #MOST Boundary directly north of Legendre island |
---|
[1921] | 15 | lat = project.north |
---|
| 16 | lon = (project.p3[1] + project.p4[1])/2 |
---|
| 17 | z, easting, northing = redfearn(lat, lon) |
---|
[1893] | 18 | |
---|
[1987] | 19 | #Time interval to plot |
---|
| 20 | tmin = 13000 |
---|
| 21 | tmax = 21000 |
---|
[1893] | 22 | |
---|
[1987] | 23 | def get_gauges_from_file(filename): |
---|
| 24 | fid = open(filename) |
---|
| 25 | lines = fid.readlines() |
---|
| 26 | fid.close() |
---|
| 27 | |
---|
| 28 | gauges = [] |
---|
| 29 | for line in lines[1:]: |
---|
| 30 | fields = line.split(',') |
---|
[2069] | 31 | lon = float(fields[4]) |
---|
| 32 | lat = float(fields[5]) |
---|
[1987] | 33 | |
---|
| 34 | z, easting, northing = redfearn(lat, lon) |
---|
| 35 | gauges.append([easting, northing]) |
---|
| 36 | |
---|
[2069] | 37 | #Return gauges and raw data for subsequent storage |
---|
| 38 | return gauges, lines |
---|
[1987] | 39 | |
---|
[2069] | 40 | gauges, buildings = get_gauges_from_file(project.gauge_filename) |
---|
[1987] | 41 | |
---|
[2083] | 42 | gauges = [[easting, northing-10]] |
---|
| 43 | |
---|
| 44 | |
---|
[1821] | 45 | #Read model output |
---|
[1987] | 46 | quantities = ['stage', 'elevation', 'xmomentum', 'ymomentum'] |
---|
| 47 | f = file_function(swwfile, |
---|
| 48 | quantities = quantities, |
---|
| 49 | interpolation_points = gauges, |
---|
| 50 | verbose = True, |
---|
| 51 | use_cache = True) |
---|
[1821] | 52 | |
---|
| 53 | |
---|
[2069] | 54 | |
---|
[1921] | 55 | from math import sqrt |
---|
[2069] | 56 | N = len(gauges) |
---|
[1921] | 57 | for k, g in enumerate(gauges): |
---|
[2069] | 58 | if k%((N+10)/10)==0: |
---|
| 59 | print 'Doing row %d of %d' %(k, N) |
---|
[1893] | 60 | |
---|
[1987] | 61 | model_time = [] |
---|
[1921] | 62 | stages = [] |
---|
| 63 | elevations = [] |
---|
| 64 | momenta = [] |
---|
[1987] | 65 | |
---|
| 66 | max_depth = 0 |
---|
[2069] | 67 | max_momentum = 0 |
---|
[2885] | 68 | for i, t in enumerate(f.get_time()): # T is a list of times |
---|
[2083] | 69 | #if tmin < t < tmax: |
---|
[2069] | 70 | w = f(t, point_id = k)[0] |
---|
| 71 | z = f(t, point_id = k)[1] |
---|
| 72 | uh = f(t, point_id = k)[2] |
---|
| 73 | vh = f(t, point_id = k)[3] |
---|
[1821] | 74 | |
---|
[2069] | 75 | m = sqrt(uh*uh + vh*vh) #Absolute momentum |
---|
| 76 | |
---|
| 77 | model_time.append(t) |
---|
| 78 | stages.append(w) |
---|
| 79 | elevations.append(z) #Should be constant over time |
---|
| 80 | momenta.append(m) |
---|
[1987] | 81 | |
---|
[2069] | 82 | if w-z > max_depth: |
---|
| 83 | max_depth = w-z |
---|
| 84 | if m > max_momentum: |
---|
| 85 | max_momentum = m |
---|
[1987] | 86 | |
---|
[2069] | 87 | |
---|
[1987] | 88 | |
---|
[2083] | 89 | #Plot only those gauges that have been inundated by more than a threshold |
---|
| 90 | #if max_depth < 0.2: |
---|
| 91 | # print 'Skipping gauge %d' %k |
---|
| 92 | # continue |
---|
[1921] | 93 | |
---|
[2083] | 94 | ion() |
---|
| 95 | hold(False) |
---|
[1921] | 96 | |
---|
[2083] | 97 | if elevations[0] < -10: |
---|
| 98 | plot(model_time, stages, '-b') |
---|
| 99 | else: |
---|
| 100 | plot(model_time, stages, '-b', |
---|
| 101 | model_time, elevations, '-k') |
---|
| 102 | name = 'Gauge_%d: (%.1f, %.1f)' %(k, g[0], g[1]) |
---|
| 103 | title(name) |
---|
[1921] | 104 | |
---|
[2083] | 105 | title('%s (stage)' %name) |
---|
| 106 | xlabel('time [s]') |
---|
| 107 | ylabel('elevation [m]') |
---|
| 108 | legend(('Stage', 'Bed = %.1f' %elevations[0]), |
---|
| 109 | shadow=True, |
---|
| 110 | loc='upper right') |
---|
| 111 | savefig('Gauge_%d_stage' %k) |
---|
[1921] | 112 | |
---|
[2083] | 113 | raw_input('Next') |
---|
[1921] | 114 | |
---|
| 115 | |
---|
[2083] | 116 | #Momentum plot |
---|
| 117 | ion() |
---|
| 118 | hold(False) |
---|
| 119 | plot(model_time, momenta, '-r') |
---|
| 120 | title(name) |
---|
[1921] | 121 | |
---|
[2083] | 122 | title('%s (momentum)' %name) |
---|
| 123 | xlabel('time [s]') |
---|
| 124 | ylabel('sqrt( uh^2 + vh^2 ) [m^2/s]') |
---|
| 125 | savefig('Gauge_%d_momentum' %k) |
---|
[1896] | 126 | |
---|
[2083] | 127 | raw_input('Next') |
---|
| 128 | |
---|
[1821] | 129 | |
---|
[2083] | 130 | show() |
---|
[1821] | 131 | |
---|