I have an x array and an y array containing column indices and rows of function v defined on a grid. I want to calculate a function on another grid (say, xnew and ynew), which is essentially the first grid, alternating again and again, possibly with a coarser distance between the grids. This is an example of what I am trying to do when the interval is the same:
from scipy import interpolate
import numpy as np
N=10
a=np.arange(N)
b=np.arange(N)
Xax,Yax=np.meshgrid(a,b)
v=np.sin(Xax+Yax)
f=interpolate.interp2d(Xax,Yax,v)
xnew=np.mod(np.arange(100),N)
ynew=np.mod(np.arange(100),N)
vnew=f(xnew,ynew)
I get the following error in IPython
ValueError Traceback (most recent call last)
<ipython-input-51-83ec5c3d24a5> in <module>()
/usr/lib/python2.7/dist-packages/scipy/interpolate/interpolate.pyc in __call__(self,x,y,dx,dy)
185 x = atleast_1d(x)
186 y = atleast_1d(y)
188 z = atleast_2d(z)
189 z = transpose(z)
/usr/lib/python2.7/dist-packages/scipy/interpolate/fitpack.pyc in bisplev(x, y, tck, dx, dy)
962 z,ier=_fitpack._bispev(tx,ty,c,kx,ky,x,y,dx,dy)
963 if ier==10:
965 if ier:
966 raise TypeError("An error occurred")
ValueError: Invalid input data
I think the problem is that the second array is larger than the first, as this works:
vnew=f(xnew[:N],ynew[:N])
One way to solve the problem would be to create an entire interleaved array, but it would be a large array, which I am trying to avoid. All points of my example are in a cell, any idea how to implement interpolation?