[SciPy-User] Interpolation in 3D with interp2d
Zachary Pincus
zachary.pincus@yale....
Wed Aug 4 14:40:54 CDT 2010
> Sun, 01 Aug 2010 21:25:37 +0200, Jana Schulz wrote:
>> I'm trying to interpolate a 3D data (from the pic attached) with the
>> interp2d command. What I have, are three vectors f, z, A (x, y, z
>> respectively, A is the percentage data given on the isolines). I
>> first
>> put the f and z in a meshgrid and afterwards pruduced a mesh with
>> the A
>> vector then started to interpolate.
>
> This sounds like you are trying to use `interp2d` for something it
> does
> not do -- it requires that your data is already gridded.
>
> So let's clarify: you have points (f[i], z[i]), and function values
> A[i].
> The points (f[i], z[i]) do not form a regular grid. If yes, then you
> almost certainly are looking for the `griddata` function:
>
>>>> from matplotlib.mlab import griddata
>
> Or possibly, you could also try to use splines:
>
>>>> from scipy.intepolate import SmoothBivariateSpline
>>>> int2d = SmoothBivariateSpline(f, z, A, s=0)
>>>> intnew = int2d(ef, ez)
>
> Mind the `s=0` -- otherwise it will try to smooth your data.
> However, if
> your data point distribution is irregular, the spline method will
> likely
> produce bad results -- they're OK for smoothing, but not so nice for
> data
> regridding.
See also:
http://www.scipy.org/Cookbook/RadialBasisFunctions
and the delaunay scikit, both of which deal directly with
interpolating scattered data, if you don't necessarily need to
interpolate on a complete grid. (The griddata function uses these
methods under the hood, I think.)
Zach
More information about the SciPy-User
mailing list