source: inundation/fit_interpolate/test_fit.py @ 2879

Last change on this file since 2879 was 2802, checked in by duncan, 19 years ago

adding the fit class

File size: 1.8 KB
Line 
1#!/usr/bin/env python
2
3#TEST
4import sys
5import unittest
6from math import sqrt
7
8
9from spike_least_squares import *
10from Numeric import allclose, array, transpose
11from Numeric import zeros, take, compress, array, Float, Int, dot, transpose, concatenate, ArrayType
12from utilities.sparse import Sparse, Sparse_CSR
13
14from coordinate_transforms.geo_reference import Geo_reference
15
16def distance(x, y):
17    return sqrt( sum( (array(x)-array(y))**2 ))
18
19def linear_function(point):
20    point = array(point)
21    return point[:,0]+point[:,1]
22
23
24class Test_Least_Squares(unittest.TestCase):
25
26    def setUp(self):
27        pass
28
29    def tearDown(self):
30        pass
31
32    def test_smooth_attributes_to_mesh(self):
33        a = [0.0, 0.0]
34        b = [0.0, 5.0]
35        c = [5.0, 0.0]
36        points = [a, b, c]
37        triangles = [ [1,0,2] ]   #bac
38
39        d1 = [1.0, 1.0]
40        d2 = [1.0, 3.0]
41        d3 = [3.0,1.0]
42        z1 = 2
43        z2 = 4
44        z3 = 4
45        data_coords = [d1, d2, d3]
46
47        z = [z1, z2, z3]
48        interp = Interpolation(points, triangles, z,data_coords, alpha=0)
49        #print "interp.get_A()", interp.get_A()
50        A = interp.A
51        #print "A",A
52        #print "z",z
53        Atz = A.trans_mult(z)
54        #print "Atz",Atz
55       
56        f = interp.fit(z)
57        answer = [0, 5., 5.]
58
59        #print "f\n",f
60        #print "answer\n",answer
61
62        assert allclose(f, answer, atol=1e-7)
63
64       
65#-------------------------------------------------------------
66if __name__ == "__main__":
67    suite = unittest.makeSuite(Test_Least_Squares,'test')
68    #suite = unittest.makeSuite(Test_Least_Squares,'test_smoothing_and_interpolation')
69    #suite = unittest.makeSuite(Test_Least_Squares,'test_smooth_attributes_to_mesh_one_point')
70    runner = unittest.TextTestRunner(verbosity=1)
71    runner.run(suite)
72
73
74
75
76
Note: See TracBrowser for help on using the repository browser.