Changeset 642 for inundation/ga
- Timestamp:
- Nov 30, 2004, 3:28:49 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/test_least_squares.py
r611 r642 622 622 z1 = interp.interpolate(f) 623 623 assert allclose(z, z1) 624 625 626 627 def test_fit_and_interpolation_with_new_points(self): 628 """Fit a surface to one set of points. Then interpolate that surface 629 using another set of points. 630 """ 631 from mesh import Mesh 632 633 634 #Setup mesh used to represent fitted function 635 a = [0.0, 0.0] 636 b = [0.0, 2.0] 637 c = [2.0, 0.0] 638 d = [0.0, 4.0] 639 e = [2.0, 2.0] 640 f = [4.0, 0.0] 641 642 points = [a, b, c, d, e, f] 643 #bac, bce, ecf, dbe, daf, dae 644 triangles = [[1,0,2], [1,2,4], [4,2,5], [3,1,4]] 645 646 #Datapoints to fit from 647 data_points1 = [[ 0.66666667, 0.66666667], 648 [ 1.33333333, 1.33333333], 649 [ 2.66666667, 0.66666667], 650 [ 0.66666667, 2.66666667], 651 [ 0.0, 1.0], 652 [ 0.0, 3.0], 653 [ 1.0, 0.0], 654 [ 1.0, 1.0], 655 [ 1.0, 2.0], 656 [ 1.0, 3.0], 657 [ 2.0, 1.0], 658 [ 3.0, 0.0], 659 [ 3.0, 1.0]] 660 661 #Fit surface to mesh 662 interp = Interpolation(points, triangles, data_points1, alpha=0.0) 663 z = linear_function(data_points1) #Example z-values 664 f = interp.fit(z) #Fitted values at vertices 665 666 667 668 #New datapoints where interpolated values are sought 669 data_points2 = [[ 0.0, 0.0], 670 [ 0.5, 0.5], 671 [ 0.7, 0.7], 672 [ 1.0, 0.5], 673 [ 2.0, 0.4], 674 [ 2.8, 1.2]] 675 676 677 #Build new A matrix based on new points 678 interp.build_interpolation_matrix_A(data_points2) 679 680 #Interpolate using fitted surface 681 z1 = interp.interpolate(f) 682 683 #Desired result 684 answer = linear_function(data_points2) 685 assert allclose(z1, answer) 686 687 688 624 689 625 690 def test_fit_to_mesh_file(self): … … 726 791 #------------------------------------------------------------- 727 792 if __name__ == "__main__": 793 #suite = unittest.makeSuite(TestCase,'test') 794 728 795 suite = unittest.makeSuite(TestCase,'test') 729 796 runner = unittest.TextTestRunner(verbosity=1)
Note: See TracChangeset
for help on using the changeset viewer.