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 | # Related major packages |
---|
26 | from anuga.shallow_water import Domain |
---|
27 | from anuga.shallow_water.data_manager import convert_dem_from_ascii2netcdf, dem2pts,start_screen_catcher, copy_code_files |
---|
28 | from anuga.geospatial_data.geospatial_data import * |
---|
29 | |
---|
30 | # Application specific imports |
---|
31 | import project # Definition of file names and polygons |
---|
32 | |
---|
33 | #------------------------------------------------------------------------------ |
---|
34 | # Copy scripts to time stamped output directory and capture screen |
---|
35 | # output to file |
---|
36 | #------------------------------------------------------------------------------ |
---|
37 | |
---|
38 | |
---|
39 | print 'time stamp: ',project.build_time |
---|
40 | print 'USER: ', project.user |
---|
41 | |
---|
42 | |
---|
43 | copy_code_files(project.output_build_time_dir,__file__, |
---|
44 | dirname(project.__file__)+sep+ project.__name__+'.py' ) |
---|
45 | |
---|
46 | start_screen_catcher(project.output_build_time_dir) |
---|
47 | |
---|
48 | |
---|
49 | #------------------------------------------------------------------------------- |
---|
50 | # Preparation of topographic data |
---|
51 | # |
---|
52 | # Convert ASC 2 DEM 2 PTS using source data and store result in source data |
---|
53 | # Do for coarse and fine data |
---|
54 | # Fine pts file to be clipped to area of interest |
---|
55 | #------------------------------------------------------------------------------- |
---|
56 | |
---|
57 | # topography directory filenames |
---|
58 | onshore_in_dir_name = project.onshore_in_dir_name |
---|
59 | coast_in_dir_name = project.coast_in_dir_name |
---|
60 | island_in_dir_name = project.island_in_dir_name |
---|
61 | offshore_in_dir_name = project.offshore_in_dir_name |
---|
62 | |
---|
63 | onshore_dir_name = project.onshore_dir_name |
---|
64 | coast_dir_name = project.coast_dir_name |
---|
65 | island_dir_name = project.island_dir_name |
---|
66 | offshore_dir_name = project.offshore_dir_name |
---|
67 | |
---|
68 | # creates DEM from asc data |
---|
69 | print "creates DEMs from ascii data" |
---|
70 | convert_dem_from_ascii2netcdf(onshore_in_dir_name, basename_out=onshore_dir_name, use_cache=True, verbose=True) |
---|
71 | convert_dem_from_ascii2netcdf(island_in_dir_name, basename_out=island_dir_name, use_cache=True, verbose=True) |
---|
72 | |
---|
73 | #creates pts file for onshore DEM |
---|
74 | print "creates pts file for onshore DEM" |
---|
75 | dem2pts(onshore_dir_name, |
---|
76 | use_cache=True, |
---|
77 | verbose=True) |
---|
78 | |
---|
79 | #creates pts file for island DEM |
---|
80 | dem2pts(island_dir_name, use_cache=True, verbose=True) |
---|
81 | |
---|
82 | print'create Geospatial data1 objects from topographies' |
---|
83 | G1 = Geospatial_data(file_name = onshore_dir_name + '.pts') |
---|
84 | print'finished reading in %s.pts' %onshore_dir_name |
---|
85 | G2 = Geospatial_data(file_name = coast_in_dir_name + '.txt') |
---|
86 | G3 = Geospatial_data(file_name = island_dir_name + '.pts') |
---|
87 | G4 = Geospatial_data(file_name = offshore_in_dir_name + '.txt') |
---|
88 | print'finished reading in files' |
---|
89 | |
---|
90 | G_onshore_clip = G1.clip(project.poly_all, verbose=True) |
---|
91 | print 'finished clip' |
---|
92 | G_onshore_clip_clipout=G_onshore_clip.clip_outside(project.poly_cbd, verbose=True) |
---|
93 | print 'finished clipout' |
---|
94 | # reduce resolution by 9 time (1/9) of the original file. This was determined |
---|
95 | # as the resolution for this region is going to be 20000 and the asc grid cellsize is |
---|
96 | # 30m there (900). The sqrt of 20000 is about 140 or 150, a 150m x150m grid would contain |
---|
97 | # 36 points at a 30m grid spacing and we only need 4. So 4/36 is 1/9 or 0.11111 |
---|
98 | G_onshore_clip_clipout_reduced=G_onshore_clip_clipout.split(0.111, verbose=True) |
---|
99 | |
---|
100 | G_cbd = G1.clip(projec.poly_cbd,verbose=True) |
---|
101 | G_cbd_reduced = G_cbd.split(0.25, verbose=True) |
---|
102 | |
---|
103 | G_bathy = G4.clip(project.poly_all) |
---|
104 | G_island = G3.clip(project.poly_all) |
---|
105 | G_coast = G2.clip(project.poly_all) |
---|
106 | |
---|
107 | print'add all geospatial objects' |
---|
108 | G = G_onshore_clip_clipout_reduced + G_cbd_reduced + G_bathy + G_island + G_coast |
---|
109 | |
---|
110 | print'clip combined geospatial object by bounding polygon' |
---|
111 | #G_clipped = G.clip(project.bounding_polygon) |
---|
112 | #FIXME: add a clip function to pts |
---|
113 | #print'shape of clipped data', G_clipped.get_data_points().shape |
---|
114 | |
---|
115 | print'export combined DEM file' |
---|
116 | if access(project.topographies_dir,F_OK) == 0: |
---|
117 | mkdir (project.topographies_dir) |
---|
118 | G.export_points_file(project.combined_dir_name + '.txt') |
---|
119 | #G_clipped.export_points_file(project.combined_dir_name + '.xya') |
---|
120 | G_small, = G.split(0.1, verbose) |
---|
121 | G_small.export_points_file(project.combined_dir_name_small + '.txt') |
---|
122 | |
---|
123 | ''' |
---|
124 | print'project.combined_dir_name + 1.xya',project.combined_dir_name + '1.xya' |
---|
125 | G_all=Geospatial_data(file_name = project.combined_dir_name + '1.xya') |
---|
126 | print'split' |
---|
127 | G_all_1, G_all_2 = G_all.split(.10) |
---|
128 | print'export 1' |
---|
129 | G_all_1.export_points_file(project.combined_dir_name+'_small1' + '.xya') |
---|
130 | print'export 2' |
---|
131 | G_all_2.export_points_file(project.combined_dir_name+'_other1' + '.xya') |
---|
132 | |
---|
133 | |
---|
134 | #------------------------------------------------------------------------- |
---|
135 | # Convert URS to SWW file for boundary conditions |
---|
136 | #------------------------------------------------------------------------- |
---|
137 | print 'starting to create boundary conditions' |
---|
138 | boundaries_in_dir_name = project.boundaries_in_dir_name |
---|
139 | |
---|
140 | from anuga.shallow_water.data_manager import urs2sww |
---|
141 | |
---|
142 | print 'minlat=project.north_boundary, maxlat=project.south_boundary',project.north_boundary, project.south_boundary |
---|
143 | print 'minlon= project.west_boundary, maxlon=project.east_boundary',project.west_boundary, project.east_boundary |
---|
144 | |
---|
145 | #import sys; sys.exit() |
---|
146 | |
---|
147 | #if access(project.boundaries_dir,F_OK) == 0: |
---|
148 | # mkdir (project.boundaries_dir) |
---|
149 | |
---|
150 | from caching import cache |
---|
151 | cache(urs2sww, |
---|
152 | (boundaries_in_dir_name, |
---|
153 | project.boundaries_dir_name1), |
---|
154 | {'verbose': True, |
---|
155 | 'minlat': project.south_boundary, |
---|
156 | 'maxlat': project.north_boundary, |
---|
157 | 'minlon': project.west_boundary, |
---|
158 | 'maxlon': project.east_boundary, |
---|
159 | # 'minlat': project.south, |
---|
160 | # 'maxlat': project.north, |
---|
161 | # 'minlon': project.west, |
---|
162 | # 'maxlon': project.east, |
---|
163 | 'mint': 0, 'maxt': 40000, |
---|
164 | # 'origin': domain.geo_reference.get_origin(), |
---|
165 | 'mean_stage': project.tide, |
---|
166 | # 'zscale': 1, #Enhance tsunami |
---|
167 | 'fail_on_NaN': False}, |
---|
168 | verbose = True, |
---|
169 | ) |
---|
170 | # dependencies = source_dir + project.boundary_basename + '.sww') |
---|
171 | |
---|
172 | ''' |
---|
173 | |
---|
174 | |
---|
175 | |
---|
176 | |
---|
177 | |
---|
178 | |
---|
179 | |
---|