Ignore:
Timestamp:
Apr 4, 2006, 3:49:42 PM (18 years ago)
Author:
duncan
Message:

Adding ability to remove points outside of the mesh when interpolating

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inundation/fit_interpolate/test_interpolate.py

    r2651 r2655  
    2020from coordinate_transforms.geo_reference import Geo_reference
    2121from shallow_water import Domain, Transmissive_boundary
    22 from utilities.numerical_tools import mean
     22from utilities.numerical_tools import mean, INF
    2323from data_manager import get_dataobject
    2424from geospatial_data.geospatial_data import Geospatial_data
     
    237237        assert allclose(sum(results, axis=1), 1.0)
    238238
    239         #FIXME - have to change this test to check default info
    240     def NO_test_arbitrary_datapoints_some_outside(self):
     239    def test_arbitrary_datapoints_some_outside(self):
    241240        """Try arbitrary datapoints one outside the triangle.
    242241        That one should be ignored
     
    253252        data = [ [0.2, 1.5], [0.123, 1.768], [1.43, 0.44], [5.0, 7.0]]
    254253
    255 
    256         interp = Interpolate(points, vertices, data, precrop = True)
    257        
    258         results = interp._build_interpolation_matrix_A(data).todense()
    259         assert allclose(sum(results, axis=1), 1.0)
    260 
    261         interp = Interpolate(points, vertices, data, precrop = False)
     254        interp = Interpolate(points, vertices, data)
    262255        results = interp._build_interpolation_matrix_A(data).todense()
    263256        assert allclose(sum(results, axis=1), [1,1,1,0])
     
    301294        assert allclose(A, answer)
    302295
    303 
     296        #FIXME -  tests are hopefully failing due to points outsdie the
     297        # mesh
    304298    def test_interpolate_attributes_to_points(self):
    305299        v0 = [0.0, 0.0]
     
    442436
    443437        z = interp.interpolate(f, point_coords)
    444         answer = [ [0., 0., 0., 0.]] # (-1,-1)
     438        answer = array([ [INF, INF, INF, INF]]) # (-1,-1)
    445439
    446440        #print "***********"
     
    452446        # of the mesh? Not currently. 
    453447
    454         assert allclose(z, answer)
    455 
     448        for i in range(4):
     449            self.failUnless( z[0,i] == answer[0,i], 'Fail!')
     450       
    456451    def test_interpolate_attributes_to_pointsIV(self):
    457452        a = [-1.0, 0.0]
     
    594589
    595590    def test_interpolation_interface_time_only(self):
    596         """Test spatio-temporal interpolation
    597         Test that spatio temporal function performs the correct
    598         interpolations in both time and space
    599         """
     591
     592        # Test spatio-temporal interpolation
     593        # Test that spatio temporal function performs the correct
     594        # interpolations in both time and space
     595       
    600596
    601597
     
    667663
    668664    def test_interpolation_interface_spatial_only(self):
    669         """Test spatio-temporal interpolation with constant time
    670         """
    671 
     665        # Test spatio-temporal interpolation with constant time
     666       
    672667        #Three timesteps
    673668        time = [1.0, 5.0, 6.0]
     
    728723
    729724    def test_interpolation_interface(self):
    730         """Test spatio-temporal interpolation
    731         Test that spatio temporal function performs the correct
    732         interpolations in both time and space
    733         """
    734 
     725        # Test spatio-temporal interpolation
     726        # Test that spatio temporal function performs the correct
     727        # interpolations in both time and space
     728   
    735729
    736730        #Three timesteps
     
    793787
    794788
    795     def qtest_interpolation_interface(self):
     789    def test_points_outside_the_polygon(self):
    796790        a = [-1.0, 0.0]
    797791        b = [3.0, 4.0]
     
    815809                        [-0.9, -1.5],
    816810                        [0.5, -1.9],
    817                         [999999, 9999999]]
     811                        [999999, 9999999]] # point Outside poly
    818812        geo_data = Geospatial_data(data_points = point_coords)
    819813
     
    827821                  2*linear_function(point_coords) ]
    828822        answer = transpose(answer)
     823        answer[11,:] = [INF, INF]
    829824        #print "z",z
    830         #print "answer",answer
    831         assert allclose(z, answer)
    832 
     825        #print "answer _ fixed",answer
     826        assert allclose(z[0:10], answer[0:10])
     827        self.failUnless( z[11,1] == answer[11,1], 'Fail!')
     828        self.failUnless( z[11,0] == answer[11,0], 'Fail!')
     829
     830       
     831    def test_points_outside_the_polygon(self):
     832        a = [-1.0, 0.0]
     833        b = [3.0, 4.0]
     834        c = [4.0, 1.0]
     835        d = [-3.0, 2.0] #3
     836        e = [-1.0, -2.0]
     837        f = [1.0, -2.0] #5
     838
     839        vertices = [a, b, c, d,e,f]
     840        triangles = [[0,1,3], [1,0,2], [0,4,5], [0,5,2]] #abd bac aef afc
     841
     842        point_coords = [[-2.0, 2.0],
     843                        [-1.0, 1.0],
     844                        [9999.0, 9999.0], # point Outside poly
     845                        [-9999.0, 1.0], # point Outside poly
     846                        [2.0, 1.0],
     847                        [0.0, 0.0],
     848                        [1.0, 0.0],
     849                        [0.0, -1.0],
     850                        [-0.2, -0.5],
     851                        [-0.9, -1.5],
     852                        [0.5, -1.9],
     853                        [999999, 9999999]] # point Outside poly
     854        geo_data = Geospatial_data(data_points = point_coords)
     855
     856        interp = Interpolate(vertices, triangles)
     857        f = array([linear_function(vertices),2*linear_function(vertices) ])
     858        f = transpose(f)
     859        #print "f",f
     860        z = interp.interpolate(f, geo_data)
     861        #z = interp.interpolate(f, point_coords)
     862        answer = [linear_function(point_coords),
     863                  2*linear_function(point_coords) ]
     864        answer = transpose(answer)
     865        answer[2,:] = [INF, INF]
     866        answer[3,:] = [INF, INF]
     867        answer[11,:] = [INF, INF]
     868        #print "z",z
     869        #print "answer _ fixed",answer
     870        assert allclose(z[0:1], answer[0:1])
     871        assert allclose(z[4:10], answer[4:10])
     872        for i in [2,3,11]:
     873            self.failUnless( z[i,1] == answer[11,1], 'Fail!')
     874            self.failUnless( z[i,0] == answer[11,0], 'Fail!')
    833875       
    834876#-------------------------------------------------------------
    835877if __name__ == "__main__":
     878
     879    #suite = unittest.makeSuite(Test_Interpolate,'test')
    836880    suite = unittest.makeSuite(Test_Interpolate,'test')
     881    #suite = unittest.makeSuite(Test_Interpolate,'test_points_outside_the_polygon')
    837882    runner = unittest.TextTestRunner(verbosity=1)
    838883    runner.run(suite)
Note: See TracChangeset for help on using the changeset viewer.