source: production/karratha_2005/get_cross_section.py @ 2240

Last change on this file since 2240 was 1960, checked in by ole, 19 years ago

More diagnostic introspection of sww files

File size: 2.4 KB
Line 
1"""Read in sww file, read points along specified cross section and time and plot
2"""
3
4import project
5from pyvolution.util import file_function
6from pyvolution.coordinate_transforms.redfearn import degminsec2decimal_degrees, redfearn
7
8
9#swwfile = project.outputdir + project.basename + '.sww'
10#swwfile = project.outputname + '_0.0tide' + '.sww'
11swwfile = project.outputname + '.sww'
12swwfile = project.outputname + '_notsunami.sww'
13#swwfile = project.outputdir + 'karratha_100m_12m.sww'
14
15
16time = 0
17
18#E-W cross section
19start = [468500, 7715177]
20end = [469500, 7715177]
21step = 1
22
23#Generate points (from west to east)
24points = []
25x = start[0]
26y = start[1]
27while x <= end[0]:
28    points.append( [x,y] )
29    x += step
30
31
32#Read model output
33from caching import cache
34f = cache(file_function, swwfile,
35          {'quantities': ['stage', 'elevation', 'xmomentum', 'ymomentum'],
36           'interpolation_points': points,
37           'verbose': True},
38          compression = False, 
39          dependencies = [swwfile],
40          verbose = True)
41
42print f
43
44from math import sqrt
45for time in [f.T[0], f.T[0] + 10]:
46
47    abscissa = []
48    stages = []
49    elevations = []
50    momenta = []
51   
52    for k, p in enumerate(points):
53        #
54        #print time, k, p
55        w = f(time, point_id = k)[0]
56        z = f(time, point_id = k)[1]
57        uh = f(time, point_id = k)[2]
58        vh = f(time, point_id = k)[3]
59
60        abscissa.append( points[k][0] )
61        stages.append(w)
62        elevations.append(z) 
63        momenta.append( sqrt(uh*uh + vh*vh) )  #Absolute momentum
64
65    from pylab import *
66   
67    ion()
68    hold(False)
69
70    if elevations[0] < -10:
71        plot(abscissa, stages, '-b')
72    else:   
73        plot(abscissa, stages, '-b',
74             abscissa, elevations, '-k')
75    name = 'Cross section (time = %.1f)' %(time)
76    title(name)
77
78    title('%s (stage)' %name)
79    xlabel('time [s]')
80    ylabel('elevation [m]')   
81    legend(('Stage', 'Bed = %.1f' %elevations[0]),
82           shadow=True,
83           loc='upper right')
84    savefig('Cross_section_%d' %int(time))
85
86    raw_input('Next')
87
88
89    #Momentum plot
90    ion()
91    hold(False)
92    plot(abscissa, momenta, '-r')
93    title(name)
94
95    title('%s (momentum)' %name)
96    xlabel('time [s]')
97    ylabel('sqrt( uh^2 + vh^2 ) [m^2/s]')   
98    savefig('Cross_section_%d_momentum' %int(time))
99
100    raw_input('Next')
101   
102
103   
104show()
105
Note: See TracBrowser for help on using the repository browser.