1 | """Script for running tsunami inundation scenario for Dampier, WA, Australia. |
---|
2 | |
---|
3 | Source data such as elevation and boundary data is assumed to be available in |
---|
4 | directories specified by project.py |
---|
5 | The output sww file is stored in project.output_time_dir |
---|
6 | |
---|
7 | The scenario is defined by a triangular mesh created from project.polygon, |
---|
8 | the elevation data and a simulated submarine landslide. |
---|
9 | |
---|
10 | Ole Nielsen and Duncan Gray, GA - 2005 and Jane Sexton, Nick Bartzis, GA - 2006 |
---|
11 | """ |
---|
12 | |
---|
13 | #------------------------------------------------------------------------------ |
---|
14 | # Import necessary modules |
---|
15 | #------------------------------------------------------------------------------ |
---|
16 | |
---|
17 | # Standard modules |
---|
18 | from os import sep |
---|
19 | from os.path import dirname, basename |
---|
20 | from os import mkdir, access, F_OK |
---|
21 | from shutil import copy |
---|
22 | import time |
---|
23 | import sys |
---|
24 | |
---|
25 | |
---|
26 | # Related major packages |
---|
27 | from anuga.shallow_water import Domain |
---|
28 | from anuga.shallow_water import Dirichlet_boundary |
---|
29 | from anuga.shallow_water import File_boundary |
---|
30 | from anuga.shallow_water import Reflective_boundary |
---|
31 | from anuga.shallow_water.data_manager import convert_dem_from_ascii2netcdf, dem2pts |
---|
32 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
33 | from anuga.geospatial_data.geospatial_data import * |
---|
34 | from anuga.abstract_2d_finite_volumes.util import start_screen_catcher, copy_code_files |
---|
35 | |
---|
36 | # Application specific imports |
---|
37 | import project # Definition of file names and polygons |
---|
38 | |
---|
39 | #------------------------------------------------------------------------------ |
---|
40 | # Copy scripts to time stamped output directory and capture screen |
---|
41 | # output to file |
---|
42 | #------------------------------------------------------------------------------ |
---|
43 | |
---|
44 | copy_code_files(project.output_build_time_dir,__file__, |
---|
45 | dirname(project.__file__)+sep+ project.__name__+'.py' ) |
---|
46 | |
---|
47 | start_screen_catcher(project.output_build_time_dir) |
---|
48 | |
---|
49 | print 'USER: ', project.user |
---|
50 | |
---|
51 | #------------------------------------------------------------------------------- |
---|
52 | # Preparation of topographic data |
---|
53 | # |
---|
54 | # Convert ASC 2 DEM 2 PTS using source data and store result in source data |
---|
55 | # Do for coarse and fine data |
---|
56 | # Fine pts file to be clipped to area of interest |
---|
57 | #------------------------------------------------------------------------------- |
---|
58 | |
---|
59 | ''' |
---|
60 | # topography directory filenames |
---|
61 | onshore_dir_name = project.onshore_dir_name |
---|
62 | coast_dir_name = project.coast_dir_name |
---|
63 | islands_dir_name = project.islands_dir_name |
---|
64 | offshore_dir_name = project.offshore_dir_name |
---|
65 | offshore_dir_name1 = project.offshore_dir_name1 |
---|
66 | offshore_dir_name2 = project.offshore_dir_name2 |
---|
67 | offshore_dir_name3 = project.offshore_dir_name3 |
---|
68 | offshore_dir_name4 = project.offshore_dir_name4 |
---|
69 | offshore_dir_name5 = project.offshore_dir_name5 |
---|
70 | offshore_dir_name6 = project.offshore_dir_name6 |
---|
71 | offshore_dir_name7 = project.offshore_dir_name7 |
---|
72 | offshore_dir_name8 = project.offshore_dir_name8 |
---|
73 | offshore_dir_name9 = project.offshore_dir_name9 |
---|
74 | offshore_dir_name10 = project.offshore_dir_name10 |
---|
75 | offshore_dir_name11 = project.offshore_dir_name11 |
---|
76 | offshore_dir_name12 = project.offshore_dir_name12 |
---|
77 | offshore_dir_name13 = project.offshore_dir_name13 |
---|
78 | offshore_dir_name14 = project.offshore_dir_name14 |
---|
79 | |
---|
80 | # creates DEM from asc data |
---|
81 | convert_dem_from_ascii2netcdf(onshore_dir_name, use_cache=True, verbose=True) |
---|
82 | convert_dem_from_ascii2netcdf(islands_dir_name, use_cache=True, verbose=True) |
---|
83 | |
---|
84 | #creates pts file for onshore DEM |
---|
85 | dem2pts(onshore_dir_name, |
---|
86 | # easting_min=project.eastingmin, |
---|
87 | # easting_max=project.eastingmax, |
---|
88 | # northing_min=project.northingmin, |
---|
89 | # northing_max= project.northingmax, |
---|
90 | use_cache=True, |
---|
91 | verbose=True) |
---|
92 | |
---|
93 | #creates pts file for islands DEM |
---|
94 | dem2pts(islands_dir_name, use_cache=True, verbose=True) |
---|
95 | |
---|
96 | print'create Geospatial data objects from topographies' |
---|
97 | G1 = Geospatial_data(file_name = project.onshore_dir_name + '.pts') |
---|
98 | G2 = Geospatial_data(file_name = project.coast_dir_name + '.xya') |
---|
99 | G3 = Geospatial_data(file_name = project.islands_dir_name + '.pts') |
---|
100 | G_off = Geospatial_data(file_name = project.offshore_dir_name + '.xya') |
---|
101 | G_off1 = Geospatial_data(file_name = project.offshore_dir_name1 + '.xya') |
---|
102 | G_off2 = Geospatial_data(file_name = project.offshore_dir_name2 + '.xya') |
---|
103 | G_off3 = Geospatial_data(file_name = project.offshore_dir_name3 + '.xya') |
---|
104 | G_off4 = Geospatial_data(file_name = project.offshore_dir_name4 + '.xya') |
---|
105 | G_off5 = Geospatial_data(file_name = project.offshore_dir_name5 + '.xya') |
---|
106 | G_off6 = Geospatial_data(file_name = project.offshore_dir_name6 + '.xya') |
---|
107 | G_off7 = Geospatial_data(file_name = project.offshore_dir_name7 + '.xya') |
---|
108 | G_off8 = Geospatial_data(file_name = project.offshore_dir_name8 + '.xya') |
---|
109 | G_off9 = Geospatial_data(file_name = project.offshore_dir_name9 + '.xya') |
---|
110 | G_off10 = Geospatial_data(file_name = project.offshore_dir_name10 + '.xya') |
---|
111 | G_off11 = Geospatial_data(file_name = project.offshore_dir_name11 + '.xya') |
---|
112 | G_off12 = Geospatial_data(file_name = project.offshore_dir_name12 + '.xya') |
---|
113 | G_off13 = Geospatial_data(file_name = project.offshore_dir_name13 + '.xya') |
---|
114 | G_off14 = Geospatial_data(file_name = project.offshore_dir_name14 + '.xya') |
---|
115 | |
---|
116 | |
---|
117 | |
---|
118 | print'clip nw', project.clip_poly_nw |
---|
119 | print'clip e', project.clip_poly_e |
---|
120 | |
---|
121 | print'reading combined_dir_name' |
---|
122 | G_offshore_data = Geospatial_data(file_name = project.topographies_dir+'dampier_combined_elevation_final.pts') |
---|
123 | |
---|
124 | print'reading offshore_dir_name_old' |
---|
125 | G_offshore_old = Geospatial_data(file_name = project.offshore_dir_name_old + '.pts') |
---|
126 | |
---|
127 | |
---|
128 | print 'G_offshore_data_old_nw', |
---|
129 | G_nw_name = project.topographies_dir + 'nw_old_data' |
---|
130 | G_offshore_nw = G_offshore_old.clip(project.clip_poly_nw) |
---|
131 | G_offshore_nw.export_points_file(G_nw_name + '.pts') |
---|
132 | G_offshore_nw.export_points_file(G_nw_name + '.xya') |
---|
133 | G_nw = array(G_offshore_nw.get_data_points()) |
---|
134 | print'shape of arr nw data', G_nw.shape |
---|
135 | print' max and min of array 0',max(G_nw[:,0]),min(G_nw[:,0]) |
---|
136 | print' max and min of array 1',max(G_nw[:,1]),min(G_nw[:,1]) |
---|
137 | |
---|
138 | print 'G_offshore_data_old_e'#, G_offshore_old_nw.get_data_points() |
---|
139 | G_e_name = project.topographies_dir+'e_old_data' |
---|
140 | G_offshore_e = G_offshore_old.clip(project.clip_poly_e) |
---|
141 | G_offshore_e.export_points_file(G_e_name + '.pts') |
---|
142 | G_offshore_e.export_points_file(G_e_name + '.xya') |
---|
143 | G_e = array(G_offshore_e.get_data_points()) |
---|
144 | print'shape of arr e data', G_e.shape |
---|
145 | print' max and min of array 0',max(G_e[:,0]),min(G_e[:,0]) |
---|
146 | print' max and min of array 1',max(G_e[:,1]),min(G_e[:,1]) |
---|
147 | |
---|
148 | |
---|
149 | print 'G_offshore_data_mid_e'#, G_offshore_old_nw.get_data_points() |
---|
150 | G_mid_e_name = project.topographies_dir+'mid_e_old_data' |
---|
151 | G_offshore_mid_e = G_offshore_old.clip(project.clip_poly_mid_e) |
---|
152 | G_offshore_mid_e.export_points_file(G_mid_e_name + '.pts') |
---|
153 | G_offshore_mid_e.export_points_file(G_mid_e_name + '.xya') |
---|
154 | G_mid_e = array(G_offshore_mid_e.get_data_points()) |
---|
155 | print'shape of arr e data', G_mid_e.shape |
---|
156 | print' max and min of array 0',max(G_mid_e[:,0]),min(G_mid_e[:,0]) |
---|
157 | print' max and min of array 1',max(G_mid_e[:,1]),min(G_mid_e[:,1]) |
---|
158 | |
---|
159 | print 'G_offshore_data_mid_w'#, G_offshore_old_nw.get_data_points() |
---|
160 | G_mid_w_name = project.topographies_dir+'mid_w_old_data' |
---|
161 | G_offshore_mid_w = G_offshore_old.clip(project.clip_poly_mid_w) |
---|
162 | G_offshore_mid_w.export_points_file(G_mid_w_name + '.pts') |
---|
163 | G_offshore_mid_w.export_points_file(G_mid_w_name + '.xya') |
---|
164 | G_mid_w = array(G_offshore_mid_w.get_data_points()) |
---|
165 | print'shape of arr e data', G_mid_w.shape |
---|
166 | print' max and min of array 0',max(G_mid_w[:,0]),min(G_mid_w[:,0]) |
---|
167 | print' max and min of array 1',max(G_mid_w[:,1]),min(G_mid_w[:,1]) |
---|
168 | |
---|
169 | |
---|
170 | print 'G_offshore_data_old_e'#, G_offshore_old_e.get_data_points() |
---|
171 | print'add all geospatial objects' |
---|
172 | #G = G1 + G2 + G3 + G_off + G_off1 + G_off2 + G_off3 + G_off4 + G_off5 \ |
---|
173 | # + G_off6 + G_off7 + G_off8 + G_off9 + G_off10 + G_off11 + G_off12 \ |
---|
174 | # + G_off13 + G_off14 |
---|
175 | |
---|
176 | G = G_offshore_data + G_offshore_mid_w + G_offshore_mid_e |
---|
177 | print'shape of arr G data', G.get_data_points().shape |
---|
178 | |
---|
179 | |
---|
180 | #print'clip combined geospatial object by bounding polygon' |
---|
181 | G_clipped = G.clip(project.bounding_polygon) |
---|
182 | #FIXME: add a clip function to pts |
---|
183 | print'shape of clipped data', G_clipped.get_data_points().shape |
---|
184 | |
---|
185 | print'export combined DEM file' |
---|
186 | if access(project.topographies_time_dir,F_OK) == 0: |
---|
187 | mkdir (project.topographies_time_dir) |
---|
188 | G_clipped.export_points_file(project.combined_time_dir_final_name + '.pts') |
---|
189 | G_clipped.export_points_file(project.combined_time_dir_final_name + '.xya') |
---|
190 | |
---|
191 | |
---|
192 | ''' |
---|
193 | #------------------------------------------------------------------------- |
---|
194 | # Convert URS to SWW file for boundary conditions |
---|
195 | #------------------------------------------------------------------------- |
---|
196 | print 'starting to create boundary conditions' |
---|
197 | boundaries_in_dir_name = project.boundaries_in_dir_name |
---|
198 | |
---|
199 | from anuga.shallow_water.data_manager import urs2sww |
---|
200 | |
---|
201 | print 'minlat=project.north_boundary, maxlat=project.south_boundary',project.north_boundary, project.south_boundary |
---|
202 | print 'minlon= project.west_boundary, maxlon=project.east_boundary',project.west_boundary, project.east_boundary |
---|
203 | |
---|
204 | #import sys; sys.exit() |
---|
205 | |
---|
206 | #if access(project.boundaries_dir,F_OK) == 0: |
---|
207 | # mkdir (project.boundaries_dir) |
---|
208 | |
---|
209 | from caching import cache |
---|
210 | cache(urs2sww, |
---|
211 | (boundaries_in_dir_name, |
---|
212 | project.boundaries_dir_name1), |
---|
213 | {'verbose': True, |
---|
214 | 'minlat': project.south_boundary, |
---|
215 | 'maxlat': project.north_boundary, |
---|
216 | 'minlon': project.west_boundary, |
---|
217 | 'maxlon': project.east_boundary, |
---|
218 | # 'minlat': project.south, |
---|
219 | # 'maxlat': project.north, |
---|
220 | # 'minlon': project.west, |
---|
221 | # 'maxlon': project.east, |
---|
222 | 'mint': 0, 'maxt': 40000, |
---|
223 | # 'origin': domain.geo_reference.get_origin(), |
---|
224 | 'mean_stage': project.tide, |
---|
225 | # 'zscale': 1, #Enhance tsunami |
---|
226 | 'fail_on_NaN': False}, |
---|
227 | verbose = True, |
---|
228 | ) |
---|
229 | # dependencies = source_dir + project.boundary_basename + '.sww') |
---|
230 | |
---|
231 | |
---|
232 | |
---|
233 | |
---|
234 | |
---|
235 | |
---|
236 | |
---|
237 | |
---|
238 | |
---|