- Timestamp:
- Mar 1, 2005, 12:16:51 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/test_least_squares.py
r969 r976 878 878 879 879 880 def test_fit_and_interpolation_with_different_origins(self): 881 """Fit a surface to one set of points. Then interpolate that surface 882 using another set of points. 883 This test tests situtaion where points and mesh belong to a different 884 coordinate system as defined by origin. 885 """ 886 from mesh import Mesh 887 888 #Setup mesh used to represent fitted function 889 a = [0.0, 0.0] 890 b = [0.0, 2.0] 891 c = [2.0, 0.0] 892 d = [0.0, 4.0] 893 e = [2.0, 2.0] 894 f = [4.0, 0.0] 895 896 points = [a, b, c, d, e, f] 897 #bac, bce, ecf, dbe, daf, dae 898 triangles = [[1,0,2], [1,2,4], [4,2,5], [3,1,4]] 899 900 #Datapoints to fit from 901 data_points1 = [[ 0.66666667, 0.66666667], 902 [ 1.33333333, 1.33333333], 903 [ 2.66666667, 0.66666667], 904 [ 0.66666667, 2.66666667], 905 [ 0.0, 1.0], 906 [ 0.0, 3.0], 907 [ 1.0, 0.0], 908 [ 1.0, 1.0], 909 [ 1.0, 2.0], 910 [ 1.0, 3.0], 911 [ 2.0, 1.0], 912 [ 3.0, 0.0], 913 [ 3.0, 1.0]] 914 915 916 #First check that things are OK when using same origin 917 mesh_origin = (56, 290000, 618000) #zone, easting, northing 918 data_origin = (56, 290000, 618000) #zone, easting, northing 919 920 921 #Fit surface to mesh 922 interp = Interpolation(points, triangles, data_points1, 923 alpha=0.0, 924 data_origin = data_origin, 925 mesh_origin = mesh_origin) 926 927 z = linear_function(data_points1) #Example z-values 928 f = interp.fit(z) #Fitted values at vertices 929 930 931 #New datapoints where interpolated values are sought 932 data_points2 = [[ 0.0, 0.0], 933 [ 0.5, 0.5], 934 [ 0.7, 0.7], 935 [ 1.0, 0.5], 936 [ 2.0, 0.4], 937 [ 2.8, 1.2]] 938 939 940 #Build new A matrix based on new points 941 interp.build_interpolation_matrix_A(data_points2) 942 943 #Interpolate using fitted surface 944 z1 = interp.interpolate(f) 945 946 #Desired result 947 answer = linear_function(data_points2) 948 assert allclose(z1, answer) 949 950 951 ############################################## 952 953 #Then check situtaion where points are relative to a different 954 #origin (same zone, though, until we figure that out (FIXME)) 955 956 mesh_origin = (56, 290000, 618000) #zone, easting, northing 957 data_origin = (56, 10000, 10000) #zone, easting, northing 958 959 #Shift datapoints according to new origin 960 961 for k in range(len(data_points1)): 962 data_points1[k][0] += mesh_origin[1] - data_origin[1] 963 data_points1[k][1] += mesh_origin[2] - data_origin[2] 964 965 for k in range(len(data_points2)): 966 data_points2[k][0] += mesh_origin[1] - data_origin[1] 967 data_points2[k][1] += mesh_origin[2] - data_origin[2] 968 969 970 971 #Fit surface to mesh 972 interp = Interpolation(points, triangles, data_points1, 973 alpha=0.0, 974 data_origin = data_origin, 975 mesh_origin = mesh_origin) 976 977 f1 = interp.fit(z) #Fitted values at vertices (using same z as before) 978 979 assert allclose(f,f1), 'Fit should have been unaltered' 980 981 982 #Build new A matrix based on new points 983 interp.build_interpolation_matrix_A(data_points2) 984 985 #Interpolate using fitted surface 986 z1 = interp.interpolate(f) 987 assert allclose(z1, answer) 988 989 880 990 881 991 def test_fit_to_mesh_file(self):
Note: See TracChangeset
for help on using the changeset viewer.