Changeset 7814 for trunk/anuga_core/source/anuga/file_conversion/sww2dem.py
- Timestamp:
- Jun 9, 2010, 12:28:24 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_core/source/anuga/file_conversion/sww2dem.py
r7796 r7814 29 29 DEFAULT_BLOCK_SIZE = 10000 30 30 31 def sww2dem( basename_in, basename_out=None,31 def sww2dem(name_in, name_out, 32 32 quantity=None, # defaults to elevation 33 33 reduction=None, … … 42 42 origin=None, 43 43 datum='WGS84', 44 format='ers',45 44 block_size=None): 46 45 """Read SWW file and convert to Digitial Elevation model format … … 98 97 apply_expression_to_dictionary 99 98 100 msg = 'Format must be either asc or ers' 101 assert format.lower() in ['asc', 'ers'], msg 99 basename_in, in_ext = os.path.splitext(name_in) 100 basename_out, out_ext = os.path.splitext(name_out) 101 out_ext = out_ext.lower() 102 103 if in_ext != '.sww': 104 raise IOError('Input format for %s must be .sww' % name_in) 105 106 if out_ext not in ['.asc', '.ers']: 107 raise IOError('Format for %s must be either asc or ers.' % name_out) 102 108 103 109 false_easting = 500000 … … 110 116 reduction = max 111 117 112 if basename_out is None:113 basename_out = basename_in + '_%s' % quantity114 115 118 if quantity_formula.has_key(quantity): 116 119 quantity = quantity_formula[quantity] … … 122 125 block_size = DEFAULT_BLOCK_SIZE 123 126 124 # Read SWW file125 swwfile = basename_in + '.sww'126 demfile = basename_out + '.' + format127 128 127 # Read sww file 129 128 if verbose: 130 log.critical('Reading from %s' % swwfile)131 log.critical('Output directory is %s' % basename_out)129 log.critical('Reading from %s' % name_in) 130 log.critical('Output directory is %s' % name_out) 132 131 133 132 from Scientific.IO.NetCDF import NetCDFFile 134 fid = NetCDFFile( swwfile)133 fid = NetCDFFile(name_in) 135 134 136 135 #Get extent and reference … … 168 167 log.critical('------------------------------------------------') 169 168 log.critical('Statistics of SWW file:') 170 log.critical(' Name: %s' % swwfile)169 log.critical(' Name: %s' % name_in) 171 170 log.critical(' Reference:') 172 171 log.critical(' Lower left corner: [%f, %f]' % (xllcorner, yllcorner)) … … 212 211 if missing_vars: 213 212 msg = ("In expression '%s', variables %s are not in the SWW file '%s'" 214 % (quantity, swwfile))213 % (quantity, name_in)) 215 214 raise Exception, msg 216 215 … … 300 299 301 300 for i in xrange(nrows): 302 if format.lower() == 'asc':301 if out_ext == '.asc': 303 302 yg = i * cellsize 304 303 else: … … 336 335 grid_values[i] = NODATA_value 337 336 338 if format.lower() == 'ers':337 if out_ext == '.ers': 339 338 # setup ERS header information 340 339 grid_values = num.reshape(grid_values, (nrows, ncols)) … … 362 361 import ermapper_grids 363 362 364 ermapper_grids.write_ermapper_grid( demfile, grid_values, header)363 ermapper_grids.write_ermapper_grid(name_out, grid_values, header) 365 364 366 365 fid.close() … … 383 382 prjid.close() 384 383 385 if verbose: log.critical('Writing %s' % demfile)386 387 ascid = open( demfile, 'w')384 if verbose: log.critical('Writing %s' % name_out) 385 386 ascid = open(name_out, 'w') 388 387 389 388 ascid.write('ncols %d\n' %ncols) … … 440 439 See sww2dem to find out what most of the parameters do. 441 440 441 basename_in is a path to sww file/s, without the .sww extension. 442 442 443 Quantities is a list of quantities. Each quantity will be 443 444 calculated for each sww file. … … 473 474 basename_out = sww_file + '_' + quantity + '_' + extra_name_out 474 475 475 file_out = sww2dem(dir+os.sep+sww_file, dir+os.sep+basename_out, 476 file_out = sww2dem(dir+os.sep+sww_file+'.sww', 477 dir+os.sep+basename_out, 476 478 quantity, 477 479 reduction,
Note: See TracChangeset
for help on using the changeset viewer.