Changeset 6086 for anuga_core/source/anuga/shallow_water/data_manager.py
- Timestamp:
- Dec 19, 2008, 10:38:08 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/shallow_water/data_manager.py
r6080 r6086 78 78 from anuga.config import minimum_storable_height as \ 79 79 default_minimum_storable_height 80 from anuga.config import netcdf_mode_r, netcdf_mode_w, netcdf_mode_a 80 81 from anuga.config import max_float 81 82 from anuga.utilities.numerical_tools import ensure_numeric, mean … … 300 301 # @param extension 301 302 # @param mode The mode of the underlying file. 302 def __init__(self, domain, extension, mode= 'w'):303 assert mode in ['r', 'w', 'a'], \303 def __init__(self, domain, extension, mode=netcdf_mode_w): 304 assert mode[0] in ['r', 'w', 'a'], \ 304 305 "Mode %s must be either:\n" % mode + \ 305 306 " 'w' (write)\n" + \ … … 341 342 # @param max_size ?? 342 343 # @param recursion ?? 343 # @note Prepare the unde lying data file if mode is'w'.344 def __init__(self, domain, mode= 'w', max_size=2000000000, recursion=False):344 # @note Prepare the underlying data file if mode starts with 'w'. 345 def __init__(self, domain, mode=netcdf_mode_w, max_size=2000000000, recursion=False): 345 346 from Scientific.IO.NetCDF import NetCDFFile 346 347 from Numeric import Int, Float, Float32 … … 363 364 # NetCDF file definition 364 365 fid = NetCDFFile(self.filename, mode) 365 if mode == 'w':366 if mode[0] == 'w': 366 367 description = 'Output from anuga.abstract_2d_finite_volumes ' \ 367 368 'suitable for plotting' … … 429 430 430 431 # append to the NetCDF file 431 fid = NetCDFFile(self.filename, 'a')432 433 # Get the variables434 x = fid.variables['x']435 y = fid.variables['y']436 z = fid.variables['elevation']437 volumes = fid.variables['volumes']432 fid = NetCDFFile(self.filename, netcdf_mode_a) 433 434 # # Get the variables 435 # x = fid.variables['x'] 436 # y = fid.variables['y'] 437 # z = fid.variables['elevation'] 438 # volumes = fid.variables['volumes'] 438 439 439 440 # Get X, Y and bed elevation Z … … 445 446 self.writer.store_triangulation(fid, 446 447 points, 447 V.astype(volumes.typecode()), 448 # V.astype(volumes.typecode()), 449 V.astype(Float32), 448 450 Z, 449 451 points_georeference=\ … … 475 477 while not file_open and retries < 10: 476 478 try: 477 fid = NetCDFFile(self.filename, 'a') # Open existing file479 fid = NetCDFFile(self.filename, netcdf_mode_a) # Open existing file 478 480 except IOError: 479 481 # This could happen if someone was reading the file. … … 623 625 # @param domain ?? 624 626 # @param mode Mode of underlying data file (default WRITE). 625 def __init__(self, domain, mode= 'w'):627 def __init__(self, domain, mode=netcdf_mode_w): 626 628 from Scientific.IO.NetCDF import NetCDFFile 627 629 from Numeric import Int, Float, Float … … 633 635 # NetCDF file definition 634 636 fid = NetCDFFile(self.filename, mode) 635 if mode == 'w':637 if mode[0] == 'w': 636 638 #Create new file 637 639 fid.institution = 'Geoscience Australia' … … 683 685 684 686 #Get NetCDF 685 fid = NetCDFFile(self.filename, 'a')687 fid = NetCDFFile(self.filename, netcdf_mode_a) 686 688 687 689 # Get the variables … … 718 720 while not file_open and retries < 10: 719 721 try: 720 fid = NetCDFFile(self.filename, 'a')722 fid = NetCDFFile(self.filename, netcdf_mode_a) 721 723 except IOError: 722 724 #This could happen if someone was reading the file. … … 1134 1136 FN = create_filename('.', basefilename, 'sww', size) 1135 1137 print 'Reading from ', FN 1136 fid = NetCDFFile(FN, 'r') #Open existing file for read1138 fid = NetCDFFile(FN, netcdf_mode_r) #Open existing file for read 1137 1139 1138 1140 # Get the variables … … 1257 1259 1258 1260 # Get NetCDF 1259 infile = NetCDFFile(filename1, 'r') #Open existing file for read1260 outfile = NetCDFFile(filename2, 'w') #Open new file1261 infile = NetCDFFile(filename1, netcdf_mode_r) #Open existing file for read 1262 outfile = NetCDFFile(filename2, netcdf_mode_w) #Open new file 1261 1263 1262 1264 # Copy dimensions … … 1303 1305 # @return A class instance of required domain and mode. 1304 1306 #Get data objects 1305 def get_dataobject(domain, mode= 'w'):1307 def get_dataobject(domain, mode=netcdf_mode_w): 1306 1308 """Return instance of class of given format using filename 1307 1309 """ … … 1389 1391 1390 1392 # Get NetCDF 1391 infile = NetCDFFile(root + '.dem', 'r')1393 infile = NetCDFFile(root + '.dem', netcdf_mode_r) 1392 1394 1393 1395 if verbose: print 'Reading DEM from %s' %(root + '.dem') … … 1419 1421 1420 1422 # NetCDF file definition 1421 outfile = NetCDFFile(ptsname, 'w')1423 outfile = NetCDFFile(ptsname, netcdf_mode_w) 1422 1424 1423 1425 # Create new file … … 2700 2702 2701 2703 # NetCDF file definition 2702 fid = NetCDFFile(netcdfname, 'w')2704 fid = NetCDFFile(netcdfname, netcdf_mode_w) 2703 2705 2704 2706 #Create new file … … 2829 2831 if verbose: print 'Reading files %s_*.nc' % basename_in 2830 2832 2831 file_h = NetCDFFile(basename_in + '_ha.nc', 'r') # Wave amplitude (cm)2832 file_u = NetCDFFile(basename_in + '_ua.nc', 'r') # Velocity (x) (cm/s)2833 file_v = NetCDFFile(basename_in + '_va.nc', 'r') # Velocity (y) (cm/s)2834 file_e = NetCDFFile(basename_in + '_e.nc', 'r') # Elevation (z) (m)2833 file_h = NetCDFFile(basename_in + '_ha.nc', netcdf_mode_r) # Wave amplitude (cm) 2834 file_u = NetCDFFile(basename_in + '_ua.nc', netcdf_mode_r) # Velocity (x) (cm/s) 2835 file_v = NetCDFFile(basename_in + '_va.nc', netcdf_mode_r) # Velocity (y) (cm/s) 2836 file_e = NetCDFFile(basename_in + '_e.nc', netcdf_mode_r) # Elevation (z) (m) 2835 2837 2836 2838 if basename_out is None: … … 3033 3035 3034 3036 # NetCDF file definition 3035 outfile = NetCDFFile(swwname, 'w')3037 outfile = NetCDFFile(swwname, netcdf_mode_w) 3036 3038 3037 3039 description = 'Converted from Ferret files: %s, %s, %s, %s' \ … … 3263 3265 from Scientific.IO.NetCDF import NetCDFFile 3264 3266 3265 fid = NetCDFFile(filename + '.tms', 'w')3267 fid = NetCDFFile(filename + '.tms', netcdf_mode_w) 3266 3268 3267 3269 fid.institution = 'Geoscience Australia' … … 3312 3314 3313 3315 #Get NetCDF 3314 fid = NetCDFFile(file_name, 'r')3316 fid = NetCDFFile(file_name, netcdf_mode_r) 3315 3317 3316 3318 # Get the variables … … 3355 3357 if verbose: print 'Reading from ', filename 3356 3358 3357 fid = NetCDFFile(filename, 'r') # Open existing file for read3359 fid = NetCDFFile(filename, netcdf_mode_r) # Open existing file for read 3358 3360 time = fid.variables['time'] # Timesteps 3359 3361 if t is None: … … 3647 3649 3648 3650 #Open existing netcdf file to read 3649 infile = NetCDFFile(inname, 'r')3651 infile = NetCDFFile(inname, netcdf_mode_r) 3650 3652 3651 3653 if verbose: print 'Reading DEM from %s' % inname … … 3684 3686 3685 3687 #Open netcdf file for output 3686 outfile = NetCDFFile(outname, 'w')3688 outfile = NetCDFFile(outname, netcdf_mode_w) 3687 3689 3688 3690 #Create new file … … 3925 3927 3926 3928 # NetCDF file definition 3927 outfile = NetCDFFile(sww_file, 'w')3929 outfile = NetCDFFile(sww_file, netcdf_mode_w) 3928 3930 3929 3931 #Create new file … … 4276 4278 4277 4279 # NetCDF file definition 4278 self.outfile = NetCDFFile(file_name, 'w')4280 self.outfile = NetCDFFile(file_name, netcdf_mode_w) 4279 4281 outfile = self.outfile 4280 4282 … … 4557 4559 4558 4560 # NetCDF file definition 4559 outfile = NetCDFFile(file_out, 'w')4561 outfile = NetCDFFile(file_out, netcdf_mode_w) 4560 4562 4561 4563 #Create new file … … 5136 5138 if verbose: print 'Output to ', swwname 5137 5139 5138 outfile = NetCDFFile(swwname, 'w')5140 outfile = NetCDFFile(swwname, netcdf_mode_w) 5139 5141 5140 5142 # For a different way of doing this, check out tsh2sww … … 5528 5530 5529 5531 # NetCDF file definition 5530 outfile = NetCDFFile(stsname, 'w')5532 outfile = NetCDFFile(stsname, netcdf_mode_w) 5531 5533 5532 5534 description = 'Converted from URS mux2 files: %s' % basename_in … … 5628 5630 5629 5631 try: 5630 fid = NetCDFFile(stsname + '.sts', 'r')5632 fid = NetCDFFile(stsname + '.sts', netcdf_mode_r) 5631 5633 except: 5632 5634 msg = 'Cannot open %s' % stsname + '.sts' … … 6718 6720 if verbose: print 'Reading from ', filename 6719 6721 6720 fid = NetCDFFile(filename, 'r') # Open existing file for read6722 fid = NetCDFFile(filename, netcdf_mode_r) # Open existing file for read 6721 6723 time = fid.variables['time'][:] # Time vector 6722 6724 time += fid.starttime[0]
Note: See TracChangeset
for help on using the changeset viewer.