source: production/karratha_2005/get_timeseries.py @ 2058

Last change on this file since 2058 was 1987, checked in by ole, 19 years ago

Updates for Karratha case study:

Gauges for inundated buildings
Use built-in cache in file_function

File size: 3.4 KB
Line 
1"""Read in sww file, interpolate at specified locations and plot
2"""
3
4import project
5from pyvolution.util import file_function
6from pyvolution.coordinate_transforms.redfearn import degminsec2decimal_degrees, redfearn
7from pylab import *
8   
9
10
11#swwfile = project.outputdir + project.basename + '.sww'
12#swwfile = project.outputname + '_0.0tide' + '.sww'
13swwfile = project.outputname + '.sww'
14#swwfile = project.outputname + '_notsunami.sww'
15#swwfile = project.outputdir + 'karratha_100m_12m.sww'
16
17#MOST Boundary directly north of Legendre island
18lat = project.north
19lon = (project.p3[1] + project.p4[1])/2 
20z, easting, northing  = redfearn(lat, lon)
21
22#Time interval to plot
23tmin = 13000
24tmax = 21000
25
26def get_gauges_from_file(filename):
27    fid = open(filename)
28    lines = fid.readlines()
29    fid.close()
30
31    gauges = []
32    for line in lines[1:]:
33        fields = line.split(',')
34        lon = float(fields[5])
35        lat = float(fields[6])
36
37        z, easting, northing  = redfearn(lat, lon)       
38        gauges.append([easting, northing])
39
40    return gauges
41
42gauges = get_gauges_from_file(project.gauge_filename)
43
44
45#gauges = gauges[-10:]
46#print gauges
47#import sys; sys.exit()
48
49#From Neil
50#gauges = [[easting, northing - 5],
51#          [easting, northing - 10],
52#          [easting, northing - 50],
53#          [easting, northing - 100],                                       
54#          [470882, 7717952],
55#          [469390, 7715426],
56#          [469214, 7714979],
57#          [468899, 7715177],
58#          [469038, 7715725],
59#          [470285, 7717470]]
60         
61
62#Read model output
63quantities = ['stage', 'elevation', 'xmomentum', 'ymomentum']
64f = file_function(swwfile,
65                  quantities = quantities,
66                  interpolation_points = gauges,
67                  verbose = True,
68                  use_cache = True)
69
70print f
71#model_time = f.T
72
73
74from math import sqrt
75for k, g in enumerate(gauges):
76
77    model_time = []
78    stages = []
79    elevations = []
80    momenta = []
81
82
83    max_depth = 0
84    for i, t in enumerate(f.T):
85        if tmin < t < tmax:
86            w = f(t, point_id = k)[0]
87            z = f(t, point_id = k)[1]
88            uh = f(t, point_id = k)[2]
89            vh = f(t, point_id = k)[3]       
90
91            model_time.append(t)       
92            stages.append(w)
93            elevations.append(z)  #Should be constant over time
94            momenta.append( sqrt(uh*uh + vh*vh) )  #Absolute momentum
95
96            if w-z > max_depth:
97                max_depth = w-z
98
99               
100
101    #Plot only those gauges that have been inundated by more than a threshold
102    if max_depth < 0.2:
103        print 'Skipping gauge %d' %k
104        continue
105   
106    ion()
107    hold(False)
108
109    if elevations[0] < -10:
110        plot(model_time, stages, '-b')
111    else:   
112        plot(model_time, stages, '-b',
113             model_time, elevations, '-k')
114    name = 'Gauge_%d: (%.1f, %.1f)' %(k, g[0], g[1])
115    title(name)
116
117    title('%s (stage)' %name)
118    xlabel('time [s]')
119    ylabel('elevation [m]')   
120    legend(('Stage', 'Bed = %.1f' %elevations[0]),
121           shadow=True,
122           loc='upper right')
123    savefig('Gauge_%d_stage' %k)
124
125    raw_input('Next')
126
127
128    #Momentum plot
129    ion()
130    hold(False)
131    plot(model_time, momenta, '-r')
132    title(name)
133
134    title('%s (momentum)' %name)
135    xlabel('time [s]')
136    ylabel('sqrt( uh^2 + vh^2 ) [m^2/s]')   
137    savefig('Gauge_%d_momentum' %k)
138
139    raw_input('Next')
140   
141
142   
143show()
144
Note: See TracBrowser for help on using the repository browser.