source: production/sydney_2006/get_timeseries.py @ 2350

Last change on this file since 2350 was 2326, checked in by sexton, 19 years ago

Fixes to velocity calculation

File size: 4.1 KB
Line 
1"""Read in sww file, interpolate at specified locations and plot time series
2
3"""
4
5import project
6from pyvolution.util import file_function
7#from pyvolution.coordinate_transforms.redfearn import degminsec2decimal_degrees, redfearn
8from coordinate_transforms.redfearn import degminsec2decimal_degrees, redfearn
9from pylab import *
10
11
12   
13#swwfile = project.newoutputname + '.sww'
14swwfile = project.outputname + '.sww'
15
16#Time interval to plot
17tmin = 13000
18tmax = 21000
19
20def get_gauges_from_file(filename):
21    fid = open(filename)
22    lines = fid.readlines()
23    fid.close()
24   
25    gauges = []
26    gaugelocation = []
27    for line in lines[1:]:
28        fields = line.split(',')
29        # my gauge file set up as locationname, easting, northing
30        location = fields[0]
31        easting = float(fields[1])
32        northing = float(fields[2])
33        #z, easting, northing  = redfearn(lat, lon)
34        gauges.append([easting, northing])
35        gaugelocation.append(location)
36       
37    #Return gauges and raw data for subsequent storage
38    #return gauges, linesfs
39    return gauges, lines, gaugelocation
40
41#gauges, buildings = get_gauges_from_file(project.gauge_filename)
42gauges, lines, locations = get_gauges_from_file(project.gauge_filename)
43
44#Read model output
45quantities = ['stage', 'elevation', 'xmomentum', 'ymomentum']
46f = file_function(swwfile,
47                  quantities = quantities,
48                  interpolation_points = gauges,
49                  verbose = True,
50                  use_cache = True)
51
52
53               
54from math import sqrt
55N = len(gauges)
56for k, g in enumerate(gauges):
57    if k%((N+10)/10)==0: # diagnostics - print 10 lines
58        print 'Doing row %d of %d' %(k, N)
59
60    model_time = []
61    stages = []
62    elevations = []
63    momenta = []
64    velocity = []
65
66    max_depth = 0
67    max_momentum = 0
68    max_velocity = 0
69    for i, t in enumerate(f.T): # T is a list of times
70        #if tmin < t < tmax:
71        w = f(t, point_id = k)[0]
72        z = f(t, point_id = k)[1]
73        uh = f(t, point_id = k)[2]
74        vh = f(t, point_id = k)[3]
75        #myloc = locations[k]
76
77        m = sqrt(uh*uh + vh*vh)   #Absolute momentum
78        vel = sqrt(uh*uh + vh*vh) / (w-z + 1.e-30) #Absolute velocity
79        print vel
80        #dep = w-z
81        #vel = sqrt(uh*uh + vh*vh) / dep #Absolute velocity
82       
83        model_time.append(t)       
84        stages.append(w)
85        elevations.append(z)  #Should be constant over time
86        momenta.append(m)
87        velocity.append(vel)
88
89        if w-z > max_depth:
90            max_depth = w-z
91        if m > max_momentum:           
92            max_momentum = m
93        if vel > max_velocity:
94            max_velocity = vel
95            print 'max speed', max_velocity
96
97   
98
99    #Plot only those gauges that have been inundated by more than a threshold
100    #if max_depth < 0.2:
101    #    print 'Skipping gauge %d' %k
102    #    continue
103
104    ion()
105    hold(False)
106
107    if elevations[0] < -10:
108        plot(model_time, stages, '-b')
109    else:   
110        plot(model_time, stages, '-b',
111             model_time, elevations, '-k')
112    name = 'Gauge_%d: (%.1f, %.1f)' %(k, g[0], g[1])
113    #name = 'Gauge_%d: (%.1f, %.1f) Location: %s' %(k, g[0], g[1], myloc)
114    title(name)
115
116    title('%s (stage)' %name)
117    xlabel('time [s]')
118    ylabel('elevation [m]')   
119    legend(('Stage', 'Bed = %.1f' %elevations[0]),
120           shadow=True,
121           loc='upper right')
122    savefig('Gauge_%d_stage' %k) # savefig('Gauge_%s_stage' %myloc)
123
124    raw_input('Next')
125
126
127    #Momentum plot
128    ion()
129    hold(False)
130    plot(model_time, momenta, '-r')
131    title(name)
132
133    title('%s (momentum)' %name)
134    xlabel('time [s]')
135    ylabel('sqrt( uh^2 + vh^2 ) [m^2/s]')   
136    savefig('Gauge_%d_momentum' %k)
137    #savefig('Gauge_%s_momentum' %myloc)
138   
139    raw_input('Next')
140
141    #Speed plot
142    ion()
143    hold(False)
144    plot(model_time, velocity, '-r')
145    title(name)
146
147    title('%s (velocity)' %name)
148    xlabel('time [s]')
149    ylabel('sqrt( uh^2 + vh^2 ) / depth [m/s]')   
150    savefig('Gauge_%d_speed' %k)
151    #savefig('Gauge_%s_speed' %myloc)
152   
153    raw_input('Next')
154   
155
156show()
157
Note: See TracBrowser for help on using the repository browser.