example lightweight isosurface plotting code in python

General scientific issues regarding ROMS

Moderators: arango, robertson

Post Reply
Message
Author
jpringle
Posts: 107
Joined: Sun Jul 27, 2003 6:49 pm
Location: UNH, USA

example lightweight isosurface plotting code in python

#1 Unread post by jpringle »

Dear all --

I hope someone finds this usefull. I wanted to plot some iso-surfaces in 3D with ROMS data without re-gridding it to a rectangular grid or some such silliness. There are many heavy-weight environments that can do all sorts of cool things like that (paraview, vapor, yt) -- but getting them to ingest the data is non-obvious, and they require a whole new tool chain. Peh.

I realized there was an easy way to do it. Scikit-images has an algorithm to produce a triangular mesh of an isosurface from a cubic data array. It is trivial to run this code on a slab of ROMS data and take the output of this code in (i,j,k) space and remap it to (x,y,z) space, and then you have the faces of an iso-surface that is easy to display.

In the attached code, I provide a python routine to do so, and example code to visualize the output in the python visvis package. The output, a series of triangles representing the isosurface, can also be easily visualized in MayaVI2 or many other packages. Once you have the mesh for the iso-surface, almost any 3d visualization package can display it! Details on how to do so are discussed in the code.

This code should be able to make iso-surfaces from any model whose underlying structure is rectangular grids.

If you import the package, it provides the routine "makeMesh()" which does the heavy lifting. If you run the package, it will either plot a sphere:



Or a temperature iso-surface from a ROMS run (you will, of course, have to provide the ROMS data, and have a code to generate the 3D array of depths for each data point. I use pyroms, but any such tool will do).



One thing to keep in mind in plotting oceanographic code is that it has extreme aspect ratios. Please read the example code carefully to see how to manage this -- otherwise your plot will look like a sheet of paper viewed edge on (because that is what the ocean looks like, in truth...).


Cheers
Jamie
Attachments
makeIsoSurfaceMesh.py
The python source.
(8.31 KiB) Downloaded 273 times

Post Reply