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 import Dirichlet_boundary |
---|
28 | #from anuga.shallow_water import File_boundary |
---|
29 | #from anuga.shallow_water import Reflective_boundary |
---|
30 | from anuga.shallow_water.data_manager import convert_dem_from_ascii2netcdf, dem2pts |
---|
31 | from anuga.pmesh.mesh_interface import create_mesh_from_regions |
---|
32 | from anuga.geospatial_data.geospatial_data import * |
---|
33 | from anuga.abstract_2d_finite_volumes.util import start_screen_catcher, copy_code_files |
---|
34 | |
---|
35 | # Application specific imports |
---|
36 | import project # Definition of file names and polygons |
---|
37 | |
---|
38 | #------------------------------------------------------------------------------ |
---|
39 | # Copy scripts to time stamped output directory and capture screen |
---|
40 | # output to file |
---|
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 | print 'USER: ', project.user |
---|
49 | |
---|
50 | #------------------------------------------------------------------------------- |
---|
51 | # Preparation of topographic data |
---|
52 | # |
---|
53 | # Convert ASC 2 DEM 2 PTS using source data and store result in source data |
---|
54 | # Do for coarse and fine data |
---|
55 | # Fine pts file to be clipped to area of interest |
---|
56 | #------------------------------------------------------------------------------- |
---|
57 | |
---|
58 | |
---|
59 | # topography directory filenames |
---|
60 | onshore_dir_name = project.onshore_dir_name |
---|
61 | coast_dir_name = project.coast_dir_name |
---|
62 | islands_dir_name = project.islands_dir_name |
---|
63 | islands_dir_name1 = project.islands_dir_name1 |
---|
64 | islands_dir_name1 = project.islands_dir_name2 |
---|
65 | offshore_dir_name = project.offshore_dir_name |
---|
66 | |
---|
67 | # creates DEM from asc data |
---|
68 | convert_dem_from_ascii2netcdf(onshore_dir_name, use_cache=True, verbose=True) |
---|
69 | convert_dem_from_ascii2netcdf(islands_dir_name, use_cache=True, verbose=True) |
---|
70 | convert_dem_from_ascii2netcdf(islands_dir_name1, use_cache=True, verbose=True) |
---|
71 | convert_dem_from_ascii2netcdf(islands_dir_name2, use_cache=True, verbose=True) |
---|
72 | |
---|
73 | #creates pts file for onshore DEM |
---|
74 | dem2pts(onshore_dir_name, |
---|
75 | # easting_min=project.eastingmin, |
---|
76 | # easting_max=project.eastingmax, |
---|
77 | # northing_min=project.northingmin, |
---|
78 | # northing_max= project.northingmax, |
---|
79 | use_cache=True, |
---|
80 | verbose=True) |
---|
81 | |
---|
82 | #creates pts file for islands DEM |
---|
83 | dem2pts(islands_dir_name, use_cache=True, verbose=True) |
---|
84 | dem2pts(islands_dir_name1, use_cache=True, verbose=True) |
---|
85 | dem2pts(islands_dir_name2, use_cache=True, verbose=True) |
---|
86 | |
---|
87 | print'create Geospatial data objects from topographies' |
---|
88 | G1 = Geospatial_data(file_name = project.onshore_dir_name + '.pts') |
---|
89 | G2 = Geospatial_data(file_name = project.coast_dir_name + '.xya') |
---|
90 | G3 = Geospatial_data(file_name = project.islands_dir_name + '.pts') |
---|
91 | G4 = Geospatial_data(file_name = project.islands_dir_name1 + '.pts') |
---|
92 | G5 = Geospatial_data(file_name = project.islands_dir_name2 + '.pts') |
---|
93 | G_off = Geospatial_data(file_name = project.offshore_dir_name + '.xya') |
---|
94 | |
---|
95 | |
---|
96 | |
---|
97 | |
---|
98 | |
---|
99 | print 'G_offshore_data_old_e'#, G_offshore_old_e.get_data_points() |
---|
100 | print'add all geospatial objects' |
---|
101 | G = G1 + G2 + G3 + G4 + G5 + G_off |
---|
102 | |
---|
103 | #print'clip combined geospatial object by bounding polygon' |
---|
104 | G_clipped = G.clip(project.bounding_polygon) |
---|
105 | #FIXME: add a clip function to pts |
---|
106 | print'shape of clipped data', G_clipped.get_data_points().shape |
---|
107 | |
---|
108 | print'export combined DEM file' |
---|
109 | if access(project.topographies_dir,F_OK) == 0: |
---|
110 | mkdir (project.topographies_dir) |
---|
111 | #G_clipped.export_points_file(project.combined_dir_name + '.pts') |
---|
112 | G_clipped.export_points_file(project.combined_dir_name + '.xya') |
---|
113 | |
---|
114 | |
---|
115 | ''' |
---|
116 | #------------------------------------------------------------------------- |
---|
117 | # Convert URS to SWW file for boundary conditions |
---|
118 | #------------------------------------------------------------------------- |
---|
119 | print 'starting to create boundary conditions' |
---|
120 | boundaries_in_dir_name = project.boundaries_in_dir_name |
---|
121 | |
---|
122 | from anuga.shallow_water.data_manager import urs2sww |
---|
123 | |
---|
124 | print 'minlat=project.north_boundary, maxlat=project.south_boundary',project.north_boundary, project.south_boundary |
---|
125 | print 'minlon= project.west_boundary, maxlon=project.east_boundary',project.west_boundary, project.east_boundary |
---|
126 | |
---|
127 | #import sys; sys.exit() |
---|
128 | |
---|
129 | #if access(project.boundaries_dir,F_OK) == 0: |
---|
130 | # mkdir (project.boundaries_dir) |
---|
131 | |
---|
132 | from caching import cache |
---|
133 | cache(urs2sww, |
---|
134 | (boundaries_in_dir_name, |
---|
135 | project.boundaries_dir_name1), |
---|
136 | {'verbose': True, |
---|
137 | 'minlat': project.south_boundary, |
---|
138 | 'maxlat': project.north_boundary, |
---|
139 | 'minlon': project.west_boundary, |
---|
140 | 'maxlon': project.east_boundary, |
---|
141 | # 'minlat': project.south, |
---|
142 | # 'maxlat': project.north, |
---|
143 | # 'minlon': project.west, |
---|
144 | # 'maxlon': project.east, |
---|
145 | 'mint': 0, 'maxt': 40000, |
---|
146 | # 'origin': domain.geo_reference.get_origin(), |
---|
147 | 'mean_stage': project.tide, |
---|
148 | # 'zscale': 1, #Enhance tsunami |
---|
149 | 'fail_on_NaN': False}, |
---|
150 | verbose = True, |
---|
151 | ) |
---|
152 | # dependencies = source_dir + project.boundary_basename + '.sww') |
---|
153 | |
---|
154 | ''' |
---|
155 | |
---|
156 | |
---|
157 | |
---|
158 | |
---|
159 | |
---|
160 | |
---|
161 | |
---|