[5005] | 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 |
---|
| 28 | from anuga.geospatial_data.geospatial_data import * |
---|
| 29 | from anuga.abstract_2d_finite_volumes.util import start_screen_catcher, copy_code_files |
---|
| 30 | |
---|
| 31 | # Application specific imports |
---|
| 32 | import project # Definition of file names and polygons |
---|
| 33 | |
---|
| 34 | #------------------------------------------------------------------------------ |
---|
| 35 | # Copy scripts to time stamped output directory and capture screen |
---|
| 36 | # output to file |
---|
| 37 | #------------------------------------------------------------------------------ |
---|
| 38 | |
---|
| 39 | start_screen_catcher(project.output_build_time_dir) |
---|
| 40 | |
---|
| 41 | print 'time stamp: ',project.gtime |
---|
| 42 | print 'USER: ', project.user |
---|
| 43 | |
---|
| 44 | |
---|
| 45 | copy_code_files(project.output_build_time_dir,__file__, |
---|
| 46 | dirname(project.__file__)+sep+ project.__name__+'.py' ) |
---|
| 47 | |
---|
| 48 | |
---|
| 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 | # topography directory filenames |
---|
| 59 | onshore_in_dir_name = project.onshore_in_dir_name |
---|
| 60 | coast_in_dir_name = project.coast_in_dir_name |
---|
| 61 | #island_in_dir_name = project.island_in_dir_name |
---|
| 62 | offshore_in_dir_name = project.offshore_in_dir_name |
---|
| 63 | |
---|
| 64 | onshore_dir_name = project.onshore_dir_name |
---|
| 65 | coast_dir_name = project.coast_dir_name |
---|
| 66 | #island_dir_name = project.island_dir_name |
---|
| 67 | offshore_dir_name = project.offshore_dir_name |
---|
| 68 | |
---|
| 69 | # creates DEM from asc data |
---|
| 70 | print "creates DEMs from ascii data" |
---|
| 71 | convert_dem_from_ascii2netcdf(onshore_in_dir_name, basename_out=onshore_dir_name, use_cache=True, verbose=True) |
---|
| 72 | #convert_dem_from_ascii2netcdf(island_in_dir_name, basename_out=island_dir_name, use_cache=True, verbose=True) |
---|
| 73 | |
---|
| 74 | #creates pts file for onshore DEM |
---|
| 75 | print "creates pts file for onshore DEM" |
---|
| 76 | dem2pts(onshore_dir_name, |
---|
| 77 | # easting_min=project.eastingmin, |
---|
| 78 | # easting_max=project.eastingmax, |
---|
| 79 | # northing_min=project.northingmin, |
---|
| 80 | # northing_max= project.northingmax, |
---|
| 81 | use_cache=True, |
---|
| 82 | verbose=True) |
---|
| 83 | |
---|
| 84 | #creates pts file for island DEM |
---|
| 85 | #dem2pts(island_dir_name, use_cache=True, verbose=True) |
---|
| 86 | |
---|
| 87 | print'create Geospatial data1 objects from topographies' |
---|
| 88 | G1 = Geospatial_data(file_name = onshore_dir_name + '.pts') |
---|
| 89 | G2 = Geospatial_data(file_name = coast_in_dir_name + '.xya') |
---|
| 90 | #G3 = Geospatial_data(file_name = island_dir_name + '.pts') |
---|
| 91 | G_off = Geospatial_data(file_name = offshore_in_dir_name + '.xya') |
---|
| 92 | |
---|
| 93 | print'add all geospatial objects' |
---|
| 94 | G = G1 + G2 + G_off |
---|
| 95 | |
---|
| 96 | print'clip combined geospatial object by bounding polygon' |
---|
| 97 | #G_clipped = G.clip(project.bounding_polygon) |
---|
| 98 | #FIXME: add a clip function to pts |
---|
| 99 | #print'shape of clipped data', G_clipped.get_data_points().shape |
---|
| 100 | |
---|
| 101 | print'export combined DEM file' |
---|
| 102 | if access(project.topographies_dir,F_OK) == 0: |
---|
| 103 | mkdir (project.topographies_dir) |
---|
| 104 | G.export_points_file(project.combined_dir_name + '.xya') |
---|
| 105 | #G_clipped.export_points_file(project.combined_dir_name + '.xya') |
---|
| 106 | |
---|
| 107 | ''' |
---|
| 108 | print'project.combined_dir_name + 1.xya',project.combined_dir_name + '1.xya' |
---|
| 109 | G_all=Geospatial_data(file_name = project.combined_dir_name + '1.xya') |
---|
| 110 | print'split' |
---|
| 111 | G_all_1, G_all_2 = G_all.split(.10) |
---|
| 112 | print'export 1' |
---|
| 113 | G_all_1.export_points_file(project.combined_dir_name+'_small1' + '.xya') |
---|
| 114 | print'export 2' |
---|
| 115 | G_all_2.export_points_file(project.combined_dir_name+'_other1' + '.xya') |
---|
| 116 | |
---|
| 117 | |
---|
| 118 | #------------------------------------------------------------------------- |
---|
| 119 | # Convert URS to SWW file for boundary conditions |
---|
| 120 | #------------------------------------------------------------------------- |
---|
| 121 | print 'starting to create boundary conditions' |
---|
| 122 | boundaries_in_dir_name = project.boundaries_in_dir_name |
---|
| 123 | |
---|
| 124 | from anuga.shallow_water.data_manager import urs2sww |
---|
| 125 | |
---|
| 126 | print 'minlat=project.north_boundary, maxlat=project.south_boundary',project.north_boundary, project.south_boundary |
---|
| 127 | print 'minlon= project.west_boundary, maxlon=project.east_boundary',project.west_boundary, project.east_boundary |
---|
| 128 | |
---|
| 129 | #import sys; sys.exit() |
---|
| 130 | |
---|
| 131 | #if access(project.boundaries_dir,F_OK) == 0: |
---|
| 132 | # mkdir (project.boundaries_dir) |
---|
| 133 | |
---|
| 134 | from caching import cache |
---|
| 135 | cache(urs2sww, |
---|
| 136 | (boundaries_in_dir_name, |
---|
| 137 | project.boundaries_dir_name1), |
---|
| 138 | {'verbose': True, |
---|
| 139 | 'minlat': project.south_boundary, |
---|
| 140 | 'maxlat': project.north_boundary, |
---|
| 141 | 'minlon': project.west_boundary, |
---|
| 142 | 'maxlon': project.east_boundary, |
---|
| 143 | # 'minlat': project.south, |
---|
| 144 | # 'maxlat': project.north, |
---|
| 145 | # 'minlon': project.west, |
---|
| 146 | # 'maxlon': project.east, |
---|
| 147 | 'mint': 0, 'maxt': 40000, |
---|
| 148 | # 'origin': domain.geo_reference.get_origin(), |
---|
| 149 | 'mean_stage': project.tide, |
---|
| 150 | # 'zscale': 1, #Enhance tsunami |
---|
| 151 | 'fail_on_NaN': False}, |
---|
| 152 | verbose = True, |
---|
| 153 | ) |
---|
| 154 | # dependencies = source_dir + project.boundary_basename + '.sww') |
---|
| 155 | |
---|
| 156 | ''' |
---|
| 157 | |
---|
| 158 | |
---|
| 159 | |
---|
| 160 | |
---|
| 161 | |
---|
| 162 | |
---|
| 163 | |
---|