Replacing matplotlib.delaunay natural neighbor interpolation

Hi all,

I'm writing regarding an issue I'm having porting the yt package to
properly handle some of the changes in matplotlib 1.4.

yt is a python library for analysis and visualization of volumetric
data, with a focus on astrophysical simulation datasets. We use
matplotlib heavily for visualization tasks.

For a while now, we've been using the natural neighbor interpolation
in matplotlib.delaunay to generate contour plots from image data. See
for example, this function:

https://bitbucket.org/yt_analysis/yt/src/84b551a47ac462d646963f0b13e4dd0e85bd9751/yt/visualization/plot_modifications.py?at=yt#cl-311

In this example, self.triang is an instance of
matplotlib.delaunay.triangulate.Triangulation.

The bug report I opened regarding this issue might also be informative:

https://bitbucket.org/yt_analysis/yt/issue/764/matplotlibdelaunay-deprecated-in

I'm writing because it seems that matplotlib.delaunay was deprecated
recently. This means users who import the yt plotting code will see a
DeprecationWarning if they are running the upcoming matplotlib 1.4
release -- definitely an undesirable situation.

Unfortunately, it looks like the workaround for this issue is to use
natgrid to generate the interpolation. This is undesirable from our
point of view since we have no way in general to control how users build their
matplotlib installation.

I'm curious whether any of the matplotlib developers have alternate
ideas for how to do deal with this.

Thanks for your help!

-Nathan Goldbaum

Hi Nathan,

To deal with your immediate problem of not wanting to see the deprecation warnings you can continue to use matplotlib.delaunay and suppress the warnings using e.g. http://docs.python.org/2/library/warnings.html#temporarily-suppressing-warnings. This will be OK for a year or two, but eventually we will completely remove matplotlib.delaunay. It will however give you time to come up with a solution.

The short answer is

  1. replace all use of matplotlib.delaunay.Triangulation with matplotlib.tri.Triangulation, and

  2. use some other form of interpolation than natural neighbour!

Matplotlib has linear and cubic triangular grid interpolators (http://matplotlib.org/dev/api/tri_api.html); if these are acceptable your code changes should be minimal. scipy.interpolate has a few more options (but no natural neighbour) which will be a little more work. Even if you were to like the natgrid approach I would steer you away from it as I can see us removing it completely from matplotlib sometime in the future.

Alternatively you could incorporate the matplotlib.delaunay code into your project and hence carry on using it as you are, but this would be madness as you would have to deal with the building of a C python extension, plus the delaunay code is ‘not very robust’. You will no doubt have observed this to be the case, and it is the reason why matplotlib and scipy have moved away from it to use qhull instead.

I expect we will add more triangular grid interpolators to matplotlib in due course and I am happy to receive suggestions on this. However, this will not include natural neighbour. Natural neighbour interpolation is specific to delaunay triangulation, and as we also support user-specified triangulations I am only interested in interpolation that covers all triangulations.

I hope this has been of some help, but I fear not…

Ian Thomas

I appreciate the separation of the triangulation from the interpolation,
but I also like natural neighbor.

But is it really only usable with delauney triangulations I can see that
it may not have very nice properties when applied with a very
non-delaunay triangulation, but I can't see why it it wouldn't be
computable. Or am I missing something?

-Chris

···

On Tue, Jan 28, 2014 at 12:59 AM, Ian Thomas <ianthomas23@...149...> wrote:

I expect we will add more triangular grid interpolators to matplotlib in
due course and I am happy to receive suggestions on this. However, this
will not include natural neighbour. Natural neighbour interpolation is
specific to delaunay triangulation, and as we also support user-specified
triangulations I am only interested in interpolation that covers all
triangulations.

--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...236...