NetCDF input/output/plotting using Matplotlib w/ Basemap

I have a model that calculates the tidal stress tensor (a symmetric 2x2 matrix) on the surface of an icy satellite. It's just two orthogonal vector fields on the surface of the body. I want to be able to make pretty plots of the model output, including:

* The magnitude of either one of the fields at any point
* The magnitude and orientation of either or both fields, as a grid of little arrows, whose colors correspond to whether the value is positive or negative.
* Animations of time (or other) series.

I also want to be able to save the model output in a format that other people can read and manipulate. Ideally, model run results could also be hosted on a web server, and other people could view them remotely.

I just re-wrote the model in pure Python (it had been written in C previously), and I've been using my own hacked together ASCII file format and a Perl script that builds GMT plots based on them to make figures and visualizations up until now... but I'm sick of that and want something more flexible.

This all seems to suggest to me, after a little poking around, that the NetCDF file format would be good. I've managed to get SciPy and Matplotlib and Basemap installed and apparently working together happily... but I can't seem to find any "official" module within that structure for writing NetCDF files. There are references to the old Scientific.IO.NetCDF package, and I found something that had been hanging around in the scipy.sandbox area... but which isn't there any more. There's quite a list of Python interfaces to NetCDF on the Unidata website... but they don't make any recommendations as to which is "best".

If I'm going to be working within Matplotlib and Basemap and SciPy, does anyone have a good recommendation for which NetCDF Python package to use? Or issues I should consider?

Thanks for any insight,

Zane

···

--
Zane Selvans
Amateur Human
zane@...1923...
303/815-6866
PGP Key: 55E0815F

Zane Selvans wrote:

> If I'm going to be working within Matplotlib and Basemap and SciPy,
> does anyone have a good recommendation for which NetCDF Python
> package to use? Or issues I should consider?

We're heavy users of netcdf4-python and it's working well.

http://code.google.com/p/netcdf4-python/

If you want to stick with netcdf3 until the official netcdf4 release, then
just run

python setup-nc3.py install

regards, Phil

Zane Selvans wrote:

I have a model that calculates the tidal stress tensor (a symmetric 2x2 matrix) on the surface of an icy satellite. It's just two orthogonal vector fields on the surface of the body. I want to be able to make pretty plots of the model output, including:

* The magnitude of either one of the fields at any point
* The magnitude and orientation of either or both fields, as a grid of little arrows, whose colors correspond to whether the value is positive or negative.
* Animations of time (or other) series.

I also want to be able to save the model output in a format that other people can read and manipulate. Ideally, model run results could also be hosted on a web server, and other people could view them remotely.

I just re-wrote the model in pure Python (it had been written in C previously), and I've been using my own hacked together ASCII file format and a Perl script that builds GMT plots based on them to make figures and visualizations up until now... but I'm sick of that and want something more flexible.

This all seems to suggest to me, after a little poking around, that the NetCDF file format would be good. I've managed to get SciPy and Matplotlib and Basemap installed and apparently working together happily... but I can't seem to find any "official" module within that structure for writing NetCDF files. There are references to the old Scientific.IO.NetCDF package, and I found something that had been hanging around in the scipy.sandbox area... but which isn't there any more. There's quite a list of Python interfaces to NetCDF on the Unidata website... but they don't make any recommendations as to which is "best".

If I'm going to be working within Matplotlib and Basemap and SciPy, does anyone have a good recommendation for which NetCDF Python package to use? Or issues I should consider?

Thanks for any insight,

Zane

Zane: Basemap already includes a NetCDFFile function that can read netCDF and opendap (http://opendap.org) datasets. If you need to write netCDF, then netcdf4-python should do fine.

-Jeff

···

--
Jeffrey S. Whitaker Phone : (303)497-6313
NOAA/OAR/CDC R/PSD1 FAX : (303)497-6449
325 Broadway Boulder, CO, USA 80305-3328