"""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.data_manager import convert_dem_from_ascii2netcdf, dem2pts,start_screen_catcher, copy_code_files from anuga.geospatial_data.geospatial_data import * # Application specific imports import project # Definition of file names and polygons #------------------------------------------------------------------------------ # Copy scripts to time stamped output directory and capture screen # output to file #------------------------------------------------------------------------------ print 'time stamp: ',project.build_time copy_code_files(project.output_build_time_dir,__file__, dirname(project.__file__)+sep+ project.__name__+'.py' ) start_screen_catcher(project.output_build_time_dir) print 'time stamp: ',project.build_time print 'USER: ', project.user, project.host #------------------------------------------------------------------------------- # 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_in_dir_name = project.onshore_in_dir_name coast_in_dir_name = project.coast_in_dir_name island_in_dir_name = project.island_in_dir_name offshore_in_dir_name = project.offshore_in_dir_name onshore_dir_name = project.onshore_dir_name coast_dir_name = project.coast_dir_name island_dir_name = project.island_dir_name offshore_dir_name = project.offshore_dir_name # creates DEM from asc data print "creates DEMs from ascii data" convert_dem_from_ascii2netcdf(onshore_in_dir_name, basename_out=onshore_dir_name, use_cache=True, verbose=True) convert_dem_from_ascii2netcdf(island_in_dir_name, basename_out=island_dir_name, use_cache=True, verbose=True) #creates pts file for onshore DEM print "creates pts file for onshore DEM" dem2pts(onshore_dir_name, use_cache=True, verbose=True) #creates pts file for island DEM dem2pts(island_dir_name, use_cache=True, verbose=True) print'create Geospatial data1 objects from topographies' G1 = Geospatial_data(file_name = onshore_dir_name + '.pts',verbose=True) print'finished reading in %s.pts' %onshore_dir_name G2 = Geospatial_data(file_name = coast_in_dir_name + '.txt',verbose=True) G3 = Geospatial_data(file_name = island_dir_name + '.pts',verbose=True) G4 = Geospatial_data(file_name = offshore_in_dir_name + '.txt',verbose=True) print'finished reading in files' #G_onshore_clip = G1.clip(project.poly_all, verbose=True) #print 'finished clip' #G_onshore_clip_clipout=G_onshore_clip.clip_outside(project.poly_cbd, verbose=True) #print 'finished clipout' ## reduce resolution by 10 time (1/10) of the original file. This was determined ## as the resolution for this region is going to be 20000 and the asc grid cellsize is ## 10m there (100). There is 2 20000m triangles in a 200m x 200m grid sqrt of 40000 is about 200, ## a 200m x 200m area would contain 400 points at a 10m grid spacing and we only need 4. So 4/400 is 1/100 or 0.01 ## 1/100 reduction is possible but a 1/10 is enough to help with file size and loading #G_onshore_clip_clipout_reduced=G_onshore_clip_clipout.split(0.1, verbose=True) # #G_cbd = G1.clip(projec.poly_cbd,verbose=True) ##G_cbd_reduced = G_cbd.split(0.25, verbose=True) # #G_bathy = G4.clip(project.poly_all) #G_island = G3.clip(project.poly_all) #G_coast = G2.clip(project.poly_all) # #print'add all geospatial objects' #G = G_onshore_clip_clipout_reduced + G_cbd_reduced + G_bathy + G_island + G_coast G = G1 + G2 + G3 + G4 G_clip = G.clip(project.poly_all, verbose=True) print'clip combined geospatial object by bounding polygon' #G_clipped = G.clip(project.bounding_polygon) #FIXME: add a clip function to pts #print'shape of clipped data', G_clipped.get_data_points().shape print'export combined DEM file' if access(project.topographies_dir,F_OK) == 0: mkdir (project.topographies_dir) G_clip.export_points_file(project.combined_dir_name + '.txt') #G_clipped.export_points_file(project.combined_dir_name + '.xya') G_small,G_other = G_clip.split(0.01, verbose=True) G_small.export_points_file(project.combined_dir_name_small + '.txt') ''' print'project.combined_dir_name + 1.xya',project.combined_dir_name + '1.xya' G_all=Geospatial_data(file_name = project.combined_dir_name + '1.xya') print'split' G_all_1, G_all_2 = G_all.split(.10) print'export 1' G_all_1.export_points_file(project.combined_dir_name+'_small1' + '.xya') print'export 2' G_all_2.export_points_file(project.combined_dir_name+'_other1' + '.xya') #------------------------------------------------------------------------- # 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 #import sys; sys.exit() #if access(project.boundaries_dir,F_OK) == 0: # mkdir (project.boundaries_dir) from caching import cache cache(urs2sww, (boundaries_in_dir_name, project.boundaries_dir_name1), {'verbose': True, 'minlat': project.south_boundary, 'maxlat': project.north_boundary, 'minlon': project.west_boundary, 'maxlon': project.east_boundary, # 'minlat': project.south, # 'maxlat': project.north, # 'minlon': project.west, # 'maxlon': project.east, 'mint': 0, 'maxt': 40000, # 'origin': domain.geo_reference.get_origin(), 'mean_stage': project.tide, # 'zscale': 1, #Enhance tsunami 'fail_on_NaN': False}, verbose = True, ) # dependencies = source_dir + project.boundary_basename + '.sww') '''