1 | """ |
---|
2 | Program to calcualte the energy density in offshore tsunami time series. |
---|
3 | Energy is integrated over the time of the each wave crest. |
---|
4 | Also calculates time integrated momentum quantities from the boundary time series. |
---|
5 | Used to investiage different methods of estimating offshore tsunami hazard, |
---|
6 | rather than just wave height. |
---|
7 | |
---|
8 | Energy calculations from Johnson 1997. 'A modern introduction to the mathematical |
---|
9 | theory of water waves' p23. |
---|
10 | |
---|
11 | Creator: Jonathan Griffin, Geoscience Australia |
---|
12 | Created: 12 October 2009 |
---|
13 | """ |
---|
14 | |
---|
15 | import os |
---|
16 | import sys |
---|
17 | from os.path import join |
---|
18 | import csv |
---|
19 | import glob |
---|
20 | import numpy |
---|
21 | import run_up |
---|
22 | |
---|
23 | # Change path here!!! |
---|
24 | filepath = r'/nas/gemd/georisk_models/inundation/data/new_south_wales/batemans_bay_tsunami_scenario_2009/anuga/boundaries' |
---|
25 | index = 2872 |
---|
26 | filebasename = 'sts_gauge_' + str(index) +'.csv' |
---|
27 | filename = join(filepath, filebasename) |
---|
28 | |
---|
29 | filepathlist = [] |
---|
30 | filenamelist = [] |
---|
31 | |
---|
32 | |
---|
33 | # Find all relevant gauges files and put into list |
---|
34 | for root, dirs, files in os.walk(filepath): |
---|
35 | |
---|
36 | for filenames in files: |
---|
37 | if filenames == filebasename: |
---|
38 | filepathname = join(root, filenames) |
---|
39 | filepathlist.append(filepathname) |
---|
40 | filenamelist.append(filenames) |
---|
41 | |
---|
42 | # Initialise lists for storing maximum values |
---|
43 | max_energy_list = [] |
---|
44 | max_energy_inst_list = [] |
---|
45 | run_up_list = [] |
---|
46 | counter = 0 |
---|
47 | |
---|
48 | ########################################################### |
---|
49 | # Loop over gauges files |
---|
50 | ########################################################### |
---|
51 | for filename in filepathlist: |
---|
52 | time = [] |
---|
53 | stage = [] |
---|
54 | x_momentum = [] |
---|
55 | y_momentum = [] |
---|
56 | momentum = [] |
---|
57 | print 'reading file ', filename |
---|
58 | csvreader = csv.reader(open(filename)) |
---|
59 | header = csvreader.next() |
---|
60 | for line in csvreader: |
---|
61 | time.append(float(line[0])) |
---|
62 | stage.append(float(line[1])) |
---|
63 | x_momentum.append(float(line[2])) |
---|
64 | y_momentum.append(float(line[3])) |
---|
65 | # Calculate momentum norm |
---|
66 | |
---|
67 | time_diff = time[1]-time[0] |
---|
68 | |
---|
69 | sign = 0 |
---|
70 | energy_sum = 0 |
---|
71 | max_energy = 0 |
---|
72 | max_energy_inst = 0 |
---|
73 | max_stage = 0 |
---|
74 | temp_max_stage = 0 |
---|
75 | |
---|
76 | ############################################################### |
---|
77 | # Loop through time series and add values (integrate over time) |
---|
78 | # Sum set to zero when stage height changes sign |
---|
79 | ############################################################### |
---|
80 | for i in range(len(time)): |
---|
81 | |
---|
82 | ############################################################### |
---|
83 | # Energy calculations - note that quantities from gauge file are |
---|
84 | # already depth integrated. |
---|
85 | ############################################################### |
---|
86 | # Calculate velocities from 'momentum' terms (Note not true momentum, |
---|
87 | # rather defined as u*h. So we devide by the depth to get u). |
---|
88 | # roh = density = 1000 kg.m-3 |
---|
89 | x_vel = x_momentum[i]/(100+stage[i]) |
---|
90 | y_vel = y_momentum[i]/(100+stage[i]) |
---|
91 | velocity = numpy.sqrt(x_vel*x_vel,y_vel*y_vel) |
---|
92 | # Kinetic energy KE = 1/2 roh h u^2 |
---|
93 | KE = (1./2.)*(numpy.power(x_vel,2)+numpy.power(y_vel,2))*(1000)*(100+stage[i]) |
---|
94 | # Potential energy PE = roh g w (w = stage) |
---|
95 | PE = 9.81*(stage[i])*1000 |
---|
96 | energy = KE+PE |
---|
97 | |
---|
98 | # Maximum instantaneous energy density |
---|
99 | if energy > max_energy_inst: |
---|
100 | max_energy_inst = energy |
---|
101 | |
---|
102 | ############################################################### |
---|
103 | # If sign of wave changes (goes from trough to crest or vice-versa) |
---|
104 | # multiply energy sum by timestep and reset sum value to zero |
---|
105 | ############################################################### |
---|
106 | |
---|
107 | if stage[i] > 0 and sign != 1: |
---|
108 | sign = 1 |
---|
109 | temp_max_energy = energy_sum*time_diff |
---|
110 | if temp_max_energy > max_energy: |
---|
111 | max_energy = temp_max_energy |
---|
112 | if temp_max_stage > max_stage: |
---|
113 | max_stage = temp_max_stage |
---|
114 | max_time = time[i] - start_time |
---|
115 | energy_sum = energy |
---|
116 | start_time = time[i] |
---|
117 | max_stage_temp = 0 |
---|
118 | |
---|
119 | elif stage[i] < 0 and sign != -1: |
---|
120 | sign = -1 |
---|
121 | temp_max_energy = energy_sum*time_diff |
---|
122 | if temp_max_energy > max_energy: |
---|
123 | max_energy = temp_max_energy |
---|
124 | if temp_max_stage > max_stage: |
---|
125 | max_stage = temp_max_stage |
---|
126 | max_time = time[i] - start_time |
---|
127 | energy_sum = energy |
---|
128 | start_time = time[i] |
---|
129 | |
---|
130 | elif stage[i] == 0 and sign != 0: |
---|
131 | sign = 0 |
---|
132 | if temp_max_stage > max_stage: |
---|
133 | max_stage = temp_max_stage |
---|
134 | max_time = time[i] - start_time |
---|
135 | energy_sum = energy |
---|
136 | start_time = time[i] |
---|
137 | |
---|
138 | else: |
---|
139 | energy_sum += energy |
---|
140 | temp_max_stage = max(temp_max_stage,stage[i]) |
---|
141 | |
---|
142 | # Add maximum values to list |
---|
143 | max_energy_inst_list.append(max_energy_inst) |
---|
144 | max_energy_list.append( max_energy) |
---|
145 | |
---|
146 | # Account for both halves of the wave |
---|
147 | max_time = max_time*2 |
---|
148 | print 'max stage',max_stage |
---|
149 | print 'max time',max_time |
---|
150 | ##################################################################### |
---|
151 | # call run-up module |
---|
152 | ##################################################################### |
---|
153 | Run_up = run_up.Madsen(100,0.01,max_stage,max_time) |
---|
154 | print 'runup', Run_up |
---|
155 | run_up_list.append(Run_up) |
---|
156 | |
---|
157 | |
---|
158 | counter += 1 |
---|
159 | |
---|
160 | |
---|
161 | |
---|
162 | |
---|
163 | counter = 0 |
---|
164 | total_max_energy = 0 |
---|
165 | total_max_inst_energy = 0 |
---|
166 | |
---|
167 | |
---|
168 | |
---|
169 | |
---|
170 | |
---|
171 | # Print results for each file and calculate maximum value across all events |
---|
172 | for filename in filepathlist: |
---|
173 | print filename |
---|
174 | print 'max crest-integrated energy:', max_energy_list[counter],'J.s/m^2' |
---|
175 | print 'max instantatneous energy:', max_energy_inst_list[counter],'J/m^2' |
---|
176 | print 'Run_up:', run_up_list[counter], 'm' |
---|
177 | |
---|
178 | if max_energy_list[counter] > total_max_energy: |
---|
179 | total_max_energy = max_energy_list[counter] |
---|
180 | max_energy_index = counter |
---|
181 | if max_energy_inst_list[counter] > total_max_inst_energy: |
---|
182 | total_max_inst_energy = max_energy_inst_list[counter] |
---|
183 | max_energy_inst_index = counter |
---|
184 | |
---|
185 | counter+=1 |
---|
186 | |
---|
187 | print '\n File with maximum crest-integrated energy is:', filepathlist[max_energy_index] |
---|
188 | print 'Energy is', max_energy_list[max_energy_index], 'J.s/m^2' |
---|
189 | print '\n File with maximum instantaneous energy is:', filepathlist[max_energy_inst_index] |
---|
190 | print 'Energy is', max_energy_inst_list[max_energy_inst_index], 'J/m^2' |
---|
191 | |
---|
192 | |
---|