2
# Created by Pearu Peterson, June 2003
3
""" Test functions for interpolate.fitpack2 module
7
python setup_interpolate.py build
8
Run tests if scipy is installed:
9
python -c 'import scipy;scipy.interpolate.test(<level>)'
10
Run tests if interpolate is not installed:
11
python tests/test_fitpack.py [<level>]
16
from numpy.testing import *
17
from numpy import array
19
from interpolate.fitpack2 import UnivariateSpline,LSQUnivariateSpline,\
20
InterpolatedUnivariateSpline
21
from interpolate.fitpack2 import LSQBivariateSpline, SmoothBivariateSpline,\
25
class test_UnivariateSpline(ScipyTestCase):
26
def check_linear_constant(self):
29
lut = UnivariateSpline(x,y,k=1)
30
assert_array_almost_equal(lut.get_knots(),[1,3])
31
assert_array_almost_equal(lut.get_coeffs(),[3,3])
32
assert_almost_equal(lut.get_residual(),0.0)
33
assert_array_almost_equal(lut([1,1.5,2]),[3,3,3])
35
def check_linear_1d(self):
38
lut = UnivariateSpline(x,y,k=1)
39
assert_array_almost_equal(lut.get_knots(),[1,3])
40
assert_array_almost_equal(lut.get_coeffs(),[0,4])
41
assert_almost_equal(lut.get_residual(),0.0)
42
assert_array_almost_equal(lut([1,1.5,2]),[0,1,2])
44
class test_LSQBivariateSpline(ScipyTestCase):
45
def check_linear_constant(self):
46
x = [1,1,1,2,2,2,3,3,3]
47
y = [1,2,3,1,2,3,1,2,3]
48
z = [3,3,3,3,3,3,3,3,3]
52
lut = LSQBivariateSpline(x,y,z,tx,ty,kx=1,ky=1)
53
#print lut.get_knots()
54
#print lut.get_coeffs()
55
#print lut.get_residual()
57
class test_SmoothBivariateSpline(ScipyTestCase):
58
def check_linear_constant(self):
59
x = [1,1,1,2,2,2,3,3,3]
60
y = [1,2,3,1,2,3,1,2,3]
61
z = [3,3,3,3,3,3,3,3,3]
62
lut = SmoothBivariateSpline(x,y,z,kx=1,ky=1)
63
assert_array_almost_equal(lut.get_knots(),([1,1,3,3],[1,1,3,3]))
64
assert_array_almost_equal(lut.get_coeffs(),[3,3,3,3])
65
assert_almost_equal(lut.get_residual(),0.0)
66
assert_array_almost_equal(lut([1,1.5,2],[1,1.5]),[[3,3],[3,3],[3,3]])
68
def check_linear_1d(self):
69
x = [1,1,1,2,2,2,3,3,3]
70
y = [1,2,3,1,2,3,1,2,3]
71
z = [0,0,0,2,2,2,4,4,4]
72
lut = SmoothBivariateSpline(x,y,z,kx=1,ky=1)
73
assert_array_almost_equal(lut.get_knots(),([1,1,3,3],[1,1,3,3]))
74
assert_array_almost_equal(lut.get_coeffs(),[0,0,4,4])
75
assert_almost_equal(lut.get_residual(),0.0)
76
assert_array_almost_equal(lut([1,1.5,2],[1,1.5]),[[0,0],[1,1],[2,2]])
78
class test_RectBivariateSpline(ScipyTestCase):
79
def check_defaults(self):
80
x = array([1,2,3,4,5])
81
y = array([1,2,3,4,5])
82
z = array([[1,2,1,2,1],[1,2,1,2,1],[1,2,3,2,1],[1,2,2,2,1],[1,2,1,2,1]])
83
lut = RectBivariateSpline(x,y,z)
84
assert_array_almost_equal(lut(x,y),z)
86
if __name__ == "__main__":