"""Script for running tsunami inundation scenario for Dampier, WA, Australia. Source data such as elevation and boundary data is assumed to be available in directories specified by project.py The output sww file is stored in project.output_time_dir The scenario is defined by a triangular mesh created from project.polygon, the elevation data and a simulated submarine landslide. Ole Nielsen and Duncan Gray, GA - 2005 and Jane Sexton, Nick Bartzis, GA - 2006 """ #------------------------------------------------------------------------------ # Import necessary modules #------------------------------------------------------------------------------ # Standard modules from os import sep from os.path import dirname, basename from os import mkdir, access, F_OK from shutil import copy import time import sys # Related major packages from anuga.shallow_water import Domain from anuga.shallow_water import Dirichlet_boundary from anuga.shallow_water import File_boundary from anuga.shallow_water import Reflective_boundary from anuga.shallow_water.data_manager import convert_dem_from_ascii2netcdf, dem2pts from anuga.pmesh.mesh_interface import create_mesh_from_regions from anuga.geospatial_data.geospatial_data import * from anuga.abstract_2d_finite_volumes.util import Screen_Catcher # Application specific imports import project # Definition of file names and polygons #------------------------------------------------------------------------------ # Copy scripts to time stamped output directory and capture screen # output to file #------------------------------------------------------------------------------ if access(project.output_build_time_dir,F_OK) == 0: mkdir (project.output_build_time_dir) copy (dirname(project.__file__) +sep+ project.__name__+'.py', project.output_build_time_dir + project.__name__+'.py') #copies project.py copy (__file__, project.output_build_time_dir + basename(__file__)) print 'files '+ project.__name__+'.py and '+ basename(__file__)+' copied to '+ project.output_build_time_dir #copies this file #import sys; sys.exit() #normal screen output is stored in screen_output_name = project.output_build_time_dir + "screen_output.txt" screen_error_name = project.output_build_time_dir + "screen_error.txt" #used to catch screen output to file sys.stdout = Screen_Catcher(screen_output_name) sys.stderr = Screen_Catcher(screen_error_name) print 'USER: ', project.user #------------------------------------------------------------------------------- # Preparation of topographic data # # Convert ASC 2 DEM 2 PTS using source data and store result in source data # Do for coarse and fine data # Fine pts file to be clipped to area of interest #------------------------------------------------------------------------------- # topography directory filenames onshore_dir_name = project.onshore_dir_name coast_dir_name = project.coast_dir_name islands_dir_name = project.islands_dir_name offshore_dir_name = project.offshore_dir_name offshore_dir_name1 = project.offshore_dir_name1 offshore_dir_name2 = project.offshore_dir_name2 offshore_dir_name3 = project.offshore_dir_name3 offshore_dir_name4 = project.offshore_dir_name4 offshore_dir_name5 = project.offshore_dir_name5 offshore_dir_name6 = project.offshore_dir_name6 offshore_dir_name7 = project.offshore_dir_name7 offshore_dir_name8 = project.offshore_dir_name8 offshore_dir_name9 = project.offshore_dir_name9 offshore_dir_name10 = project.offshore_dir_name10 offshore_dir_name11 = project.offshore_dir_name11 offshore_dir_name12 = project.offshore_dir_name12 offshore_dir_name13 = project.offshore_dir_name13 offshore_dir_name14 = project.offshore_dir_name14 # creates DEM from asc data convert_dem_from_ascii2netcdf(onshore_dir_name, use_cache=True, verbose=True) convert_dem_from_ascii2netcdf(islands_dir_name, use_cache=True, verbose=True) #creates pts file for onshore DEM dem2pts(onshore_dir_name, # easting_min=project.eastingmin, # easting_max=project.eastingmax, # northing_min=project.northingmin, # northing_max= project.northingmax, use_cache=True, verbose=True) #creates pts file for islands DEM dem2pts(islands_dir_name, use_cache=True, verbose=True) print'create Geospatial data objects from topographies' G1 = Geospatial_data(file_name = project.onshore_dir_name + '.pts') G2 = Geospatial_data(file_name = project.coast_dir_name + '.xya') G3 = Geospatial_data(file_name = project.islands_dir_name + '.pts') G_off = Geospatial_data(file_name = project.offshore_dir_name + '.xya') G_off1 = Geospatial_data(file_name = project.offshore_dir_name1 + '.xya') G_off2 = Geospatial_data(file_name = project.offshore_dir_name2 + '.xya') G_off3 = Geospatial_data(file_name = project.offshore_dir_name3 + '.xya') G_off4 = Geospatial_data(file_name = project.offshore_dir_name4 + '.xya') G_off5 = Geospatial_data(file_name = project.offshore_dir_name5 + '.xya') G_off6 = Geospatial_data(file_name = project.offshore_dir_name6 + '.xya') G_off7 = Geospatial_data(file_name = project.offshore_dir_name7 + '.xya') G_off8 = Geospatial_data(file_name = project.offshore_dir_name8 + '.xya') G_off9 = Geospatial_data(file_name = project.offshore_dir_name9 + '.xya') G_off10 = Geospatial_data(file_name = project.offshore_dir_name10 + '.xya') G_off11 = Geospatial_data(file_name = project.offshore_dir_name11 + '.xya') G_off12 = Geospatial_data(file_name = project.offshore_dir_name12 + '.xya') G_off13 = Geospatial_data(file_name = project.offshore_dir_name13 + '.xya') G_off14 = Geospatial_data(file_name = project.offshore_dir_name14 + '.xya') print'add all geospatial objects' G = G1 + G2 + G3 + G_off + G_off1 + G_off2 + G_off3 + G_off4 + G_off5 \ + G_off6 + G_off7 + G_off8 + G_off9 + G_off10 + G_off11 + G_off12 \ + G_off13 + G_off14 print'clip combined geospatial object by bounding polygon' G.clip(project.bounding_polygon) #FIXME: add a clip function to pts print'export combined DEM file' if access(project.topographies_time_dir,F_OK) == 0: mkdir (project.topographies_time_dir) G.export_points_file(project.combined_time_dir_name + '.pts') #------------------------------------------------------------------------- # Convert URS to SWW file for boundary conditions #------------------------------------------------------------------------- print 'starting to create boundary conditions' boundaries_in_dir_name = project.boundaries_in_dir_name from anuga.shallow_water.data_manager import urs2sww print 'minlat=project.north_boundary, maxlat=project.south_boundary',project.north_boundary, project.south_boundary print 'minlon= project.west_boundary, maxlon=project.east_boundary',project.west_boundary, project.east_boundary if access(project.boundaries_time_dir,F_OK) == 0: mkdir (project.boundaries_time_dir) #urs2sww(boundaries_in_dir_name,basename_out= project.boundaries_time_dir_name, # minlat=project.south_boundary, maxlat=project.north_boundary, # minlon= project.west_boundary, maxlon=project.east_boundary, # mint=0, maxt= 35000, # verbose='true') cache(urs2sww, (boundaries_in_dir_name, basename_out= project.boundaries_time_dir_name), {'verbose': True, 'minlat': project.south_boundary, 'maxlat': project.north_boundary, 'minlon': project.west_boundary, 'maxlon': project.east_boundary, 'mint': 0, 'maxt': 35000, 'origin': domain.geo_reference.get_origin(), 'mean_stage': project.tide, # 'zscale': 1, #Enhance tsunami 'fail_on_NaN': False, 'inverted_bathymetry': True}, verbose = True, ) # dependencies = source_dir + project.boundary_basename + '.sww')