Interpolation in 2D...

Hi,

I know this may be a question for scipy or numarray but since matplotlib is using something close to what I wish to have..., here is the question:

- I would like to use some 2D interpolation of a set of x, y, z points (not regularly positioned). If possible I would like to test various interpolation schemes (bilinear, splines, etc), and have a FLAG to tell me if I am trying to EXTRAPOLATE (so that I can control the output). I looked at scipy but this is really bad: as far as I understand the doc mentions that it takes 1D array (what I want), but in fact works on 2D arrays (NOT what I want).... (and it only provides splines)

I know that imshow has this built in with many different options for the visualisation. So how is this done? Is it hard coded in one of the matplotlib routine ? Could not find it there...

thanks for the help

Eric Emsellem

···

--

Observatoire de Lyon emsellem@...419...
9 av. Charles-Andre tel: +33 4 78 86 83 84
69561 Saint-Genis Laval Cedex fax: +33 4 78 86 83 86
France http://www-obs.univ-lyon1.fr/eric.emsellem

- I would like to use some 2D interpolation of a set of x, y, z points (not regularly positioned). If possible I would like to test various interpolation schemes (bilinear, splines, etc), and have a FLAG to tell me if I am trying to EXTRAPOLATE (so that I can control the output). I looked at scipy but this is really bad: as far as I understand the doc mentions that it takes 1D array (what I want), but in fact works on 2D arrays (NOT what I want).... (and it only provides splines)

You have at least 2 general approaches: Delaunay triangulation and splines. Straight Delaunay triangulation would be linear interpolation, but can be embellished with fancier interpolation techniques. As far as I know, Delaunay triangulation and associated interpolation routines are not (yet) available in scipy. Surface splines are available in scipy -- check out bisplrep/bisplev.

As far as a FLAG to tell if you want to EXTRAPOLATE, I don't know. They may not be in ALL CAPS, either, so read the fine print. :slight_smile:

I know that imshow has this built in with many different options for the visualisation. So how is this done? Is it hard coded in one of the matplotlib routine ? Could not find it there...

I don't think imshow does anything as fancy as what you suggest. The contour routines are more sophisticated and may be useful to you, but I haven't followed how they work.

···

On Jul 19, 2005, at 2:17 AM, Eric Emsellem wrote:

Hi
thanks for the input, however scipy interpolation scheme is on a regular grid.

The positions I have are not even on an ORTHOGONAL grid: they are randomly distributed!
So I have a set of x,y random positions with Z values and I wish to know the interpolated value
at a new position xnew, ynew...

It seems that this does not exist in scipy. Someone pointed out Scientific Python but this again does not work
(using irregular but orthogonal grids)...

This would be pretty bad if I cannot do this in python!!!

Any help welcome!

Cheers
Eric

Eric Emsellem wrote:

···

Hi,

I know this may be a question for scipy or numarray but since matplotlib is using something close to what I wish to have..., here is the question:

- I would like to use some 2D interpolation of a set of x, y, z points (not regularly positioned). If possible I would like to test various interpolation schemes (bilinear, splines, etc), and have a FLAG to tell me if I am trying to EXTRAPOLATE (so that I can control the output). I looked at scipy but this is really bad: as far as I understand the doc mentions that it takes 1D array (what I want), but in fact works on 2D arrays (NOT what I want).... (and it only provides splines)

I know that imshow has this built in with many different options for the visualisation. So how is this done? Is it hard coded in one of the matplotlib routine ? Could not find it there...

thanks for the help

Eric Emsellem

On Jul 19, 2005, at 2:17 AM, Eric Emsellem wrote:

> - I would like to use some 2D interpolation of a set of x, y, z points > (not regularly positioned). If possible I would like to test various > interpolation schemes (bilinear, splines, etc), and have a FLAG to > tell me if I am trying to EXTRAPOLATE (so that I can control the > output). I looked at scipy but this is really bad: as far as I > understand the doc mentions that it takes 1D array (what I want), but > in fact works on 2D arrays (NOT what I want).... (and it only provides > splines)

You have at least 2 general approaches: Delaunay triangulation and splines. Straight Delaunay triangulation would be linear interpolation, but can be embellished with fancier interpolation techniques. As far as I know, Delaunay triangulation and associated interpolation routines are not (yet) available in scipy. Surface splines are available in scipy -- check out bisplrep/bisplev.

As far as a FLAG to tell if you want to EXTRAPOLATE, I don"t know. They may not be in ALL CAPS, either, so read the fine print. :slight_smile:

> I know that imshow has this built in with many different options for > the visualisation. So how is this done? Is it hard coded in one of the > matplotlib routine ? Could not find it there...

I don"t think imshow does anything as fancy as what you suggest. The contour routines are more sophisticated and may be useful to you, but I haven"t followed how they work.

--

Observatoire de Lyon emsellem@...419...
9 av. Charles-Andre tel: +33 4 78 86 83 84
69561 Saint-Genis Laval Cedex fax: +33 4 78 86 83 86
France http://www-obs.univ-lyon1.fr/eric.emsellem

I do this in python/matplotlib using hardy's multiquadric interpolation.... I've posted here before promising to attach some code, but haven't done so yet, since really need to clean things up a little. Will try to get it done on my 10 hour flight tonight... and post within the next few days...

Cheers,
Peter

Eric Emsellem wrote:

···

Hi
thanks for the input, however scipy interpolation scheme is on a regular grid.

The positions I have are not even on an ORTHOGONAL grid: they are randomly distributed!
So I have a set of x,y random positions with Z values and I wish to know the interpolated value
at a new position xnew, ynew...

It seems that this does not exist in scipy. Someone pointed out Scientific Python but this again does not work
(using irregular but orthogonal grids)...

This would be pretty bad if I cannot do this in python!!!

Any help welcome!

Cheers
Eric

Eric Emsellem wrote:

Hi,

I know this may be a question for scipy or numarray but since matplotlib is using something close to what I wish to have..., here is the question:

- I would like to use some 2D interpolation of a set of x, y, z points (not regularly positioned). If possible I would like to test various interpolation schemes (bilinear, splines, etc), and have a FLAG to tell me if I am trying to EXTRAPOLATE (so that I can control the output). I looked at scipy but this is really bad: as far as I understand the doc mentions that it takes 1D array (what I want), but in fact works on 2D arrays (NOT what I want).... (and it only provides splines)

I know that imshow has this built in with many different options for the visualisation. So how is this done? Is it hard coded in one of the matplotlib routine ? Could not find it there...

thanks for the help

Eric Emsellem

On Jul 19, 2005, at 2:17 AM, Eric Emsellem wrote:

> - I would like to use some 2D interpolation of a set of x, y, z points > (not regularly positioned). If possible I would like to test various > interpolation schemes (bilinear, splines, etc), and have a FLAG to > tell me if I am trying to EXTRAPOLATE (so that I can control the > output). I looked at scipy but this is really bad: as far as I > understand the doc mentions that it takes 1D array (what I want), but > in fact works on 2D arrays (NOT what I want).... (and it only provides > splines)

You have at least 2 general approaches: Delaunay triangulation and splines. Straight Delaunay triangulation would be linear interpolation, but can be embellished with fancier interpolation techniques. As far as I know, Delaunay triangulation and associated interpolation routines are not (yet) available in scipy. Surface splines are available in scipy -- check out bisplrep/bisplev.

As far as a FLAG to tell if you want to EXTRAPOLATE, I don"t know. They may not be in ALL CAPS, either, so read the fine print. :slight_smile:

> I know that imshow has this built in with many different options for > the visualisation. So how is this done? Is it hard coded in one of the > matplotlib routine ? Could not find it there...

I don"t think imshow does anything as fancy as what you suggest. The contour routines are more sophisticated and may be useful to you, but I haven"t followed how they work.

--
Peter Groszkowski Gemini Observatory
Tel: +1 808 9742509 670 N. A'ohoku Place
Fax: +1 808 9359235 Hilo, Hawai'i 96720, USA

Andrew Straw wrote:

You have at least 2 general approaches: Delaunay triangulation and splines. Straight Delaunay triangulation would be linear interpolation, but can be embellished with fancier interpolation techniques. As far as I know, Delaunay triangulation and associated interpolation routines are not (yet) available in scipy.

I don't think they are. I've been planning to write python wrappers for
Jonathan Shewchuk's triangle code, but if someone wanted to beat me to
it....

http://www-2.cs.cmu.edu/~quake/triangle.html

Surface splines are available in scipy -- check out bisplrep/bisplev.

Can you do surface splines with irregularly spaced points?

The
contour routines are more sophisticated and may be useful to you, but I haven't followed how they work.

I'm pretty sure they require regularly spaced points as well. Or at
least "logically Cartesian" points.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...259...

Eric Emsellem wrote:

Hi,

I know this may be a question for scipy or numarray but since matplotlib is using something close to what I wish to have..., here is the question:

- I would like to use some 2D interpolation of a set of x, y, z points (not regularly positioned). If possible I would like to test various interpolation schemes (bilinear, splines, etc), and have a FLAG to tell me if I am trying to EXTRAPOLATE (so that I can control the output). I looked at scipy but this is really bad: as far as I understand the doc mentions that it takes 1D array (what I want), but in fact works on 2D arrays (NOT what I want).... (and it only provides splines)

I know that imshow has this built in with many different options for the visualisation. So how is this done? Is it hard coded in one of the matplotlib routine ? Could not find it there...

thanks for the help

Eric Emsellem

Eric: There are a couple of modules in CDAT (http://cdat.sf.net) to do this. See

http://rainbow.llnl.gov/software/cdat/support/cdat_utilities/cdat_utilities-3.php

Look for the 'ngmath' module. I've found that ngmath.natgrid works quite well. Here's a quick description from the docstring:

"natgrid - a two-dimensional random data interpolation package based on Dave Watson's nngridr."

-Jeff

···

--
Jeffrey S. Whitaker Phone : (303)497-6313
Meteorologist FAX : (303)497-6449
NOAA/OAR/CDC R/CDC1 Email : Jeffrey.S.Whitaker@...259...
325 Broadway Office : Skaggs Research Cntr 1D-124
Boulder, CO, USA 80303-3328 Web : Jeffrey S. Whitaker: NOAA Physical Sciences Laboratory