Changeset 7340 for anuga_core/source/anuga/shallow_water/data_manager.py
- Timestamp:
- Aug 8, 2009, 2:19:58 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/shallow_water/data_manager.py
r7339 r7340 329 329 ## 330 330 # @brief Class for storing output to e.g. visualisation 331 class Data_format_sww(Data_format):331 class SWW_file(Data_format): 332 332 """Interface to native NetCDF format (.sww) for storing model output 333 333 … … 434 434 fid = NetCDFFile(self.filename, netcdf_mode_a) 435 435 436 # # Get the variables437 # x = fid.variables['x']438 # y = fid.variables['y']439 # z = fid.variables['elevation']440 # volumes = fid.variables['volumes']441 442 436 # Get X, Y and bed elevation Z 443 437 Q = domain.quantities['elevation'] … … 456 450 457 451 ## 458 # @brief Store time and named quantities to the underlying data file. 459 # @param names The names of the quantities to store. 460 # @note If 'names' not supplied, store a standard set of quantities. 452 # @brief Store time and time dependent quantities 453 # to the underlying data file. 461 454 def store_timestep(self, names=None): 462 """Store time and named quantities to file455 """Store time and time dependent quantities 463 456 """ 464 457 … … 468 461 from os import stat 469 462 470 if names is None: 471 # Standard shallow water wave equation quantitites in ANUGA 472 names = ['stage', 'xmomentum', 'ymomentum'] 463 # Get names of quantities to be stored every time step 464 names = self.writer.dynamic_quantities 473 465 474 466 # Get NetCDF … … 521 513 522 514 # Build a new data_structure. 523 next_data_structure = Data_format_sww(self.domain, mode=self.mode,515 next_data_structure = SWW_file(self.domain, mode=self.mode, 524 516 max_size=self.max_size, 525 517 recursion=self.recursion+1) … … 618 610 ## 619 611 # @brief Class for handling checkpoints data 620 class Data_format_cpt(Data_format): 621 """Interface to native NetCDF format (.cpt) 612 # @note This is not operational at the moment 613 class CPT_file(Data_format): 614 """Interface to native NetCDF format (.cpt) to be 615 used for checkpointing (one day) 622 616 """ 623 617 … … 705 699 706 700 ## 707 # @brief Store ti emand named quantities to underlying data file.701 # @brief Store time and named quantities to underlying data file. 708 702 # @param name 709 703 def store_timestep(self, name): … … 1464 1458 infile.close() 1465 1459 outfile.close() 1466 1467 1468 ##1469 # @brief Return instance of class of given format using filename.1470 # @param domain Data domain (eg, 'sww', etc).1471 # @param mode The mode to open domain in.1472 # @return A class instance of required domain and mode.1473 #Get data objects1474 def get_dataobject(domain, mode=netcdf_mode_w):1475 """Return instance of class of given format using filename1476 """1477 1478 cls = eval('Data_format_%s' % domain.format)1479 return cls(domain, mode)1480 1460 1481 1461 … … 3987 3967 domain.format)) 3988 3968 3989 sww = get_dataobject(domain)3969 sww = SWW_file(domain) 3990 3970 sww.store_connectivity() 3991 3971 sww.store_timestep() … … 5323 5303 volumes = mesh_dic['generatedtrianglelist'] 5324 5304 5325 # write sww intro and grid stuff.5305 # Write sww intro and grid stuff. 5326 5306 if basename_out is None: 5327 5307 swwname = basename_in + '.sww' … … 5983 5963 outfile.variables[q+Write_sww.RANGE][1] = -max_float # Max 5984 5964 5985 # FIXME: Backwartds compat get rid of z once old view has retired 5986 5965 # FIXME: Backwards compat - get rid of z once old view has retired 5987 5966 outfile.createVariable('z', sww_precision, 5988 ('number_of_points',)) 5967 ('number_of_points',)) 5989 5968 5990 5969 for q in self.dynamic_quantities: … … 6000 5979 6001 5980 if isinstance(times, (list, num.ndarray)): 6002 outfile.variables['time'][:] = times # Store time relative5981 outfile.variables['time'][:] = times # Store time relative 6003 5982 6004 5983 if verbose: … … 6097 6076 log.critical('------------------------------------------------') 6098 6077 6099 #z = resize(bath_grid, outfile.variables['z'][:].shape)6100 6078 outfile.variables['x'][:] = points[:,0] #- geo_ref.get_xllcorner() 6101 6079 outfile.variables['y'][:] = points[:,1] #- geo_ref.get_yllcorner() … … 6118 6096 # @param verbose True if this function is to be verbose. 6119 6097 # @param **quant 6120 def store_quantities(self, outfile, sww_precision=num.float32, 6121 slice_index=None, time=None, 6122 verbose=False, **quant): 6098 def store_quantities(self, 6099 outfile, 6100 sww_precision=num.float32, 6101 slice_index=None, 6102 time=None, 6103 verbose=False, 6104 **quant): 6123 6105 """ 6124 Write the quantity info .6106 Write the quantity info at each timestep. 6125 6107 6126 6108 **quant is extra keyword arguments passed in. These must be 6127 the sww quantities, currently; stage, xmomentum, ymomentum.6109 the numpy arrays to be stored in the sww file at each timestep. 6128 6110 6129 6111 if the time array is already been built, use the slice_index … … 6140 6122 6141 6123 Precondition: 6142 triangulation and6143 header have been called.6124 store_triangulation and 6125 store_header have been called. 6144 6126 """ 6145 6127 … … 6149 6131 file_time[slice_index] = time 6150 6132 else: 6151 slice_index = int(slice_index) # In case it was numpy.int 6152 6153 # Write the conserved quantities from Domain. 6154 # Typically stage, xmomentum, ymomentum 6155 # other quantities will be ignored, silently. 6156 # Also write the ranges: stage_range, 6157 # xmomentum_range and ymomentum_range 6133 slice_index = int(slice_index) # Has to be cast in case it was numpy.int 6134 6135 # Write the named dynamic quantities 6136 # The dictionary quant must contain numpy arrays for each name. 6137 # These will typically be the conserved quantities from Domain 6138 # (Typically stage, xmomentum, ymomentum). 6139 # 6140 # Arrays not listed in dynamic_quantitiues will be ignored, silently. 6141 # 6142 # This method will also write the ranges for each quantity, 6143 # e.g. stage_range, xmomentum_range and ymomentum_range 6158 6144 for q in self.dynamic_quantities: 6159 6145 if not quant.has_key(q): 6160 msg = 'SWW file can not write quantity %s' % q 6146 msg = 'Values for quantity %s was not specified in ' % q 6147 msg += 'store_quantities so they cannot be stored.' 6161 6148 raise NewQuantity, msg 6162 6149 else:
Note: See TracChangeset
for help on using the changeset viewer.