source: development/momentum_sink/get_timeseries.py @ 2417

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