Changeset 6369
- Timestamp:
- Feb 19, 2009, 2:01:10 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_work/production/busselton/standardised_version/run_model.py
r6368 r6369 46 46 # Application specific imports 47 47 from 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,:]) 48 import build_urs_boundary as bub 139 49 140 50 #------------------------------------------------------------------------------- … … 158 68 # Create the STS file 159 69 print '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)) 70 if not os.path.exists(project.event_sts + '.sts'): 71 bub.build_urs_boundary(project.mux_input_filename, project.event_sts) 163 72 164 73 # Read in boundary from ordered sts file … … 206 115 207 116 # 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) 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 omain.set_quantity('stage', IC, use_cache=True, verbose=True) 212 124 domain.set_quantity('friction', project.friction) 213 125 domain.set_quantity('elevation', … … 225 137 Br = Reflective_boundary(domain) 226 138 Bt = Transmissive_stage_zero_momentum_boundary(domain) 227 Bd = Dirichlet_boundary([ kwargs['tide'], 0, 0])139 Bd = Dirichlet_boundary([project.tide, 0, 0]) 228 140 Bf = Field_boundary(project.event_sts+'.sts', 229 141 domain, mean_stage=project.tide, … … 235 147 236 148 domain.set_boundary({'back': Br, 237 'side': B t,149 'side': Bd, 238 150 'ocean': Bf}) 239 151
Note: See TracChangeset
for help on using the changeset viewer.