Changeset 6369


Ignore:
Timestamp:
Feb 19, 2009, 2:01:10 PM (15 years ago)
Author:
kristy
Message:

added if statements for build_boundary and Initial conditions.

File:
1 edited

Legend:

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

    r6368 r6369  
    4646# Application specific imports
    4747from setup_model import project
    48 
    49 
    50 
    51 ##
    52 # @brief Build boundary STS files from one or more MUX files.
    53 # @param mux_dir Directory containing the MUX files.
    54 # @param event_file Path to meta-file containing mux files+weight data.
    55 # @param output_dir Directory to write STS data to.
    56 # @note 'event_file' is produced by EventSelection.
    57 def build_urs_boundary(mux_dir, event_file, output_dir):
    58     '''Build a boundary STS file from a set of MUX files.'''
    59 
    60     print 'build_urs_boundary: mux_dir=%s' % mux_dir
    61     print 'build_urs_boundary: event_file=%s' % event_file
    62     print 'build_urs_boundary: output_dir=%s' % output_dir
    63 
    64     # if we are using an EventSelection multi-mux file
    65     if project.multi_mux:   
    66         # get the mux+weight data from the event file
    67         mux_event_file = os.path.join(mux_dir, event_file)
    68         try:
    69             fd = open(mux_event_file, 'r')
    70             mux_data = fd.readlines()
    71             fd.close()
    72         except IOError, e:
    73             msg = 'File %s cannot be read: %s' % (mux_event_file, str(e))
    74             raise Exception, msg
    75         except:
    76             raise
    77 
    78         # first line of file is # filenames+weight in rest of file
    79         num_lines = int(mux_data[0].strip())
    80         mux_data = mux_data[1:]
    81         print 'number of sources %d' % num_lines
    82 
    83         # quick sanity check on input mux meta-file
    84         if num_lines != len(mux_data):
    85             msg = ('Bad file %s: %d data lines, but line 1 count is %d'
    86                    % (event_file, len(mux_data), num_lines))
    87             raise Exception, msg
    88 
    89         # Create filename and weights lists.
    90         # Must chop GRD filename just after '*.grd'.
    91         mux_filenames = []
    92         for line in mux_data:
    93             muxname = line.strip().split()[0]
    94             split_index = muxname.index('.grd')
    95             muxname = muxname[:split_index+len('.grd')]
    96             muxname = os.path.join(mux_dir, muxname)
    97             mux_filenames.append(muxname)
    98        
    99         mux_weights = [float(line.strip().split()[1]) for line in mux_data]
    100 
    101         # Call legacy function to create STS file.
    102         # This should be replaced in the future.
    103         print 'reading', project.urs_order
    104         print 'creating STS file'
    105         print 'mux_filenames=%s' % str(mux_filenames)
    106         print 'basename_out=%s' % str(output_dir)
    107         print 'ordering_filename=%s' % str(project.urs_order)
    108         print 'weights=%s' % str(mux_weights)
    109         print 'mean_stage=%s' % str(project.tide)
    110         urs2sts(mux_filenames,
    111                 basename_out=output_dir,
    112                 ordering_filename=project.urs_order,
    113                 weights=mux_weights,
    114                 mean_stage=project.tide,
    115                 verbose=True)
    116     else:                           # a single mux stem file
    117         urs_filenames = [os.path.join(mux_dir, event_file)]
    118 
    119         weight_factor = 1.0
    120         weights = weight_factor*num.ones(len(urs_filenames), num.float)
    121            
    122         order_filename = os.path.join(project.order_filename_dir)
    123 
    124         print 'reading', order_filename
    125         # Create ordered sts file
    126         print 'creating sts file'
    127         urs2sts(urs_filenames,
    128                 basename_out=os.path.join(project.boundaries_dir,
    129                                           project.scenario_name),
    130                 ordering_filename=order_filename,
    131                 weights=weights,
    132                 mean_stage=project.tide,
    133                 verbose=True)
    134 
    135     # report on stuff so far
    136     quantities, elevation, time = get_sts_gauge_data(project.event_folder,
    137                                                      verbose=False)
    138     print len(elevation), len(quantities['stage'][0,:])
     48import build_urs_boundary as bub
    13949
    14050#-------------------------------------------------------------------------------
     
    15868# Create the STS file
    15969print 'project.mux_data_folder=%s' % project.mux_data_folder
    160 bub.build_urs_boundary(project.mux_input_filename,
    161                        os.path.join(project.event_folder,
    162                                     project.scenario_name))
     70if not os.path.exists(project.event_sts + '.sts'):
     71    bub.build_urs_boundary(project.mux_input_filename, project.event_sts)
    16372
    16473# Read in boundary from ordered sts file
     
    206115
    207116# Set the initial stage in the offcoast region only
    208 IC = Polygon_function(project.land_initial_conditions,
    209                       default=project.tide,
    210                       geo_reference=domain.geo_reference)
    211 domain.set_quantity('stage', IC, use_cache=True, verbose=True)
     117if project.land_initial_conditions:
     118    IC = Polygon_function(project.land_initial_conditions,
     119                          default=project.tide,
     120                          geo_reference=domain.geo_reference)
     121else:
     122    IC = 0
     123omain.set_quantity('stage', IC, use_cache=True, verbose=True)
    212124domain.set_quantity('friction', project.friction)
    213125domain.set_quantity('elevation',
     
    225137Br = Reflective_boundary(domain)
    226138Bt = Transmissive_stage_zero_momentum_boundary(domain)
    227 Bd = Dirichlet_boundary([kwargs['tide'], 0, 0])
     139Bd = Dirichlet_boundary([project.tide, 0, 0])
    228140Bf = Field_boundary(project.event_sts+'.sts',
    229141                    domain, mean_stage=project.tide,
     
    235147
    236148domain.set_boundary({'back': Br,
    237                      'side': Bt,
     149                     'side': Bd,
    238150                     'ocean': Bf})
    239151
Note: See TracChangeset for help on using the changeset viewer.