~ubuntu-branches/ubuntu/saucy/python-scipy/saucy

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Ondrej Certik
  • Date: 2008-06-16 22:58:01 UTC
  • mfrom: (2.1.24 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080616225801-irdhrpcwiocfbcmt
Tags: 0.6.0-12
* The description updated to match the current SciPy (Closes: #489149).
* Standards-Version bumped to 3.8.0 (no action needed)
* Build-Depends: netcdf-dev changed to libnetcdf-dev

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 numpy.testing import *
17
 
from numpy import array
18
 
set_package_path()
19
 
from interpolate.fitpack2 import UnivariateSpline,LSQUnivariateSpline,\
20
 
     InterpolatedUnivariateSpline
21
 
from interpolate.fitpack2 import LSQBivariateSpline, SmoothBivariateSpline,\
22
 
     RectBivariateSpline
23
 
restore_path()
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
 
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)
85
 
 
86
 
if __name__ == "__main__":
87
 
    ScipyTest().run()