Changeset 2309


Ignore:
Timestamp:
Jan 31, 2006, 5:41:13 PM (17 years ago)
Author:
ole
Message:

Deployed geo_spatial stuff

Location:
inundation
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • inundation/geospatial_data/geospatial_data.py

    r2306 r2309  
    4242        self.set_attributes(attributes)
    4343        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
    4547
    4648
     
    8587
    8688
     89    def set_default_attribute_name(self, default_attribute_name):
     90        self.default_attribute_name = default_attribute_name
    8791
     92
     93    def get_geo_reference(self):
     94        return self.geo_reference
     95       
    8896    def get_data_points(self):
    8997        return self.data_points
    9098
    91     def get_attribute_values(self, attribute_name = None):
     99    def get_attributes(self, attribute_name = None):
    92100        """Return values for one named attribute.
    93101
  • inundation/geospatial_data/test_geospatial_data.py

    r2306 r2309  
    5656
    5757
    58     def test_get_attribute_values_1(self):
     58    def test_get_attributes_1(self):
    5959        from coordinate_transforms.geo_reference import Geo_reference
    6060        points = [[1.0, 2.1], [3.0, 5.3]]
     
    6767        assert allclose(P, [[1.0, 2.1], [3.0, 5.3]])       
    6868       
    69         V = G.get_attribute_values() #Simply get them
     69        V = G.get_attributes() #Simply get them
    7070        assert allclose(V, [2, 4])
    7171
    72         V = G.get_attribute_values('attribute') #Get by name
     72        V = G.get_attributes('attribute') #Get by name
    7373        assert allclose(V, [2, 4])
    7474
    7575
    76     def test_get_attribute_values_2(self):
     76    def test_get_attributes_2(self):
    7777        """Multiple attributes
    7878        """
     
    8989        assert allclose(P, [[1.0, 2.1], [3.0, 5.3]])       
    9090       
    91         V = G.get_attribute_values() #Get default attribute
     91        V = G.get_attributes() #Get default attribute
    9292        assert allclose(V, [2, 4])
    9393
    94         V = G.get_attribute_values('a0') #Get by name
     94        V = G.get_attributes('a0') #Get by name
    9595        assert allclose(V, [0, 0])
    9696
    97         V = G.get_attribute_values('a1') #Get by name
     97        V = G.get_attributes('a1') #Get by name
    9898        assert allclose(V, [2, 4])
    9999
    100         V = G.get_attribute_values('a2') #Get by name
     100        V = G.get_attributes('a2') #Get by name
    101101        assert allclose(V, [79.4, -7])
    102102
    103103        try:
    104             V = G.get_attribute_values('hdnoatedu') #Invalid
     104            V = G.get_attributes('hdnoatedu') #Invalid
    105105        except AssertionError:
    106106            pass
     
    166166        #assert allclose(V, [2, 4])
    167167
    168         V = G.get_attribute_values('a0') #Get by name
     168        V = G.get_attributes('a0') #Get by name
    169169        assert allclose(V, [0, 0])
    170170
    171         V = G.get_attribute_values('a1') #Get by name
     171        V = G.get_attributes('a1') #Get by name
    172172        assert allclose(V, [2, 4])
    173173
    174         V = G.get_attribute_values('a2') #Get by name
     174        V = G.get_attributes('a2') #Get by name
    175175        assert allclose(V, [79.4, -7])
    176176
  • inundation/pyvolution/quantity.py

    r2262 r2309  
    167167                   quantity = None,   # Another quantity
    168168                   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)
    170171                   filename = None, attribute_name = None, #Input from file
    171172                   alpha = None,
     
    181182          If callable it will treated as a function (see below)
    182183          If instance of another Quantity it will be treated as such.
     184          If geo_spatial object it will be treated as such
    183185
    184186        quantity:
     
    191193          The function will be evaluated at points determined by
    192194          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           
    193200
    194201        points:
     
    208215          Name of a .pts file containing data points and attributes for
    209216          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.
    212222
    213223        alpha:
     
    255265        """
    256266
     267        from geospatial_data.geospatial_data import Geospatial_data
    257268        from types import FloatType, IntType, LongType, ListType, NoneType
    258269        from Numeric import ArrayType
    259270
    260271        #General input checks
    261         L = [numeric, quantity, function, points, filename]
     272        L = [numeric, quantity, function, geospatial_data, points, filename]
    262273        msg = 'Exactly one of the arguments '+\
    263               'numeric, quantity, function, points, or filename '+\
     274              'numeric, quantity, function, geospatial_data, points, or filename '+\
    264275              'must be present.'
    265276        assert L.count(None) == len(L)-1, msg
     
    292303                self.set_values_from_quantity(numeric,
    293304                                              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)
    294311            else:
    295312                msg = 'Illegal type for argument numeric: %s' %str(numeric)
     
    304321            self.set_values_from_function(function,
    305322                                          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)
    306329        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           
    307333            msg = 'When points are specified, associated values must also be.'
    308334            assert values is not None, msg
     
    552578
    553579
     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                               
    554600
    555601    def set_values_from_points(self, points, values, alpha,
     
    571617
    572618        if location != 'vertices':
    573             msg = 'set_values_from_points is only defined for'+\
     619            msg = 'set_values_from_points is only defined for '+\
    574620                  'location=\'vertices\''
    575621            raise msg
     
    622668
    623669
    624 
    625 
    626670    def set_values_from_file(self, filename, attribute_name, alpha,
    627671                             location, indices,
     
    635679
    636680        from load_mesh.loadASCII import import_points_file
     681        from geospatial_data.geospatial_data import points_dictionary2geospatial_data
    637682
    638683        from types import StringType
     
    658703            print 'Available attributes: %s' %(names)
    659704
    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 msg
     705        #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
    666711
    667712
     
    674719
    675720
     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       
    676732        #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)
    682738
    683739
  • inundation/pyvolution/test_quantity.py

    r2262 r2309  
    280280    def test_set_values_using_least_squares(self):
    281281
     282        from geospatial_data.geospatial_data import Geospatial_data
    282283       
    283284        quantity = Quantity(self.mesh4)
     
    301302       
    302303        #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       
    304308        answer = linear_function(quantity.domain.get_vertex_coordinates(obj = True))
    305309        #print quantity.vertex_values, answer
     
    327331
    328332        from domain import Domain
     333        from geospatial_data.geospatial_data import Geospatial_data       
    329334        from coordinate_transforms.geo_reference import Geo_reference
    330335        from least_squares import fit_to_mesh
     
    362367        assert allclose( ref, [0,5,5] )       
    363368
     369
    364370        #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)
    368384        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)       
    369397
    370398
  • inundation/utilities/__init__.py

    r1910 r2309  
    44pass
    55
     6#Add path of package to PYTHONPATH to allow C-extensions to be loaded
     7import sys
     8sys.path += __path__
Note: See TracChangeset for help on using the changeset viewer.