Ignore:
Timestamp:
Mar 3, 2005, 6:40:01 PM (20 years ago)
Author:
ole
Message:

Implemented precropping facility in least squares
Also optimised inside_polygon

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inundation/ga/storm_surge/pyvolution/test_least_squares.py

    r994 r997  
    301301        assert allclose(sum(interp.get_A(), axis=1), 1.0)
    302302       
    303 
    304     # this causes a memory error in scipy.sparce       
     303    def test_arbitrary_datapoints_some_outside(self):
     304        """Try arbitrary datapoints one outside the triangle.
     305        That one should be ignored
     306        """
     307
     308        from Numeric import sum
     309       
     310        a = [0.0, 0.0]
     311        b = [0.0, 2.0]
     312        c = [2.0,0.0]
     313        points = [a, b, c]
     314        vertices = [ [1,0,2] ]   #bac
     315
     316        data = [ [0.2, 1.5], [0.123, 1.768], [1.43, 0.44], [5.0, 7.0]]
     317
     318
     319        interp = Interpolation(points, vertices, data, precrop = True)
     320        assert allclose(sum(interp.get_A(), axis=1), 1.0)
     321
     322        interp = Interpolation(points, vertices, data, precrop = False)
     323        assert allclose(sum(interp.get_A(), axis=1), [1,1,1,0])
     324       
     325       
     326
     327    # this causes a memory error in scipy.sparse       
    305328    def test_more_triangles(self):
    306329       
     
    844867                        [ 1.0, 0.0],
    845868                        [ 1.0, 1.0],
     869                        [ 15, -17],   #Outside mesh
    846870                        [ 1.0, 2.0],
    847871                        [ 1.0, 3.0],                                         
     
    851875
    852876        #Fit surface to mesh
    853         interp = Interpolation(points, triangles, data_points1, alpha=0.0)
     877        interp = Interpolation(points, triangles, data_points1, alpha=0.0,
     878                               precrop = True)
    854879        z = linear_function(data_points1) #Example z-values
    855880        f = interp.fit(z)                 #Fitted values at vertices
     
    861886                        [ 0.5, 0.5],
    862887                        [ 0.7, 0.7],
     888                        [-13, 65],  #Outside
    863889                        [ 1.0, 0.5],
    864890                        [ 2.0, 0.4],
     
    866892       
    867893
    868         #Build new A matrix based on new points
    869         interp.build_interpolation_matrix_A(data_points2)
     894
     895        #Build new A matrix based on new points (without precrop)
     896        interp.build_interpolation_matrix_A(data_points2, precrop = False)
    870897
    871898        #Interpolate using fitted surface
    872899        z1 = interp.interpolate(f)
     900
     901        #import Numeric
     902        #data_points2 = Numeric.take(data_points2, interp.point_indices)
     903
     904        #Desired result (OK for points inside)
     905
     906        answer = linear_function(data_points2)
     907        import Numeric
     908        z1 = Numeric.take(z1, [0,1,2,4,5,6])
     909        answer = Numeric.take(answer, [0,1,2,4,5,6])               
     910        assert allclose(z1, answer)
     911
     912        #Build new A matrix based on new points (with precrop)
     913        interp.build_interpolation_matrix_A(data_points2, precrop = True)
     914
     915        #Interpolate using fitted surface
     916        z1 = interp.interpolate(f)
     917
     918        import Numeric
     919        data_points2 = Numeric.take(data_points2, interp.point_indices)
    873920
    874921        #Desired result
     
    11121159#-------------------------------------------------------------
    11131160if __name__ == "__main__":
    1114     #suite = unittest.makeSuite(TestCase,'test')
    1115 
    11161161    suite = unittest.makeSuite(TestCase,'test')
     1162
    11171163    #suite = unittest.makeSuite(TestCase,'test_arbitrary_datapoints')
    11181164    runner = unittest.TextTestRunner(verbosity=1)
Note: See TracChangeset for help on using the changeset viewer.