NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.

To learn about what's going on, see About the Archive Site.

ANN: netcdf4-python version 0.5

A new release of the python netCDF4 python module (0.5) is now available that supports both compound and vlen data types.

Here's a simple example that shows how to create a compound data type, or table:


>>> # open a new file for writing
>>> import netCDF4
>>> ncfile = netCDF4.Dataset('test.h5','w')
>>> # create an unlimited dimension called 'station'
>>> ncfile.createDimension('station',False)
>>> # create a compound datatype.
>>> # (a list of 3-tuples containing
>>> # the name of each member, it's primitive data type, and it's size).
>>> # Only fixed-size primitive data types allowed (no variable length
>>> # strings, or other compound types)
>>> # Members can be multi-dimensional arrays (in which case the third
>>> # element is a shape tuple instead of a scalar).
>>> datatype = [('latitude', 'f4',1), ('longitude', 'f4',1),
>>>             ('sfc_press','i4',1), ('temp_sounding','f4',10)]
>>> table = ncfile.createUserType(datatype,'compound','station_data')
>>> # create a variable with this data type.
>>> statdat = ncfile.createVariable('station_obs', table, ('station',))
>>> # write one record of data.
>>> statdat[0] = (40.78,-73.99,1002,
>>>              (290.2,282.5,279.,277.9,276.,266.,264.1,260.,255.5,243.))
>>> # close and reopen the file, take a look at the data.
>>> ncfile.close()
>>> ncfile = netCDF4.Dataset('test.h5')
>>> statdat = ncfile.variables['station_obs']
>>> # retrieve the data.
>>> statdatout = statdat[:]
>>> # print the data type
>>> print statdatout.dtype
[('latitude', '>f4'), ('longitude', '>f4'), ('sfc_press', '>i4'), ('temp_sounding', '>f4', (10,))]
>>> # print the data.
>>> print statdatout[:]
[ (40.779998779296875, -73.989997863769531, 1002, array([ 290.20001221, 282.5 , 279. , 277.8999939 ,
      276.        ,  266.        ,  264.1000061 ,  260.        ,
      255.5       ,  243.        ], dtype=float32))]


The primary restriction is that you can't yet have nested compound data types (compound data types whose elements are also compound data types). The netCDF4_classic module provides a high-degree of compatibility with the most popular python netCDF3 module, Scientific.IO.NetCDF. It can read or write NETCDF3 and NETCDF4_CLASSIC files, and can use zlib compression in NETCDF4_CLASSIC mode.
For more information,  and to download the source, see

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

Regards,

-Jeff

P.S. Russ or Ed, could you update the URL on http://www.unidata.ucar.edu/software/netcdf/software.html to point to the google URL?

--
Jeffrey S. Whitaker         Phone  : (303)497-6313
Meteorologist               FAX    : (303)497-6449
NOAA/OAR/PSD  R/PSD1        Email  : Jeffrey.S.Whitaker@xxxxxxxx
325 Broadway                Office : Skaggs Research Cntr 1D-124
Boulder, CO, USA 80303-3328 Web    : http://tinyurl.com/5telg

==============================================================================
To unsubscribe netcdfgroup, visit:
http://www.unidata.ucar.edu/mailing-list-delete-form.html
==============================================================================


  • 2006 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: