Changeset 6382
- Timestamp:
- Feb 23, 2009, 4:16:51 PM (14 years ago)
- Location:
- anuga_work/production/australia_ph2/broome
- Files:
-
- 3 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_work/production/australia_ph2/broome/build_elevation.py
r6339 r6382 1 """Build the elevation data to run a tsunami scenario2 for B roome, WA, Australia for input into the Ph2 Hazard Map.1 """Build the elevation data to run a tsunami inundation scenario 2 for Busselton, WA, Australia. 3 3 4 4 Input: elevation data from project.py … … 24 24 25 25 # Application specific imports 26 import project # Definition of file names and polygons26 from setup_model import project # Definition of file names and polygons 27 27 28 28 … … 50 50 # Create Geospatial data from ASCII files 51 51 geospatial_data = {} 52 ##for filename in project.ascii_grid_filenames: 53 ## absolute_filename = join(project.topographies_folder, filename) 54 ## convert_dem_from_ascii2netcdf(absolute_filename, 55 ## basename_out=absolute_filename, 56 ## use_cache=True, 57 ## verbose=True) 58 ## dem2pts(absolute_filename, use_cache=True, verbose=True) 59 ## 60 ## geospatial_data[filename] = Geospatial_data(file_name=absolute_filename+ 61 ## '.pts', verbose=True) 52 if not project.ascii_grid_filenames == []: 53 for filename in project.ascii_grid_filenames: 54 absolute_filename = join(project.topographies_folder, filename) 55 convert_dem_from_ascii2netcdf(absolute_filename, 56 basename_out=absolute_filename, 57 use_cache=True, 58 verbose=True) 59 dem2pts(absolute_filename, use_cache=True, verbose=True) 60 61 geospatial_data[filename] = Geospatial_data(file_name=absolute_filename+'.pts', 62 verbose=True) 62 63 63 64 # Create Geospatial data from TXT files 64 for filename in project.point_filenames:65 absolute_filename = join(project.topographies_folder, filename)66 geospatial_data[filename] = Geospatial_data(file_name=absolute_filename,67 verbose=True)68 65 if not project.point_filenames == []: 66 for filename in project.point_filenames: 67 absolute_filename = join(project.topographies_folder, filename) 68 geospatial_data[filename] = Geospatial_data(file_name=absolute_filename, 69 verbose=True) 69 70 70 71 #------------------------------------------------------------------------------- -
anuga_work/production/australia_ph2/broome/file_length.py
r6339 r6382 7 7 Returns: number of lines in file 8 8 """ 9 9 10 def file_length(in_file): 11 '''Function to return the number of lines in a file. 12 13 in_file: Path to the file to get number of lines in. 14 15 Returns: number of lines in file 16 ''' 17 10 18 fid = open(in_file) 11 19 data = fid.readlines() -
anuga_work/production/australia_ph2/broome/project.py
r6346 r6382 1 """Common filenames and locations for elevation, meshes and outputs.2 This script is the heart of all scripts in the folder3 1 """ 4 #------------------------------------------------------------------------------ 5 # Import necessary modules 6 #------------------------------------------------------------------------------ 2 This file contains all your file and directory definitions 3 for elevation, meshes and outputs. 4 """ 7 5 8 6 import os 9 import sys 10 from os.path import join 11 from os import sep, getenv 7 from anuga.utilities.system_tools import get_user_name, get_host_name 12 8 from time import localtime, strftime, gmtime 13 from anuga.utilities.polygon import read_polygon, number_mesh_triangles14 from anuga.utilities.system_tools import get_user_name, get_host_name 15 16 #------------------------------------------------------------------------------ 9 from os.path import join, exists 10 11 12 #------------------------------------------------------------------------------- 17 13 # Directory setup 18 #------------------------------------------------------------------------------ 19 # Note: INUNDATIONHOME is the inundation directory, not the data directory. 20 21 home = getenv('INUNDATIONHOME')+sep+'data'+sep # Absolute path for data folder 22 muxhome = getenv('MUXHOME') 23 user = get_user_name() 24 host = get_host_name() 25 26 # determines time for setting up output directories 27 time = strftime('%Y%m%d_%H%M%S',localtime()) 28 gtime = strftime('%Y%m%d_%H%M%S',gmtime()) 29 build_time = time+'_build' 30 run_time = time+'_run' 14 #------------------------------------------------------------------------------- 31 15 32 16 # this section needs to be updated to reflect the modelled community. … … 34 18 state = 'australia_ph2' 35 19 scenario_name = 'broome' 36 37 #------------------------------------------------------------------------------ 20 scenario_folder = scenario_name 21 22 #------------------------------------------------------------------------------- 38 23 # Initial Conditions 39 #------------------------------------------------------------------------------ 40 # Model specific parameters. One or all can be changed each time the 41 # run_scenario script is executed 42 tide = 0 43 event_number = 27255 # Java 9.3 worst case for Perth 24 #------------------------------------------------------------------------------- 25 26 # Model specific parameters. 27 # One or all can be changed each time the run_model script is executed 28 tide = 0 # difference between MSL and HAT 29 event_number = 27255 # the event number or the mux file name 44 30 alpha = 0.1 # smoothing parameter for mesh 45 friction = 0.01 # manning's friction coefficient 46 starttime = 0 47 finaltime = 1000 # final time for simulation 48 49 setup = 'trial' # Final can be replaced with trial or basic. 50 # Either will result in a coarser mesh that will allow a 51 # faster, but less accurate, simulation. 52 53 if setup =='trial': 54 print'trial' 55 scale_factor=100 56 time_thinning=96 57 yieldstep=240 58 if setup =='basic': 59 print'basic' 60 scale_factor=4 61 time_thinning=12 62 yieldstep=120 63 if setup =='final': 64 print'final' 65 scale_factor=1 66 time_thinning=4 67 yieldstep=60 68 69 70 #------------------------------------------------------------------------------ 71 # Output Filename 72 #------------------------------------------------------------------------------ 73 # Important to distinguish each run - ensure str(user) is included! 74 # Note, the user is free to include as many parameters as desired 75 output_comment= ('_' + setup + '_' + str(tide)+ '_' + str(event_number) + 76 '_' + str(user)) 77 78 #------------------------------------------------------------------------------ 31 friction=0.01 # manning's friction coefficient 32 starttime=0 # start time for simulation 33 finaltime=1000 # final time for simulation 34 35 setup = 'trial' # This can be one of three values 36 # trial - coarsest mesh, fast 37 # basic - coarse mesh 38 # final - fine mesh, slowest 39 40 #------------------------------------------------------------------------------- 41 # Output filename 42 # 43 # Your output filename should be unique between different runs on different data. 44 # The list of items below will be used to create a file in your output directory. 45 # Your user name and time+date will be automatically added. For example, 46 # [setup, tide, event_number] 47 # will result in a filename like 48 # 20090212_091046_run_final_0_27283_rwilson 49 #------------------------------------------------------------------------------- 50 51 output_comment = [setup, tide, event_number] 52 53 #------------------------------------------------------------------------------- 79 54 # Input Data 80 #------------------------------------------------------------------------------ 55 #------------------------------------------------------------------------------- 56 81 57 # ELEVATION DATA 82 58 # Used in build_elevation.py 83 84 ### Format for ascii grids, as produced in ArcGIS + a projection file 85 ##ascii_grid_filenames = ['grid250m'] # 250m grid 2005 59 # Format for ascii grids, as produced in ArcGIS + a projection file 60 ascii_grid_filenames = [] # Grid data 86 61 87 62 # Format for point is x,y,elevation (with header) 88 point_filenames = ['grid 250m.txt']# 250m grid 200563 point_filenames = ['grid.txt'] # 250m grid 2005 89 64 90 65 # BOUNDING POLYGON - for data clipping and estimate of triangles in mesh … … 92 67 # Format for points easting,northing (no header) 93 68 bounding_polygon_filename = 'bounding_polygon.csv' 69 bounding_polygon_maxarea = 100000 70 71 # INTERIOR REGIONS - for designing the mesh 72 # Used in run_model.py 73 # Format for points easting,northing (no header) 74 interior_regions_data = [] 75 76 # LAND - used to set the initial stage/water to be offcoast only 77 # Used in run_model.py. Format for points easting,northing (no header) 78 land_initial_conditions_filename = [] 94 79 95 80 # GAUGES - for creating timeseries at a specific point 96 # Used in get_timeseries.py 81 # Used in get_timeseries.py. 97 82 # Format easting,northing,name,elevation (with header) 98 ##gauges_filename = 'gauges.csv' 99 100 # BOUNDING POLYGON 101 # used in build_boundary.py and run_model.py respectively 83 gauges_filename = 'gauges.csv' 84 85 # BUILDINGS EXPOSURE - for identifying inundated houses 86 # Used in run_building_inundation.py 87 # Format latitude,longitude etc (geographic) 88 building_exposure_filename = 'busselton_res_clip.csv' # from NEXIS 89 90 # BOUNDING POLYGON - used in build_boundary.py and run_model.py respectively 102 91 # NOTE: when files are put together the points must be in sequence 103 92 # For ease go clockwise! … … 112 101 landward_boundary_filename = 'landward_boundary.csv' 113 102 114 #------------------------------------------------------------------------------ 103 # MUX input filename. 104 # If a meta-file from EventSelection is used, set 'multi-mux' to True. 105 # If a single MUX stem filename (*.grd) is used, set 'multi-mux' to False. 106 ##mux_input_filename = event_number # to be found in event_folder 107 # (ie boundaries/event_number/) 108 ##multi_mux = False 109 mux_input_filename = 'event.list' 110 multi_mux = True 111 112 113 ################################################################################ 114 ################################################################################ 115 #### NOTE: NOTHING WOULD NORMALLY CHANGE BELOW THIS POINT. #### 116 ################################################################################ 117 ################################################################################ 118 119 # Get system user and host names. 120 # These values can be used to distinguish between two similar runs by two 121 # different users or runs by the same user on two different machines. 122 user = get_user_name() 123 host = get_host_name() 124 125 # Environment variable names. 126 # The inundation directory, not the data directory. 127 ENV_INUNDATIONHOME = 'INUNDATIONHOME' 128 129 # Path to MUX data 130 ENV_MUXHOME = 'MUXHOME' 131 132 #------------------------------------------------------------------------------- 115 133 # Output Elevation Data 116 #------------------------------------------------------------------------------ 134 #------------------------------------------------------------------------------- 135 117 136 # Output filename for elevation 118 137 # this is a combination of all the data generated in build_elevation.py 119 combined_elevation_basename = scenario_name + '_combined_elevation _new'120 121 #------------------------------------------------------------------------------ 138 combined_elevation_basename = scenario_name + '_combined_elevation' 139 140 #------------------------------------------------------------------------------- 122 141 # Directory Structure 123 #------------------------------------------------------------------------------ 124 anuga_folder = join(home, state, scenario_name, 'anuga') 142 #------------------------------------------------------------------------------- 143 144 # determines time for setting up output directories 145 time = strftime('%Y%m%d_%H%M%S', localtime()) 146 gtime = strftime('%Y%m%d_%H%M%S', gmtime()) 147 build_time = time + '_build' 148 run_time = time + '_run_' 149 150 # create paths generated from environment variables. 151 home = join(os.getenv(ENV_INUNDATIONHOME), 'data') # Absolute path for data folder 152 muxhome = os.getenv(ENV_MUXHOME) 153 154 # check various directories/files that must exist 155 anuga_folder = join(home, state, scenario_folder, 'anuga') 125 156 topographies_folder = join(anuga_folder, 'topographies') 126 157 polygons_folder = join(anuga_folder, 'polygons') 127 158 boundaries_folder = join(anuga_folder, 'boundaries') 128 159 output_folder = join(anuga_folder, 'outputs') 129 gauges_folder = join(anuga_folder, 'gauges')160 gauges_folder = join(anuga_folder, 'gauges') 130 161 meshes_folder = join(anuga_folder, 'meshes') 131 132 #------------------------------------------------------------------------------ 162 event_folder = join(boundaries_folder, str(event_number)) 163 164 # MUX data files 165 # Directory containing the MUX data files to be used with EventSelection. 166 mux_data_folder = join(muxhome, 'mux') 167 168 #------------------------------------------------------------------------------- 133 169 # Location of input and output data 134 #------------------------------------------------------------------------------ 170 #------------------------------------------------------------------------------- 171 172 # Convert the user output_comment to a string for run_model.py 173 output_comment = ('_'.join([str(x) for x in output_comment if x != user]) 174 + '_' + user) 135 175 136 176 # The absolute pathname of the all elevation, generated in build_elevation.py … … 138 178 139 179 # The absolute pathname of the mesh, generated in run_model.py 140 meshes = join(meshes_folder, scenario_name) + ' new.msh'141 142 # The absolute pathname for the urs order points, used within build_boundary.py180 meshes = join(meshes_folder, scenario_name) + '.msh' 181 182 # The pathname for the urs order points, used within build_urs_boundary.py 143 183 urs_order = join(boundaries_folder, urs_order_filename) 144 184 … … 147 187 landward_boundary = join(boundaries_folder, landward_boundary_filename) 148 188 149 event_folder = join(boundaries_folder, str(event_number))150 151 189 # The absolute pathname for the .sts file, generated in build_boundary.py 152 190 event_sts = join(event_folder, scenario_name) … … 162 200 # The absolute pathname for the gauges file 163 201 # Used for get_timeseries.py 164 ##gauges = join(gauges_folder, gauges_filename) 165 166 #------------------------------------------------------------------------------ 167 # Reading polygons and creating interior regions 168 #------------------------------------------------------------------------------ 169 170 # Initial bounding polygon for data clipping 171 bounding_polygon = read_polygon(join(polygons_folder, 172 bounding_polygon_filename)) 173 bounding_maxarea = 100000*scale_factor 174 175 interior_regions = [] 176 177 # Estimate the number of triangles 178 trigs_min = number_mesh_triangles(interior_regions, 179 bounding_polygon, bounding_maxarea) 180 print 'min estimated number of triangles', trigs_min 181 182 202 gauges = join(gauges_folder, gauges_filename) 203 204 # The absolute pathname for the building file 205 # Used for run_building_inundation.py 206 building_exposure = join(gauges_folder, building_exposure_filename) 207 208 # full path to where MUX files (or meta-files) live 209 mux_input = join(event_folder, mux_input_filename) 210 -
anuga_work/production/australia_ph2/broome/run_model.py
r6340 r6382 22 22 # Standard modules 23 23 import os 24 import os.path 24 25 import time 26 from time import localtime, strftime, gmtime 25 27 26 28 # Related major packages 29 from Scientific.IO.NetCDF import NetCDFFile 30 import Numeric as num 31 27 32 from anuga.interface import create_domain_from_regions 28 33 from anuga.interface import Transmissive_stage_zero_momentum_boundary … … 36 41 from anuga.shallow_water.data_manager import start_screen_catcher 37 42 from anuga.shallow_water.data_manager import copy_code_files 43 from anuga.shallow_water.data_manager import urs2sts 38 44 from anuga.utilities.polygon import read_polygon, Polygon_function 39 45 40 46 # Application specific imports 41 import project # Definition of file names and polygons 47 from setup_model import project 48 import build_urs_boundary as bub 42 49 43 44 #------------------------------------------------------------------------------ 50 #------------------------------------------------------------------------------- 45 51 # Copy scripts to time stamped output directory and capture screen 46 52 # output to file. Copy script must be before screen_catcher 47 #------------------------------------------------------------------------------ 53 #------------------------------------------------------------------------------- 54 48 55 copy_code_files(project.output_run, __file__, 49 os.path. dirname(project.__file__)+os.sep+\50 project.__name__+'.py')56 os.path.join(os.path.dirname(project.__file__), 57 project.__name__+'.py')) 51 58 start_screen_catcher(project.output_run, 0, 1) 52 59 53 54 #------------------------------------------------------------------------------ 60 #------------------------------------------------------------------------------- 55 61 # Create the computational domain based on overall clipping polygon with 56 62 # a tagged boundary and interior regions defined in project.py along with 57 63 # resolutions (maximal area of per triangle) for each polygon 58 #------------------------------------------------------------------------------ 64 #------------------------------------------------------------------------------- 65 59 66 print 'Create computational domain' 67 68 # Create the STS file 69 print 'project.mux_data_folder=%s' % project.mux_data_folder 70 if not os.path.exists(project.event_sts + '.sts'): 71 bub.build_urs_boundary(project.mux_input_filename, project.event_sts) 60 72 61 73 # Read in boundary from ordered sts file … … 70 82 71 83 # Number of boundary segments 72 N = len(event_sts)-1 84 num_ocean_segments = len(event_sts) - 1 85 # Number of landward_boundary points 86 num_land_points = file_length(project.landward_boundary) 73 87 74 # Number of landward_boundary points75 M = file_length(project.landward_boundary)76 77 88 # Boundary tags refer to project.landward_boundary 78 89 # 4 points equals 5 segments start at N 79 boundary_tags={'back': range(N+1, N+M), 80 'side': [N, N+M], 81 'ocean': range(N)} 90 boundary_tags={'back': range(num_ocean_segments+1, 91 num_ocean_segments+num_land_points), 92 'side': [num_ocean_segments, 93 num_ocean_segments+num_land_points], 94 'ocean': range(num_ocean_segments)} 82 95 83 96 # Build mesh and domain … … 95 108 domain.set_minimum_storable_height(0.01) # Don't store depth less than 1cm 96 109 110 #------------------------------------------------------------------------------- 111 # Setup initial conditions 112 #------------------------------------------------------------------------------- 97 113 98 #------------------------------------------------------------------------------99 # Setup initial conditions100 #------------------------------------------------------------------------------101 114 print 'Setup initial conditions' 102 115 103 116 # Set the initial stage in the offcoast region only 104 ##IC = Polygon_function(project.land_initial_conditions, 105 ## default=project.tide, 106 ## geo_reference=domain.geo_reference) 107 domain.set_quantity('stage', 0, use_cache=True, verbose=True) 117 if project.land_initial_conditions: 118 IC = Polygon_function(project.land_initial_conditions, 119 default=project.tide, 120 geo_reference=domain.geo_reference) 121 else: 122 IC = 0 123 domain.set_quantity('stage', IC, use_cache=True, verbose=True) 108 124 domain.set_quantity('friction', project.friction) 109 125 domain.set_quantity('elevation', … … 113 129 alpha=project.alpha) 114 130 131 #------------------------------------------------------------------------------- 132 # Setup boundary conditions 133 #------------------------------------------------------------------------------- 115 134 116 #------------------------------------------------------------------------------117 # Setup boundary conditions118 #------------------------------------------------------------------------------119 135 print 'Set boundary - available tags:', domain.get_boundary_tags() 120 136 121 137 Br = Reflective_boundary(domain) 122 138 Bt = Transmissive_stage_zero_momentum_boundary(domain) 139 Bd = Dirichlet_boundary([project.tide, 0, 0]) 123 140 Bf = Field_boundary(project.event_sts+'.sts', 124 141 domain, mean_stage=project.tide, … … 130 147 131 148 domain.set_boundary({'back': Br, 132 'side': B t,149 'side': Bd, 133 150 'ocean': Bf}) 134 151 152 #------------------------------------------------------------------------------- 153 # Evolve system through time 154 #------------------------------------------------------------------------------- 135 155 136 #------------------------------------------------------------------------------137 # Evolve system through time138 #------------------------------------------------------------------------------139 156 t0 = time.time() 140 157 for t in domain.evolve(yieldstep=project.yieldstep, … … 144 161 print domain.boundary_statistics(tags='ocean') 145 162 146 print 'Simulation took %.2f seconds' % (time.time()-t0)163 print 'Simulation took %.2f seconds' % (time.time()-t0)
Note: See TracChangeset
for help on using the changeset viewer.