~ubuntu-branches/ubuntu/karmic/python-scipy/karmic

« back to all changes in this revision

Viewing changes to Lib/interpolate/tests/test_fitpack.py

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T. Chen (new)
  • Date: 2005-03-16 02:15:29 UTC
  • Revision ID: james.westby@ubuntu.com-20050316021529-xrjlowsejs0cijig
Tags: upstream-0.3.2
ImportĀ upstreamĀ versionĀ 0.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# Created by Pearu Peterson, June 2003
 
3
""" Test functions for interpolate.fitpack2 module
 
4
"""
 
5
__usage__ = """
 
6
Build interpolate:
 
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>]
 
12
"""
 
13
#import libwadpy
 
14
 
 
15
import sys
 
16
from scipy_test.testing import *
 
17
set_package_path()
 
18
from interpolate.fitpack2 import UnivariateSpline,LSQUnivariateSpline,\
 
19
     InterpolatedUnivariateSpline
 
20
from interpolate.fitpack2 import LSQBivariateSpline, SmoothBivariateSpline
 
21
del sys.path[0]
 
22
 
 
23
import unittest
 
24
 
 
25
class test_UnivariateSpline(ScipyTestCase):
 
26
    def check_linear_constant(self):
 
27
        x = [1,2,3]
 
28
        y = [3,3,3]
 
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])
 
34
 
 
35
    def check_linear_1d(self):
 
36
        x = [1,2,3]
 
37
        y = [0,2,4]
 
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])
 
43
 
 
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]
 
49
        s = 0.1
 
50
        tx = [1+s,3-s]
 
51
        ty = [1+s,3-s]
 
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()
 
56
 
 
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]])
 
67
 
 
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]])
 
77
 
 
78
if __name__ == "__main__":
 
79
    ScipyTest('interpolate.fitpack').run()