[SciPy-dev] interpolate

Stefan van der Walt stefan at sun.ac.za
Tue Jan 10 06:31:49 CST 2006


In scipy, interpolate.interp2d is currently broken.  The scipy
tutorial shows an interpolation example which uses bisplev en
bisplrep.

Is there any reason why these functions can't be used in interp2d?
The attached patch calls those functions like in the tutorial.

Stéfan
-------------- next part --------------
--- /home/stefan/work/scipy/scipy/Lib/interpolate/interpolate.py	2005-12-06 11:34:43.000000000 +0200
+++ interpolate.py	2005-12-06 15:30:27.000000000 +0200
@@ -42,7 +42,7 @@
         Input:
           x,y  - 1-d arrays defining 2-d grid (or 2-d meshgrid arrays)
           z    - 2-d array of grid values
-          kind - interpolation type ('nearest', 'linear', 'cubic', 'spline')
+          kind - interpolation type ('linear', 'cubic', 'spline')
           copy - if true then data is copied into class, otherwise only a
                    reference is held.
           bounds_error - if true, then when out_of_bounds occurs, an error is
@@ -51,6 +51,10 @@
           fill_value - if None, then NaN, otherwise the value to fill in
                         outside defined region.
         """
+        degree = {'linear' : 1,
+                  'cubic'  : 2,
+                  'spline' : 3}
+        
         self.x = atleast_1d(x).copy()
         self.y = atleast_1d(y).copy()
         if rank(self.x) > 2 or rank(self.y) > 2:
@@ -62,9 +66,10 @@
         self.z = array(z,copy=True)
         if rank(z) != 2:
             raise ValueError, "Grid values is not a 2-d array."
+        if kind not in degree:
+            raise ValueError, "Invalid kind of interpolation requested."
 
-
-        
+        self.tck = fitpack.bisplrep(x, y, z, kx=degree[kind], ky=degree[kind])
 
     def __call__(self,x,y,dx=0,dy=0):
         """


More information about the Scipy-dev mailing list