Changeset 1681
- Timestamp:
- Aug 4, 2005, 3:40:49 PM (19 years ago)
- Location:
- inundation/ga/storm_surge/pyvolution
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/domain.py
r1662 r1681 141 141 142 142 143 def set_quantity(self, name, X, location='vertices', indexes = None): 143 def set_quantity(self, name, 144 X, 145 location='vertices', 146 indexes = None): 144 147 """Set values for named quantity 145 148 … … 170 173 Q is a quantity 171 174 b is either a scalar, a quantity or a compatible array 175 pts file 172 176 location: Where values are to be stored. 173 177 Permissible options are: vertices, edges, centroid … … 180 184 181 185 182 183 186 """ 184 187 … … 192 195 193 196 #Set value 194 self.quantities[name].set_values(X, location, indexes = indexes) 197 self.quantities[name].set_values(X, 198 location, 199 indexes = indexes) 200 195 201 196 202 -
inundation/ga/storm_surge/pyvolution/least_squares.py
r1671 r1681 890 890 891 891 Optional input: 892 quantity_names: List of keys into quantities dictionary892 quantity_names: List of keys into the quantities dictionary 893 893 vertex_coordinates: mx2 array of coordinates (Float) 894 894 triangles: nx3 array of indices into vertex_coordinates (Int) -
inundation/ga/storm_surge/pyvolution/quantity.py
r1657 r1681 79 79 80 80 81 def set_values(self, X, location='vertices', indexes = None): 81 def set_values(self, X, 82 location='vertices', 83 indexes = None): 82 84 """Set values for quantity 83 85 … … 107 109 In any other case, only values for the specified locations 108 110 will be assigned and the others will be left undefined. 111 109 112 """ 110 113 … … 112 115 msg = 'Invalid location: %s' %location 113 116 raise msg 117 118 #FIXME Do we really need 'location'? 114 119 115 120 if X is None: … … 170 175 self.vertex_values[i_vertex,:] = X 171 176 172 el se:177 elif type(X) in [Numeric.ArrayType, types.ListType]: 173 178 #Use array specific method 174 179 self.set_array_values(X, location, indexes = indexes) 175 180 elif type(X) == types.StringType: 181 #Assume X is a filename 182 self.set_values_from_file(X) #FIXME: More parameters 183 184 176 185 if location == 'vertices' or location == 'unique vertices': 177 186 #Intialise centroid and edge_values … … 383 392 384 393 394 395 def set_values_from_file(self, filename, 396 attribute_name = None, 397 verbose = False): 398 """Set quantity based on arbitrary points in .pts file using least_squares 399 400 attribute_name selects name of attribute present in file. 401 If not specified try to use whatever is available in file. 402 """ 403 404 #FIXME location, indices 405 406 407 import util, least_squares 408 409 points, attributes = util.read_xya(filename) 410 411 if attribute_name is None: 412 names = attributes.keys() 413 attribute_name = names[0] 414 415 416 if verbose: 417 print 'Using attribute %s from file %s' %(attribute_name, filename) 418 print 'Available attributes: %s' %(names) 419 420 421 try: 422 z = attributes[attribute_name] 423 except: 424 msg = 'Could not extract attribute %s from file %s'\ 425 %(attribute_name, filename) 426 raise msg 427 428 429 #Fit attributes to mesh 430 X = least_squares.fit_to_mesh(self.domain.coordinates, 431 self.domain.triangles, 432 points, 433 z, 434 verbose=verbose) 435 436 437 438 #Recursively set value using fitted array 439 print 'shape', X.shape 440 self.set_values(X, location='vertices') #FIXME, indexes = None): 441 442 443 444 385 445 # FIXME have a get_vertex_values as well, so the 'stage' quantity can be 386 446 # set, based on the elevation -
inundation/ga/storm_surge/pyvolution/util.py
r1671 r1681 138 138 interpolation_points = None, verbose = False): 139 139 """If quantities is not specified, derive them from domain 140 (if that is specified) 140 (if that is specified) 141 142 143 see get_netcdf_file_function 141 144 """ 142 145 … … 198 201 199 202 200 import time, calendar 203 import time, calendar, types 201 204 from config import time_format 202 205 from Scientific.IO.NetCDF import NetCDFFile … … 207 210 fid = NetCDFFile(filename, 'r') 208 211 212 if type(quantity_names) == types.StringType: 213 quantity_names = [quantity_names] 214 209 215 if quantity_names is None or len(quantity_names) < 1: 210 216 #Get quantities from file … … 230 236 231 237 #Decide whether this data has a spatial dimension 238 #FIXME: Let us split this up into two functions: One that reads 239 #sww and one that reads tms (time series only) 232 240 spatial = True 233 241 for quantity in ['x', 'y']: … … 344 352 attributes = {} 345 353 for key in keys: 346 attributes[key] = fid.variables[key] 354 if key != 'points': 355 attributes[key] = fid.variables[key] 347 356 #Don't close - arrays are needed outside this function, 348 357 #alternatively take a copy here
Note: See TracChangeset
for help on using the changeset viewer.