[Scipy-svn] r4596 - in branches/Interpolate1D: . tests
scipy-svn@scip...
scipy-svn@scip...
Mon Aug 4 09:37:47 CDT 2008
Author: fcady
Date: 2008-08-04 09:37:45 -0500 (Mon, 04 Aug 2008)
New Revision: 4596
Modified:
branches/Interpolate1D/fitpack_wrapper2d.py
branches/Interpolate1D/tests/test_fitpack_wrapper2d.py
Log:
all tests, including those for 2D interpolation, are passing
Modified: branches/Interpolate1D/fitpack_wrapper2d.py
===================================================================
--- branches/Interpolate1D/fitpack_wrapper2d.py 2008-08-01 23:34:03 UTC (rev 4595)
+++ branches/Interpolate1D/fitpack_wrapper2d.py 2008-08-04 14:37:45 UTC (rev 4596)
@@ -113,7 +113,7 @@
self._is_initialized = True
def __call__(self, x, y):
- """ Evaluate spline at positions x[i],y[i].
+ """ Evaluate spline at positions (x[i], y[i]).
x and y should be 1d arrays.
If (xi, yi) is outside the interpolation range, it will be
@@ -123,6 +123,11 @@
if self._is_initialized is not True:
raise Error, "x, y and z must be initialized before interpolating"
+
+ # check input format
+ assert isinstance(x, np.ndarray) and isinstance(y, np.ndarray), \
+ "newx and newy must both be numpy arrays"
+ assert len(x) == len(y), "newx and newy must be of the same length"
# sort only once for efficiency
sorted_x = sorted(x)
@@ -143,6 +148,11 @@
if self._is_initialized is not True:
raise Error, "x, y and z must be initialized before interpolating"
+ # check input format
+ assert isinstance(x, np.ndarray) and isinstance(y, np.ndarray), \
+ "newx and newy must both be numpy arrays"
+ assert len(x) == len(y), "newx and newy must be of the same length"
+
tx,ty,c = self.tck[:3]
kx,ky = self.degrees
z,ier = _dfitpack.bispev(tx,ty,c,kx,ky,x,y)
Modified: branches/Interpolate1D/tests/test_fitpack_wrapper2d.py
===================================================================
--- branches/Interpolate1D/tests/test_fitpack_wrapper2d.py 2008-08-01 23:34:03 UTC (rev 4595)
+++ branches/Interpolate1D/tests/test_fitpack_wrapper2d.py 2008-08-04 14:37:45 UTC (rev 4596)
@@ -75,24 +75,13 @@
Z = X + Y
x, y, z = map(ravel, [X, Y, Z])
- newx = arange(N+8) +.5
- newy = 2*newx
-
interp_func = Spline2d(x, y, z, kx=1, ky=1)
- newz = interp_func(newx, newy)
- print "newx: ", newx
- print "newy: ", newy
- print "sum : ", newx+newy
- print "newz: ", newz
+ # upper-right region of R2
+ self.assertAllclose(interp_func(np.array([N+1.]),np.array([N+1.])) , 2*N-2)
- print "Homer Simpson"
- print interp_func(array([-2.0]),array([3.5]))
- print interp_func(array([-7.0]),array([3.5]))
- print interp_func(array([-2.0]),array([7]))
- print "Bartman"
-
- self.assertAllclose(newz, newx+newy)
+ # directly above interpolation region; only extrapolating in one variable
+ self.assertAllclose(interp_func(np.array([N])/2.,2.*np.array([N])) , N/2. + (N-1.))
def runTest(self):
test_list = [name for name in dir(self) if name.find('test_')==0]
More information about the Scipy-svn
mailing list