[SciPy-Dev] SciPy-Dev Digest, Vol 92, Issue 9

Pauli Virtanen pav at iki.fi
Mon Jun 13 12:57:15 EDT 2011


On Mon, 13 Jun 2011 09:32:31 +0700, Ole Nielsen wrote:
[clip]
> Meanwhile, if you could tell me where the LinearNDInterpolator package can be found?

See the link I posted earlier:

    http://docs.scipy.org/doc/scipy/reference/interpolate.html

It's not a separate package, but a part of Scipy 0.9. Usage for your case:

--------------------
# some data on a grid, containing nans
x = np.linspace(0, 1, 20)
y = np.linspace(0, 1, 30)
z = np.cos(x[:,None]) + np.sin(y[None,:])
z[np.random.rand(*z.shape) > 0.9] = np.nan

# flatten grid data to (x, y, z) point list
xx = (x[:,None] + 0*y[None,:]).ravel()
yy = (0*x[:,None] + y[None,:]).ravel()
zz = z.ravel()

# filter out nans
m = np.isnan(zz)
xx = xx[~m]
yy = yy[~m]
zz = zz[~m]

# new grid
xi = np.linspace(0, 1, 100)
yi = np.linspace(0, 1, 200)

# interpolate onto new grid
zi = scipy.interpolate.griddata((xx, yy), zz, (xi[:,None], yi[None,:]))
--------------------

It's linear interpolation, so it will not overshoot. However, the result
depends on how the Delaunay triangulation of the point set looks like,
so to most natural results, you need to ensure that the `x` and `y` axes
are scaled so that the euclidean distance `sqrt(x^2 + y^2)` means something
natural.

Also, the performance if perhaps not completely optimal for very large data
sets, as it needs to construct the triangulation first.


-- 
Pauli Virtanen




More information about the SciPy-Dev mailing list