[SciPy-user] Help with 2D interpolation
Ryan May
rmay31 at gmail.com
Sun Jun 22 17:45:38 EDT 2008
Hi,
Can anyone explain why this won't work:
import numpy as np
import scipy.interpolate as interp
from scipy.interpolate.fitpack2 import SmoothBivariateSpline
import matplotlib.pyplot as plt
x = np.linspace(-10, 10, 25)
y = np.linspace(-15, 15, 50)
X,Y = np.meshgrid(x,y)
Z = 1.5 * X**2 + 0.5 * Y**2
#tck = interp.bisplrep(X, Y, Z)
#z = interp.bisplev(X.flatten(), Y.flatten(), tck)
lut = SmoothBivariateSpline(X.ravel(), Y.ravel(), Z.ravel())
z = lut(X.ravel(), Y.ravel())
fig = plt.figure()
ax1 = fig.add_subplot(1,2,1)
ax1.pcolor(X,Y,Z)
ax1.set_title('Original')
ax2 = fig.add_subplot(1,2,2)
ax2.pcolor(X,Y,z.reshape(Z.shape))
ax2.set_title('Interpolated')
plt.show()
I get this error with scipy 0.6:
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
/home/rmay/pypkg/scattering/test/test_interp.py in <module>()
14
15 lut = SmoothBivariateSpline(X.ravel(), Y.ravel(), Z.ravel())
---> 16 z = lut(X.ravel(), Y.ravel())
17
18 fig = plt.figure()
/usr/lib64/python2.5/site-packages/scipy/interpolate/fitpack2.py in
__call__(self, x, y, mth)
350 kx,ky = self.degrees
351 z,ier = dfitpack.bispev(tx,ty,c,kx,ky,x,y)
--> 352 assert ier==0,'Invalid input: ier='+`ier`
353 return z
354 raise NotImplementedError
Any takers?
Ryan
--
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma
More information about the SciPy-User
mailing list