Contouring on triangular grids

I've written some code to perform contouring on triangular grids. I
wrote the underlying C++ for a separate project, but as there has been
some interest on the mpl mailing lists for such functionality I've had
a go at wrapping it up as a python module so that it is available from
mpl. I've also added a few utility functions for plotting triangular
grids, doing pseudocolour plots, etc.

Attached is the source code with some documentation and examples.
There's an example of the output at
http://img10.imageshack.us/img10/2873/tricontourfdemo3g.png
This example is similar to one of the mpl contourf examples, but on a
triangular grid of 1000 randomly spaced points, with the grid
overlaid.

So far it is only experimental code and hasn't been widely tested. I
have a list of improvements already, but thought it best to let people
see a working version before spending time polishing it. If it turned
out that a (much improved) version of it was considered good enough to
incorporate into mpl, I'd would happily help as I'd like to
contribute.

I hope someone finds it useful!
Ian Thomas

mpl_tri.tar.gz (17.1 KB)

Ian Thomas wrote:

I've written some code to perform contouring on triangular grids. I
wrote the underlying C++ for a separate project, but as there has been
some interest on the mpl mailing lists for such functionality I've had
a go at wrapping it up as a python module so that it is available from
mpl. I've also added a few utility functions for plotting triangular
grids, doing pseudocolour plots, etc.
  
Hi Ian,

Thanks for this.

I haven't had a chance to look at your code -- can you elaborate on the
approach you took versus natural neighbors interpolation, as available
through the mlab.griddata function? (See
examples/pylab_examples/griddata_demo.py for an example apparently
similar to yours.)

-Andrew

Andrew Straw wrote:

Thanks for this.

Yes, indeed. It looks like nice stuff!

I do encourage you to keep up the good work on this (the only thing I notice is the need for some more docs). I also encourage you to keep the contour generating code separate from anything matplotlib specific. I, for one, would like to use it outside of MPL.

Unfortunately, it will probably be a month or two before I can spend any time digging into this for my stuff, but it looks great so far.

I haven't had a chance to look at your code -- can you elaborate on the
approach you took versus natural neighbors interpolation, as available
through the mlab.griddata function?

I think I can answer that a bit: this is contouring directly on the triangular mesh, rather than interpolating to a rectangular grid, then contouring. It should be a little more accurate, as well as saving processing time and memory. In particular, it should work better around the edges of a non-rectangular domain.

-Chris

···

--
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@...259...