[SciPy-User] [SciPy-user] mgrid format from unstructured data
Peter Combs
peter.combs@berkeley....
Tue Mar 1 05:51:04 CST 2011
On Feb 23, 2011, at 1:49 AM, Spiffalizer wrote:
> I have found some examples that looks like this
> x,y = np.mgrid[-1:1:10j,-1:1:10j]
> z = (x+y)*np.exp(-6.0*(x*x+y*y))
> xnew,ynew = np.mgrid[-1:1:3j,-1:1:3j]
> tck = interpolate.bisplrep(x,y,z,s=0)
> znew = interpolate.bisplev(xnew[:,0],ynew[0,:],tck)
>
>
> So my question really is how to sort/convert my input to a format that can
> be used by the interpolate function?
I use the LSQBivariateSpline functions:
import numpy as np
import scipy.interpolate as interp
num_knots = int(floor(sqrt(len(z))))
xknots = np.linspace(xmin, xmax, n)
yknots = np.linspace(ymin, ymax, n)
interpolator = interp.LSQBivariateSpline(x, y, z, xknots, yknots)
znew = interpolator.ev(xnew, ynew)
The object orientation is useful for my applications, for reasons that I no longer quite remember. Looking through the documentation for bisplrep, though, it doesn't seem like you need to worry about the order that the points are in. You might try something like:
xknots = list(set(x))
yknots = list(set(y))
tck = interpolate.bisplrep(x,y,z, task=-1, tx = xknots, ty=yknots)
but my understanding of the bisplrep function is hazy at best, so probably best to check it with data you already know the answer.
Peter Combs
peter.combs@berkeley.edu
More information about the SciPy-User
mailing list