python-netcdf4 and multi-file support

82 views
Skip to first unread message

hannah

unread,
Feb 13, 2012, 2:29:45 AM2/13/12
to ccp-viz-toolkit-discuss
I know this comes long after the promised deadline, but I incorporated
python-netcdf4 and the multifile capability of the dataset. I left
scipy in as the fall back library netcdf4 doesn't have to be installed
unless those features are needed, and for multiple files I support
pointing to a folder and using the glob syntax exemplified in the
python netcdf-4 docs.

Julien Emile-Geay

unread,
Feb 13, 2012, 11:44:00 AM2/13/12
to hannah, ccp-viz-toolkit-discuss
Hi Hannah,
Great to hear from you. How was the AMS meeting?
It's good news that you switched to a modern netcdf implementation. Did you update the CCP website as well? It would be nice to sync it to your latest version and call it a day.
What other fun things are you working on?
Cheers
Julien

--
Julien Emile-Geay (by way of a mobile typo generator. Please kindly forgive brevity and errors)

Hannah

unread,
Feb 13, 2012, 2:42:20 PM2/13/12
to ccp-viz-too...@googlegroups.com
AMS was fun, though I still need to upload a screencast of my
presentation. I just updated the code on the CCP website, so if you
restart apache it should be good to go. I'm actually finding
python-netcdf4 to be slower than scipy.io, but I could be doing
something wonky. Also, it seems that files opened as an MFdataset
create timestrings that coards doesn't read, so I turned off labeling
time on those but I need to sort out a better solution.
I'm hacking on this library so much lately 'cause I'm using it for a
bunch of precip datasets that it seems to be behaving fairly well
with. I'm mostly playing around with the coloring/normalization, but I
don't have anything stable yet. (Though I did change the code so you
could either pass in a colormap string or an actual matplotlib
colormap object for even more customizability)

Filipe

unread,
Feb 13, 2012, 3:08:18 PM2/13/12
to ccp-viz-too...@googlegroups.com
Hannah, I usually use num2date to get datetime objects. Does it help
your case? I never used the multi-file support before...

from netCDF4 import Dataset
from netCDF4 import num2date

nc = Dataset(ncfile)
time = num2date(nc.variables['time'][:], nc.variables['time'].units)

Filipe

Hannah

unread,
Feb 13, 2012, 3:19:29 PM2/13/12
to ccp-viz-too...@googlegroups.com
> Hannah, I usually use num2date to get datetime objects. Does it help your
> case? I never used the multi-file support before...
I don't think so cause coards doesn't seem to have any problem with
the files pulled using netcdf.Dataset, so I'm thinking the bug is in
how MFDataset constructs the aggregate timeseries dimension. The
complaint is with the epoch data being 1970, which it shouldn't
actually have a problem with. I think when I have time to go down that
road, I'll probably do something like what you're suggestion, which is
take the times provided by MFdataset, convert them to datetime using
num2date, and then make the object time reference be all those
datetime objects converted back to coards
Reply all
Reply to author
Forward
0 new messages