1 | """Read in sww file, read points along specified cross section and time and plot |
---|
2 | """ |
---|
3 | |
---|
4 | import project |
---|
5 | from pyvolution.util import file_function |
---|
6 | from pyvolution.coordinate_transforms.redfearn import degminsec2decimal_degrees, redfearn |
---|
7 | |
---|
8 | |
---|
9 | #swwfile = project.outputdir + project.basename + '.sww' |
---|
10 | #swwfile = project.outputname + '_0.0tide' + '.sww' |
---|
11 | swwfile = project.outputname + '.sww' |
---|
12 | swwfile = project.outputname + '_notsunami.sww' |
---|
13 | #swwfile = project.outputdir + 'karratha_100m_12m.sww' |
---|
14 | |
---|
15 | |
---|
16 | time = 0 |
---|
17 | |
---|
18 | #E-W cross section |
---|
19 | start = [468500, 7715177] |
---|
20 | end = [469500, 7715177] |
---|
21 | step = 1 |
---|
22 | |
---|
23 | #Generate points (from west to east) |
---|
24 | points = [] |
---|
25 | x = start[0] |
---|
26 | y = start[1] |
---|
27 | while x <= end[0]: |
---|
28 | points.append( [x,y] ) |
---|
29 | x += step |
---|
30 | |
---|
31 | |
---|
32 | #Read model output |
---|
33 | from caching import cache |
---|
34 | f = 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 | |
---|
42 | print f |
---|
43 | |
---|
44 | from math import sqrt |
---|
45 | for 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 | |
---|
104 | show() |
---|
105 | |
---|