Changeset 6308


Ignore:
Timestamp:
Feb 10, 2009, 2:27:54 PM (16 years ago)
Author:
rwilson
Message:

Major fiddle to get this into a more user-friendly form.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_work/production/busselton/standardised_version/project.py

    r6284 r6308  
    1 """Common filenames and locations for elevation, meshes and outputs.
     1"""
     2Common filenames and locations for elevation, meshes and outputs.
    23This script is the heart of all scripts in the folder
    34"""
    4 #------------------------------------------------------------------------------
    5 # Import necessary modules
    6 #------------------------------------------------------------------------------
    7 
     5
     6import sys
    87import os
    9 from os.path import join
    10 from os import sep, getenv
     8from os.path import join, exists
    119from time import localtime, strftime, gmtime
    1210from anuga.utilities.polygon import read_polygon, number_mesh_triangles
    1311from anuga.utilities.system_tools import get_user_name, get_host_name
    1412
    15 #------------------------------------------------------------------------------
    16 # Directory setup
    17 #------------------------------------------------------------------------------
    18 # Note: INUNDATIONHOME is the inundation directory, not the data directory.
    19 
    20 home = getenv('INUNDATIONHOME')+sep+'data'+sep # Absolute path for data folder
    21 muxhome = getenv('MUXHOME')
     13
     14#-----
     15# Get system data - don't fiddle with this.
     16#-----
     17
    2218user = get_user_name()
    2319host = get_host_name()
    2420
    25 # determines time for setting up output directories
    26 time = strftime('%Y%m%d_%H%M%S',localtime())
    27 gtime = strftime('%Y%m%d_%H%M%S',gmtime())
    28 build_time = time+'_build'
    29 run_time = time+'_run'
     21#-------------------------------------------------------------------------------
     22# Directory setup
     23#-------------------------------------------------------------------------------
    3024
    3125# this section needs to be updated to reflect the modelled community.
     
    3529scenario_folder = 'busselton_tsunami_scenario'
    3630
    37 #------------------------------------------------------------------------------
     31#-------------------------------------------------------------------------------
    3832# 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              #0.6
    43 event_number = 27255 # Java 9.3 worst case for Perth
    44 #event_number = 68693 # Sumatra 9.2
    45 #event_number = 27283  # Java 9.3 original
    46 tide = 0                #0.6
    47 #event_number = 27255   # Java 9.3 worst case for Perth
    48 #event_number = 68693   # Sumatra 9.2
    49 event_number = 27283    # Java 9.3 original
     33#-------------------------------------------------------------------------------
     34
     35# Model specific parameters.
     36# One or all can be changed each time the run_model script is executed
     37tide = 0                # ??
     38event_number = 27283    # the event number
    5039alpha = 0.1             # smoothing parameter for mesh
    5140friction=0.01           # manning's friction coefficient
    52 starttime=0             
     41starttime=0             # start time for simulation
    5342finaltime=80000         # final time for simulation
    5443
    55 setup='final'  # Final can be replaced with trial or basic.
    56                # Either will result in a coarser mesh that will allow a
    57                # faster, but less accurate, simulation.
    58 
    59 if setup =='trial':
    60     print'trial'
    61     scale_factor=100
    62     time_thinning=96
    63     yieldstep=240
    64 if setup =='basic':
    65     print'basic'
    66     scale_factor=4
    67     time_thinning=12
    68     yieldstep=120
    69 if setup =='final':
    70     print'final'
    71     scale_factor=1
    72     time_thinning=4
    73     yieldstep=60
    74 
    75 
    76 #------------------------------------------------------------------------------
     44setup = 'final'  # Final can be replaced with trial or basic.
     45                 # Either will result in a coarser mesh that will
     46                 # allow a faster, but less accurate, simulation.
     47
     48#-------------------------------------------------------------------------------
    7749# Output Filename
    78 #------------------------------------------------------------------------------
     50#-------------------------------------------------------------------------------
     51
    7952# Important to distinguish each run - ensure str(user) is included!
    8053# Note, the user is free to include as many parameters as desired
    81 output_comment= ('_' + setup + '_' + str(tide)+ '_' + str(event_number) +
    82                  '_' + str(user))
    83 
    84 #------------------------------------------------------------------------------
     54output_comment = '_'.join([setup, str(tide), str(event_number), str(user)])
     55
     56#-------------------------------------------------------------------------------
    8557# Input Data
    86 #------------------------------------------------------------------------------
     58#-------------------------------------------------------------------------------
     59
    8760# ELEVATION DATA
    8861# Used in build_elevation.py
     
    9265
    9366# Format for point is x,y,elevation (with header)
    94 point_filenames = ['Busselton_Contour0.txt',     # Coastline
    95                    'Busselton_BeachSurvey.txt',    # Beach survey
    96                    'Busselton_NavyFinal.txt',  # Bathymetry
    97                    'Busselton_Chart.txt', # Bathymetry Charts
    98                    'Busselton_Digitised.txt', # Digitised Fairsheet
    99                    'Busselton_250m.txt', # 250m
    100                    'Bunbury_TIN.txt', # Bunbury aoi TIN'd in ArcGIS
    101                    'Busselton_TIN.txt', # Busselton aoi TIN'd in ArcGIS
    102                    'XYAHD_clip.txt'] # To extend boundary
    103 
    104 
    105 # LAND - used to set the initial stage/water to be offcoast only
    106 # Used in run_model,py
    107 # Format for points easting,northing (no header)
    108 land_initial_conditions_filename = [['initial_condition_extend.csv', 0],
    109                                     ['initial_condition_marina.csv', 0]]
     67point_filenames = ['Busselton_Contour0.txt',    # Coastline
     68                   'Busselton_BeachSurvey.txt', # Beach survey
     69                   'Busselton_NavyFinal.txt',   # Bathymetry
     70                   'Busselton_Chart.txt',       # Bathymetry Charts
     71                   'Busselton_Digitised.txt',   # Digitised Fairsheet
     72                   'Busselton_250m.txt',        # 250m
     73                   'Bunbury_TIN.txt',           # Bunbury aoi TIN'd in ArcGIS
     74                   'Busselton_TIN.txt',         # Busselton aoi TIN'd in ArcGIS
     75                   'XYAHD_clip.txt']            # To extend boundary
    11076
    11177# BOUNDING POLYGON - for data clipping and estimate of triangles in mesh
     
    12591                         ['coast_5km_d20m.csv', 40000]]
    12692
     93# LAND - used to set the initial stage/water to be offcoast only
     94# Used in run_model.py.  Format for points easting,northing (no header)
     95land_initial_conditions_filename = [['initial_condition_extend.csv', 0],
     96                                    ['initial_condition_marina.csv', 0]]
     97
    12798# GAUGES - for creating timeseries at a specific point
    128 # Used in get_timeseries.py
     99# Used in get_timeseries.py
    129100# Format easting,northing,name,elevation (with header)
    130101gauges_filename = 'gauges.csv'
     
    135106building_exposure_filename = 'busselton_res_clip.csv' #from NEXIS
    136107
    137 # BOUNDING POLYGON
    138 # used in build_boundary.py and run_model.py respectively
     108# BOUNDING POLYGON - used in build_boundary.py and run_model.py respectively
    139109# NOTE: when files are put together the points must be in sequence
    140110# For ease go clockwise!
     
    149119landward_boundary_filename = 'landward_boundary_extend.csv'
    150120
    151 #------------------------------------------------------------------------------
     121# MUX input filename
     122# Must exist in $MUXHOME/mux directory.
     123# If MUX file not used, do "mux_input_file = None".
     124mux_input_file = 'event_031451.list'          # File produced by EventSelection
     125
     126#-------------------------------------------------------------------------------
    152127# Clipping regions for export to asc and regions for clipping data
    153128# Final inundation maps should only be created in regions of the finest mesh
    154 #------------------------------------------------------------------------------
     129#-------------------------------------------------------------------------------
    155130
    156131# ASCII export grid for Busselton
     
    167142
    168143
    169 #------------------------------------------------------------------------------
     144################################################################################
     145################################################################################
     146####             NOTE: NOTHING SHOULD CHANGE BELOW THIS POINT.              ####
     147################################################################################
     148################################################################################
     149
     150#-------------------------------------------------------------------------------
     151# Sanity checks
     152#-------------------------------------------------------------------------------
     153
     154# Test that environment variables are defined.
     155# A little late, but better here than up in user-changeable data.
     156
     157# Environment variable names.
     158# The inundation directory, not the data directory.
     159ENV_INUNDATIONHOME = 'INUNDATIONHOME'
     160
     161# Path to MUX data
     162ENV_MUXHOME = 'MUXHOME'
     163
     164# Check we have required environment variables set
     165sanity_error = False               # checked at bottom of this file
     166
     167if os.getenv(ENV_INUNDATIONHOME) is None:
     168    print "Environment variable '%s' is not set" % ENV_INUNDATIONHOME
     169    sanity_error = True
     170
     171if os.getenv(ENV_MUXHOME) is None:
     172    print "Environment variable '%s' is not set" % ENV_MUXHOME
     173    sanity_error = True
     174
     175# check for errors detected so far
     176if sanity_error:
     177    print 'You must fix the above errors before continuing.'
     178    sys.exit(10)
     179
     180#-------------------------------------------------------------------------------
    170181# Output Elevation Data
    171 #------------------------------------------------------------------------------
     182#-------------------------------------------------------------------------------
     183
    172184# Output filename for elevation
    173185# this is a combination of all the data generated in build_elevation.py
    174186combined_elevation_basename = scenario_name + '_combined_elevation'
    175187
    176 #------------------------------------------------------------------------------
     188#-------------------------------------------------------------------------------
    177189# Directory Structure
    178 #------------------------------------------------------------------------------
     190#-------------------------------------------------------------------------------
     191
     192# determines time for setting up output directories
     193time = strftime('%Y%m%d_%H%M%S', localtime())
     194gtime = strftime('%Y%m%d_%H%M%S', gmtime())
     195build_time = time + '_build'
     196run_time = time + '_run'
     197
     198# create paths generated from environment variables.
     199home = join(os.getenv(ENV_INUNDATIONHOME), 'data') # Absolute path for data folder
     200if not exists(home):
     201    print "Sorry, data directory '%s' doesn't exist" % home
     202    sanity_error = True
     203   
     204muxhome = os.getenv(ENV_MUXHOME)
     205if not exists(muxhome):
     206    print "Sorry, MUX directory '%s' doesn't exist" % muxhome
     207    sanity_error = True
     208   
     209# if mux_input_file has been defined, check if file exists
     210if mux_input_file:
     211    if not exists(join(muxhome, mux_input_file)):
     212        print ("Sorry, MUX input file '%s' doesn't exist"
     213               % join(muxhome, mux_input_file))
     214        sanity_error = True
     215
     216# check various directories that must exist
    179217anuga_folder = join(home, state, scenario_folder, 'anuga')
     218if not exists(anuga_folder):
     219    print "Sorry, ANUGA directory '%s' doesn't exist" % anuga_folder
     220    sanity_error = True
     221
    180222topographies_folder = join(anuga_folder, 'topographies')
     223if not exists(topographies_folder):
     224    print "Sorry, topo directory '%s' doesn't exist" % topographies_folder
     225    sanity_error = True
     226
    181227polygons_folder = join(anuga_folder, 'polygons')
     228if not exists(polygons_folder):
     229    print "Sorry, polygon directory '%s' doesn't exist" % polygons_folder
     230    sanity_error = True
     231
    182232boundaries_folder = join(anuga_folder, 'boundaries')
     233if not exists(boundaries_folder):
     234    print "Sorry, boundaries directory '%s' doesn't exist" % boundaries_folder
     235    sanity_error = True
     236
    183237output_folder = join(anuga_folder, 'outputs')
    184 gauges_folder = join(anuga_folder,'gauges')
     238if not exists(output_folder):
     239    print "Sorry, outputs directory '%s' doesn't exist" % output_folder
     240    sanity_error = True
     241
     242gauges_folder = join(anuga_folder, 'gauges')
     243if not exists(gauges_folder):
     244    print "Sorry, gauges directory '%s' doesn't exist" % gauges_folder
     245    sanity_error = True
     246
    185247meshes_folder = join(anuga_folder, 'meshes')
    186 
    187 #------------------------------------------------------------------------------
     248if not exists(meshes_folder):
     249    print "Sorry, meshes directory '%s' doesn't exist" % meshes_folder
     250    sanity_error = True
     251
     252
     253#-------------------------------------------------------------------------------
    188254# Location of input and output data
    189 #------------------------------------------------------------------------------
     255#-------------------------------------------------------------------------------
    190256
    191257# The absolute pathname of the all elevation, generated in build_elevation.py
    192258combined_elevation = join(topographies_folder, combined_elevation_basename)
    193 
    194259
    195260# The absolute pathname of the mesh, generated in run_model.py
     
    222287building_exposure = join(gauges_folder, building_exposure_filename)
    223288
    224 #------------------------------------------------------------------------------
     289#-------------------------------------------------------------------------------
     290# Determine type of run
     291#-------------------------------------------------------------------------------
     292
     293if setup == 'trial':
     294    print 'trial'
     295    scale_factor = 100
     296    time_thinning = 96
     297    yieldstep = 240
     298elif setup == 'basic':
     299    print 'basic'
     300    scale_factor = 4
     301    time_thinning = 12
     302    yieldstep = 120
     303elif setup == 'final':
     304    print 'final'
     305    scale_factor = 1
     306    time_thinning = 4
     307    yieldstep = 60
     308else:
     309    print ("Sorry, you must set the 'setup' variable to one of 'trial', "
     310           "'basic' or 'final'. I found '%s'" % str(setup))
     311    sanity_error = True
     312
     313#-------------------------------------------------------------------------------
    225314# Reading polygons and creating interior regions
    226 #------------------------------------------------------------------------------
     315#-------------------------------------------------------------------------------
    227316
    228317# Create list of land polygons with initial conditions
     
    246335trigs_min = number_mesh_triangles(interior_regions,
    247336                                  bounding_polygon, bounding_maxarea)
     337
     338#-------------------------------------------------------------------------------
     339# Check for errors detected above.
     340#-------------------------------------------------------------------------------
     341
     342if sanity_error:
     343    print 'You must fix the above errors before continuing.'
     344    sys.exit(10)
     345
     346
    248347print 'min estimated number of triangles', trigs_min
    249    
    250 
Note: See TracChangeset for help on using the changeset viewer.