Changeset 2309
- Timestamp:
- Jan 31, 2006, 5:41:13 PM (17 years ago)
- Location:
- inundation
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/geospatial_data/geospatial_data.py
r2306 r2309 42 42 self.set_attributes(attributes) 43 43 self.set_geo_reference(geo_reference) 44 self.default_attribute_name = default_attribute_name 44 self.set_default_attribute_name(default_attribute_name) 45 46 45 47 46 48 … … 85 87 86 88 89 def set_default_attribute_name(self, default_attribute_name): 90 self.default_attribute_name = default_attribute_name 87 91 92 93 def get_geo_reference(self): 94 return self.geo_reference 95 88 96 def get_data_points(self): 89 97 return self.data_points 90 98 91 def get_attribute _values(self, attribute_name = None):99 def get_attributes(self, attribute_name = None): 92 100 """Return values for one named attribute. 93 101 -
inundation/geospatial_data/test_geospatial_data.py
r2306 r2309 56 56 57 57 58 def test_get_attribute _values_1(self):58 def test_get_attributes_1(self): 59 59 from coordinate_transforms.geo_reference import Geo_reference 60 60 points = [[1.0, 2.1], [3.0, 5.3]] … … 67 67 assert allclose(P, [[1.0, 2.1], [3.0, 5.3]]) 68 68 69 V = G.get_attribute _values() #Simply get them69 V = G.get_attributes() #Simply get them 70 70 assert allclose(V, [2, 4]) 71 71 72 V = G.get_attribute _values('attribute') #Get by name72 V = G.get_attributes('attribute') #Get by name 73 73 assert allclose(V, [2, 4]) 74 74 75 75 76 def test_get_attribute _values_2(self):76 def test_get_attributes_2(self): 77 77 """Multiple attributes 78 78 """ … … 89 89 assert allclose(P, [[1.0, 2.1], [3.0, 5.3]]) 90 90 91 V = G.get_attribute _values() #Get default attribute91 V = G.get_attributes() #Get default attribute 92 92 assert allclose(V, [2, 4]) 93 93 94 V = G.get_attribute _values('a0') #Get by name94 V = G.get_attributes('a0') #Get by name 95 95 assert allclose(V, [0, 0]) 96 96 97 V = G.get_attribute _values('a1') #Get by name97 V = G.get_attributes('a1') #Get by name 98 98 assert allclose(V, [2, 4]) 99 99 100 V = G.get_attribute _values('a2') #Get by name100 V = G.get_attributes('a2') #Get by name 101 101 assert allclose(V, [79.4, -7]) 102 102 103 103 try: 104 V = G.get_attribute _values('hdnoatedu') #Invalid104 V = G.get_attributes('hdnoatedu') #Invalid 105 105 except AssertionError: 106 106 pass … … 166 166 #assert allclose(V, [2, 4]) 167 167 168 V = G.get_attribute _values('a0') #Get by name168 V = G.get_attributes('a0') #Get by name 169 169 assert allclose(V, [0, 0]) 170 170 171 V = G.get_attribute _values('a1') #Get by name171 V = G.get_attributes('a1') #Get by name 172 172 assert allclose(V, [2, 4]) 173 173 174 V = G.get_attribute _values('a2') #Get by name174 V = G.get_attributes('a2') #Get by name 175 175 assert allclose(V, [79.4, -7]) 176 176 -
inundation/pyvolution/quantity.py
r2262 r2309 167 167 quantity = None, # Another quantity 168 168 function = None, # Callable object: f(x,y) 169 points = None, values = None, data_georef = None, #Input for least squares 169 geospatial_data = None, #Arbitrary dataset 170 points = None, values = None, data_georef = None, #Input for least squares (obsoleted by use of geo_spatial object) 170 171 filename = None, attribute_name = None, #Input from file 171 172 alpha = None, … … 181 182 If callable it will treated as a function (see below) 182 183 If instance of another Quantity it will be treated as such. 184 If geo_spatial object it will be treated as such 183 185 184 186 quantity: … … 191 193 The function will be evaluated at points determined by 192 194 location and indices in the underlying mesh. 195 196 geospatial_data: 197 Arbitrary geo spatial dataset in the form of the class 198 Geospatial_data. Mesh points are populated using least squares 199 fitting 193 200 194 201 points: … … 208 215 Name of a .pts file containing data points and attributes for 209 216 use with least squares. 210 If attribute_name is specified, any array matching that name 211 will be used. Otherwise the first available one will be used. 217 218 attribute_name: 219 If specified, any array matching that name 220 will be used. from file or geospatial_data. 221 Otherwise a default will be used. 212 222 213 223 alpha: … … 255 265 """ 256 266 267 from geospatial_data.geospatial_data import Geospatial_data 257 268 from types import FloatType, IntType, LongType, ListType, NoneType 258 269 from Numeric import ArrayType 259 270 260 271 #General input checks 261 L = [numeric, quantity, function, points, filename]272 L = [numeric, quantity, function, geospatial_data, points, filename] 262 273 msg = 'Exactly one of the arguments '+\ 263 'numeric, quantity, function, points, or filename '+\274 'numeric, quantity, function, geospatial_data, points, or filename '+\ 264 275 'must be present.' 265 276 assert L.count(None) == len(L)-1, msg … … 292 303 self.set_values_from_quantity(numeric, 293 304 location, indices, verbose) 305 elif isinstance(numeric, Geospatial_data): 306 self.set_values_from_geospatial_data(numeric, 307 alpha, 308 location, indices, 309 verbose = verbose, 310 use_cache = use_cache) 294 311 else: 295 312 msg = 'Illegal type for argument numeric: %s' %str(numeric) … … 304 321 self.set_values_from_function(function, 305 322 location, indices, verbose) 323 elif geospatial_data is not None: 324 self.set_values_from_geospatial_data(geospatial_data, 325 alpha, 326 location, indices, 327 verbose = verbose, 328 use_cache = use_cache) 306 329 elif points is not None: 330 print 'The usage of points in set_values will be deprecated.' +\ 331 'Please use the geospatial_data object.' 332 307 333 msg = 'When points are specified, associated values must also be.' 308 334 assert values is not None, msg … … 552 578 553 579 580 581 def set_values_from_geospatial_data(self, geospatial_data, alpha, 582 location, indices, 583 verbose = False, 584 use_cache = False): 585 586 #FIXME: Use this function for the time being. Later move code in here 587 588 points = geospatial_data.get_data_points() 589 values = geospatial_data.get_attributes() 590 data_georef = geospatial_data.get_geo_reference() 591 592 593 self.set_values_from_points(points, values, alpha, 594 location, indices, 595 data_georef = data_georef, 596 verbose = verbose, 597 use_cache = use_cache) 598 599 554 600 555 601 def set_values_from_points(self, points, values, alpha, … … 571 617 572 618 if location != 'vertices': 573 msg = 'set_values_from_points is only defined for '+\619 msg = 'set_values_from_points is only defined for '+\ 574 620 'location=\'vertices\'' 575 621 raise msg … … 622 668 623 669 624 625 626 670 def set_values_from_file(self, filename, attribute_name, alpha, 627 671 location, indices, … … 635 679 636 680 from load_mesh.loadASCII import import_points_file 681 from geospatial_data.geospatial_data import points_dictionary2geospatial_data 637 682 638 683 from types import StringType … … 658 703 print 'Available attributes: %s' %(names) 659 704 660 try:661 z = attributes[attribute_name]662 except:663 msg = 'Could not extract attribute %s from file %s'\664 %(attribute_name, filename)665 raise msg705 #try: 706 # z = attributes[attribute_name] 707 #except: 708 # msg = 'Could not extract attribute %s from file %s'\ 709 # %(attribute_name, filename) 710 # raise msg 666 711 667 712 … … 674 719 675 720 721 722 #Call underlying method for geospatial data 723 geospatial_data = points_dictionary2geospatial_data(points_dict) 724 geospatial_data.set_default_attribute_name(attribute_name) 725 726 self.set_values_from_geospatial_data(geospatial_data, 727 alpha, 728 location, indices, 729 verbose = verbose, 730 use_cache = use_cache) 731 676 732 #Call underlying method for points 677 self.set_values_from_points(points, z, alpha,678 location, indices,679 data_georef = data_georef,680 verbose = verbose,681 use_cache = use_cache)733 #self.set_values_from_points(points, z, alpha, 734 # location, indices, 735 # data_georef = data_georef, 736 # verbose = verbose, 737 # use_cache = use_cache) 682 738 683 739 -
inundation/pyvolution/test_quantity.py
r2262 r2309 280 280 def test_set_values_using_least_squares(self): 281 281 282 from geospatial_data.geospatial_data import Geospatial_data 282 283 283 284 quantity = Quantity(self.mesh4) … … 301 302 302 303 #Use built-in least squares fit 303 quantity.set_values(points = data_points, values = z, alpha = 0) 304 quantity.set_values( Geospatial_data(data_points, z), alpha = 0 ) 305 #quantity.set_values(points = data_points, values = z, alpha = 0) 306 307 304 308 answer = linear_function(quantity.domain.get_vertex_coordinates(obj = True)) 305 309 #print quantity.vertex_values, answer … … 327 331 328 332 from domain import Domain 333 from geospatial_data.geospatial_data import Geospatial_data 329 334 from coordinate_transforms.geo_reference import Geo_reference 330 335 from least_squares import fit_to_mesh … … 362 367 assert allclose( ref, [0,5,5] ) 363 368 369 364 370 #Test set_values 365 quantity.set_values(points = data_points, values = z, data_georef = data_georef, 366 alpha = 0) 367 371 372 quantity.set_values( Geospatial_data(data_points, z, data_georef), alpha = 0 ) 373 374 #quantity.set_values(points = data_points, 375 # values = z, 376 # data_georef = data_georef, 377 # alpha = 0) 378 379 380 #quantity.set_values(points = data_points, 381 # values = z, 382 # data_georef = data_georef, 383 # alpha = 0) 368 384 assert allclose(quantity.vertex_values.flat, ref) 385 386 387 388 #Test set_values using geospatial data object 389 quantity.vertex_values[:] = 0.0 390 391 from geospatial_data.geospatial_data import Geospatial_data 392 geo = Geospatial_data(data_points, z, data_georef) 393 394 395 quantity.set_values(geospatial_data = geo, alpha = 0) 396 assert allclose(quantity.vertex_values.flat, ref) 369 397 370 398 -
inundation/utilities/__init__.py
r1910 r2309 4 4 pass 5 5 6 #Add path of package to PYTHONPATH to allow C-extensions to be loaded 7 import sys 8 sys.path += __path__
Note: See TracChangeset
for help on using the changeset viewer.