Changeset 2577


Ignore:
Timestamp:
Mar 22, 2006, 5:28:24 PM (18 years ago)
Author:
duncan
Message:

changing interpolate to use geospatial_data objects

Location:
inundation/fit_interpolate
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • inundation/fit_interpolate/interpolate.py

    r2573 r2577  
    3232from utilities.numerical_tools import ensure_numeric, mean, INF
    3333from utilities.polygon import inside_polygon
     34from geospatial_data.geospatial_data import Geospatial_data
    3435
    3536from search_functions import search_tree_of_vertices
     
    188189          point_coordinates: Interpolate mesh data to these positions.
    189190              List of coordinate pairs [x, y] of
    190               data points (or an nx2 Numeric array)
     191              data points or an nx2 Numeric array or a Geospatial_data object
     192             
    191193              If point_coordinates is absent, the points inputted last time
    192194              this method was called are used, if possible.
     
    198200        """
    199201        #print "point_coordinates interpolate.interpolate",point_coordinates
    200         # Can I interpolate, based on previous point_coordinates?
     202        # Can I interpolate, based on previous point_coordinates?
     203        if isinstance(point_coordinates,Geospatial_data):
     204            point_coordinates = point_coordinates.get_data_points( \
     205                absolute = True)
     206       
    201207        if point_coordinates is None:
    202208            if self._A_can_be_reused is True and \
  • inundation/fit_interpolate/test_interpolate.py

    r2563 r2577  
    2222from utilities.numerical_tools import mean
    2323from data_manager import get_dataobject
     24from geospatial_data.geospatial_data import Geospatial_data
    2425
    2526def distance(x, y):
     
    792793            raise 'Should raise exception'
    793794
    794        
    795     def BADtest_interpolate_sww(self):
    796         """Not a unit test, rather a system test for interpolate_sww
    797         This function is obsolete
    798         """
    799        
    800         self.domain.filename = 'datatest' + str(time.time())
    801         self.domain.format = 'sww'
    802         self.domain.smooth = True
    803         self.domain.reduction = mean
    804 
    805         sww = get_dataobject(self.domain)
    806         sww.store_connectivity()
    807         sww.store_timestep('stage')
    808         self.domain.time = 2.
    809         sww.store_timestep('stage')
    810 
    811         #print "self.domain.filename",self.domain.filename
    812         interp = interpolate_sww(sww.filename, [0.0, 2.0],
    813                                  [[0,1],[0.5,0.5]],
    814                                  ['stage'])
    815         #assert allclose(interp,[0.0,2.0])
    816 
    817         #Cleanup
    818         os.remove(sww.filename)
     795
     796    def qtest_interpolation_interface(self):
     797        a = [-1.0, 0.0]
     798        b = [3.0, 4.0]
     799        c = [4.0, 1.0]
     800        d = [-3.0, 2.0] #3
     801        e = [-1.0, -2.0]
     802        f = [1.0, -2.0] #5
     803
     804        vertices = [a, b, c, d,e,f]
     805        triangles = [[0,1,3], [1,0,2], [0,4,5], [0,5,2]] #abd bac aef afc
     806
     807        point_coords = [[-2.0, 2.0],
     808                        [-1.0, 1.0],
     809                        [0.0, 2.0],
     810                        [1.0, 1.0],
     811                        [2.0, 1.0],
     812                        [0.0, 0.0],
     813                        [1.0, 0.0],
     814                        [0.0, -1.0],
     815                        [-0.2, -0.5],
     816                        [-0.9, -1.5],
     817                        [0.5, -1.9],
     818                        [999999, 9999999]]
     819        geo_data = Geospatial_data(data_points = point_coords)
     820
     821        interp = Interpolate(vertices, triangles)
     822        f = array([linear_function(vertices),2*linear_function(vertices) ])
     823        f = transpose(f)
     824        #print "f",f
     825        z = interp.interpolate(f, geo_data)
     826        #z = interp.interpolate(f, point_coords)
     827        answer = [linear_function(point_coords),
     828                  2*linear_function(point_coords) ]
     829        answer = transpose(answer)
     830        #print "z",z
     831        #print "answer",answer
     832        assert allclose(z, answer)
     833
    819834       
    820835#-------------------------------------------------------------
    821836if __name__ == "__main__":
    822     suite = unittest.makeSuite(Test_Interpolate,'test')
     837    suite = unittest.makeSuite(Test_Interpolate,'qtest')
    823838    runner = unittest.TextTestRunner(verbosity=1)
    824839    runner.run(suite)
Note: See TracChangeset for help on using the changeset viewer.