source: development/momentum_sink/plot_cross_section.py @ 2415

Last change on this file since 2415 was 2415, checked in by nicholas, 19 years ago
File size: 3.7 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
18gauge_depth = Numeric.arrayrange(0, 700, 20)
19gauge_breadth = 100
20gauge_locations = []
21
22for GD in gauge_depth:
23    gauge_location = [GD,gauge_breadth]
24    gauge_locations.append(gauge_location)
25
26
27#Read model output
28quantities = ['stage', 'elevation', 'xmomentum', 'ymomentum']
29f = file_function(swwfile,
30                  quantities = quantities,
31                  interpolation_points = gauge_locations,
32                  verbose = True,
33                  use_cache = True)
34
35T=[150]
36               
37from math import sqrt
38N = len(gauge_locations)
39for k, g in enumerate(gauge_locations):
40    #if k%((N+10)/10)==0: # diagnostics - print 10 lines
41    #    print 'Doing row %d of %d' %(k, N)
42
43    model_time = []
44    stages = []
45    elevations = []
46    momenta = []
47    velocity = []
48
49    max_depth = 0
50    max_momentum = 0
51    max_velocity = 0
52    for t in T:
53    #for i, t in enumerate(f.T): # T is a list of times
54        #if tmin < t < tmax:
55        w = f(t, point_id = k)[0]
56        z = f(t, point_id = k)[1]
57        uh = f(t, point_id = k)[2]
58        vh = f(t, point_id = k)[3]
59        #myloc = locations[k]
60
61        m = sqrt(uh*uh + vh*vh)   #Absolute momentum
62        vel = sqrt(uh*uh + vh*vh) / (w-z + 1.e-30) #Absolute velocity
63        print vel
64        #dep = w-z
65        #vel = sqrt(uh*uh + vh*vh) / dep #Absolute velocity
66       
67        model_time.append(t)       
68        stages.append(w)
69        elevations.append(z)  #Should be constant over time
70        momenta.append(m)
71        velocity.append(vel)
72
73        if w-z > max_depth:
74            max_depth = w-z
75        if m > max_momentum:           
76            max_momentum = m
77        if vel > max_velocity:
78            max_velocity = vel
79            print 'max speed', max_velocity
80
81    print len(stages), "STAGES"
82
83    #Plot only those gauges that have been inundated by more than a threshold
84    #if max_depth < 0.2:
85    #    print 'Skipping gauge %d' %k
86    #    continue
87
88    ion()
89    hold(False)
90
91    #if elevations[0] < -10:
92    #    #plot(model_time, stages, '-b')
93    #    plot(stages, elevations, '-b')
94    #else:   
95    #    plot(model_time, stages, '-b',
96    #         model_time, elevations, '-k')
97    #name = 'Gauge_%d: (%.1f, %.1f)' %(k, g[0], g[1])
98    #   name = 'Gauge_%d: (%.1f, %.1f) Location: %s' %(k, g[0], g[1], myloc)
99    #title(name)
100
101    #title('%s (stage)' %name)
102    #xlabel('time [s]')
103    #ylabel('elevation [m]')   
104    #legend(('Stage', 'Bed = %.1f' %elevations[0]),
105    #       shadow=True,
106    #       loc='upper right')
107    #savefig('Gauge_%d_stage' %k) # savefig('Gauge_%s_stage' %myloc)
108
109    # raw_input('Next')
110
111
112    #Momentum plot
113    #ion()
114    #hold(False)
115    #plot(model_time, momenta, '-r')
116    #title(name)
117
118    #title('%s (momentum)' %name)
119    #xlabel('time [s]')
120    #ylabel('sqrt( uh^2 + vh^2 ) [m^2/s]')   
121    #savefig('Gauge_%d_momentum' %k)
122    #savefig('Gauge_%s_momentum' %myloc)
123   
124    # raw_input('Next')
125
126    #Speed plot
127    #ion()
128    #hold(False)
129    #plot(model_time, velocity, '-r')
130    #title(name)
131
132    #title('%s (velocity)' %name)
133    #xlabel('time [s]')
134    #ylabel('sqrt( uh^2 + vh^2 ) / depth [m/s]')   
135    #savefig('Gauge_%d_speed' %k)
136    #           savefig('Gauge_%s_speed' %myloc)
137   
138    # raw_input('Next')
139   
140
141show()
142
Note: See TracBrowser for help on using the repository browser.