#!/usr/bin/env python #TEST import sys import unittest from math import sqrt from spike_least_squares import * from Numeric import allclose, array, transpose from Numeric import zeros, take, compress, array, Float, Int, dot, transpose, concatenate, ArrayType from utilities.sparse import Sparse, Sparse_CSR from coordinate_transforms.geo_reference import Geo_reference def distance(x, y): return sqrt( sum( (array(x)-array(y))**2 )) def linear_function(point): point = array(point) return point[:,0]+point[:,1] class Test_Least_Squares(unittest.TestCase): def setUp(self): pass def tearDown(self): pass def test_smooth_attributes_to_mesh(self): a = [0.0, 0.0] b = [0.0, 5.0] c = [5.0, 0.0] points = [a, b, c] triangles = [ [1,0,2] ] #bac d1 = [1.0, 1.0] d2 = [1.0, 3.0] d3 = [3.0,1.0] z1 = 2 z2 = 4 z3 = 4 data_coords = [d1, d2, d3] z = [z1, z2, z3] interp = Interpolation(points, triangles, z,data_coords, alpha=0) #print "interp.get_A()", interp.get_A() A = interp.A #print "A",A #print "z",z Atz = A.trans_mult(z) #print "Atz",Atz f = interp.fit(z) answer = [0, 5., 5.] #print "f\n",f #print "answer\n",answer assert allclose(f, answer, atol=1e-7) #------------------------------------------------------------- if __name__ == "__main__": suite = unittest.makeSuite(Test_Least_Squares,'test') #suite = unittest.makeSuite(Test_Least_Squares,'test_smoothing_and_interpolation') #suite = unittest.makeSuite(Test_Least_Squares,'test_smooth_attributes_to_mesh_one_point') runner = unittest.TextTestRunner(verbosity=1) runner.run(suite)