Changeset 2262 for inundation/pyvolution/quantity.py
- Timestamp:
- Jan 20, 2006, 11:04:18 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/pyvolution/quantity.py
r2233 r2262 167 167 quantity = None, # Another quantity 168 168 function = None, # Callable object: f(x,y) 169 points = None, values = None, #Input for least squares169 points = None, values = None, data_georef = None, #Input for least squares 170 170 filename = None, attribute_name = None, #Input from file 171 171 alpha = None, … … 201 201 If points is specified, values is an array of length N containing 202 202 attribute values for each point. 203 204 data_georef: 205 If points is specified, geo_reference applies to each point. 203 206 204 207 filename: … … 305 308 assert values is not None, msg 306 309 self.set_values_from_points(points, values, alpha, 307 location, indices, verbose, 308 use_cache) 310 location, indices, 311 data_georef = data_georef, 312 verbose = verbose, 313 use_cache = use_cache) 309 314 elif filename is not None: 310 315 self.set_values_from_file(filename, attribute_name, alpha, 311 location, indices, verbose, 312 use_cache) 316 location, indices, 317 verbose = verbose, 318 use_cache = use_cache) 313 319 else: 314 320 raise 'This can\'t happen :-)' … … 513 519 #FIXME: Should check that function returns something sensible and 514 520 #raise a meaningfull exception if it returns None for example 521 522 #FIXME: Should supply absolute coordinates 515 523 516 524 from Numeric import take … … 546 554 547 555 def set_values_from_points(self, points, values, alpha, 548 location, indices, verbose, use_cache): 556 location, indices, 557 data_georef = None, 558 verbose = False, 559 use_cache = False): 549 560 """Set quantity values from arbitray data points using least squares 550 561 """ … … 553 564 from util import ensure_numeric 554 565 from least_squares import fit_to_mesh 566 from coordinate_transforms.geo_reference import Geo_reference 567 555 568 556 569 points = ensure_numeric(points, Float) … … 565 578 triangles = self.domain.triangles 566 579 580 581 #Take care of georeferencing 582 if data_georef is None: 583 data_georef = Geo_reference() 584 585 586 mesh_georef = self.domain.geo_reference 587 588 #print mesh_georef 589 #print data_georef 590 #print points 591 592 593 #Call least squares method 594 args = (coordinates, triangles, points, values) 595 kwargs = {'data_origin': data_georef.get_origin(), 596 'mesh_origin': mesh_georef.get_origin(), 597 'alpha': alpha, 598 'verbose': verbose} 599 600 #print kwargs 601 567 602 if use_cache is True: 568 603 try: … … 573 608 raise msg 574 609 575 args = (coordinates, triangles, points, values)576 kwargs = {'alpha': alpha, 'verbose': verbose}577 610 vertex_attributes = cache(fit_to_mesh, 578 611 args, kwargs, 579 612 verbose = verbose) 580 613 else: 581 vertex_attributes = fit_to_mesh(coordinates, 582 triangles, 583 points, 584 values, 585 alpha = alpha, 586 verbose = verbose) 587 588 614 615 vertex_attributes = apply(fit_to_mesh, 616 args, kwargs) 617 618 #Call underlying method using array values 589 619 self.set_values_from_array(vertex_attributes, 590 620 location, indices, verbose) … … 595 625 596 626 def set_values_from_file(self, filename, attribute_name, alpha, 597 location, indices, verbose, use_cache): 627 location, indices, 628 verbose = False, 629 use_cache = False): 598 630 """Set quantity based on arbitrary points in .pts file 599 631 using least_squares attribute_name selects name of attribute … … 602 634 """ 603 635 636 from load_mesh.loadASCII import import_points_file 604 637 605 638 from types import StringType … … 609 642 610 643 #Read from (NetCDF) file 611 from load_mesh.loadASCII import import_points_file612 644 points_dict = import_points_file(filename) 613 645 points = points_dict['pointlist'] … … 634 666 635 667 636 #Call least squares method 668 #Take care of georeferencing 669 if points_dict.has_key('geo_reference') and \ 670 points_dict['geo_reference'] is not None: 671 data_georef = points_dict['geo_reference'] 672 else: 673 data_georef = None 674 675 676 #Call underlying method for points 637 677 self.set_values_from_points(points, z, alpha, 638 location, indices, verbose, use_cache) 678 location, indices, 679 data_georef = data_georef, 680 verbose = verbose, 681 use_cache = use_cache) 639 682 640 683
Note: See TracChangeset
for help on using the changeset viewer.