[SciPy-user] 2D interpolation containing missing values

Robert Kern robert.kern@gmail....
Thu Feb 28 23:51:00 CST 2008


On Wed, Feb 27, 2008 at 4:27 PM, Jesper Larsen <jesper.webmail@gmail.com> wrote:
> Hi SciPy users,
>
>  I would like to interpolate data from a 2D irregular grid to a limited
>  number of points. The input data is defined by: a 2D longitude array,
>  a 2D latitude array and a 2D array containing the data values. The
>  data array is a numpy masked array (numpy.ma) and may contain masked
>  out values. It can for example represent an ocean temperature field
>  which is masked out at land points. If a land point is included in the
>  interpolation to one of the output points I would like the result to
>  be nan or something else identifiable so that I can mask it out.
>
>  I have tried to do the interpolation using the delaunay package.
>  Unfortunately it does not seem to be able to handle masked arrays. I
>  have therefore ended up with a solution in which I only keep the
>  non-masked values of the data in the interpolation. The result of this
>  is that land values are interpolated from the nearest ocean values. I
>  can of course mask out these values afterwards by finding the nearest
>  point in my input data array and check if it is masked. But that is
>  probably not very effective and I was wondering if anyone has a better
>  solution?

That's pretty much how I would do it. One trick you might try is to
interpolate a dataset which is 0.0 on land and 1.0 on ocean. If you
use the linear interpolator rather than the natural-neighbor
interpolator, an interpolated value of 1.0 will occur only when the
point is entirely contained in a triangle whose points are all ocean
in the Delaunay triangulation. Treat 0.0 as land, 1.0 as ocean, and
make decision about what to do with the values in between.

This will only work if you have actually sampled the land point
sufficiently in the triangulation. If you only have ocean points, then
everything in the convex hull of the ocean points will be considered
ocean, which is almost certainly not what you want.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco


More information about the SciPy-user mailing list