A Tuesday 16 November 2010 16:38:20 David E. Sallis escrigué:
> Gerrit Holl said the following on 11/16/2010 8:12 AM:
> > I am moving from NetCDF to HDF5. In NetCDF, I can assign attributes
> > to each variable/column. That is very useful for self-documenting
> > the
> > 
> > file like this:
> >     double AVHRR_LONG(Collocations) ;
> >     
> >             AVHRR_LONG:long_name = "AVHRR Longitude" ;
> >             AVHRR_LONG:units = "degrees_east" ;
> >             AVHRR_LONG:valid_range = -180., 180. ;
> > 
> > I know that in HDF5, I can assign attributes to each node. But I
> > think the columns of a table are not nodes. Is there an equivalent
> > in HDF5 to NetCDF's variable attributes? How would I use this in
> > pytables?
> 
> You can store arbitrary key/value pairs on a node by using the node's
> _f_setAttr() method.  I use this frequently and in much the same way
> as in your example.   The key is the column name, and the value is a
> Python dictionary containing the long name, units, etc.
> 
> Example:   n._f_setAttr('AVHRR_LONG':{'long_name':'AVHRR_Longitude',
> 'units':'degrees_east', 'valid_range':(-180.0,180.0)})
> 
> You can then extract the values using _f_getAttr().

Yeah.  This is however equivalent to:

n.attrs.AVHRR_LONG = {'long_name':'AVHRR_Longitude',  
'units':'degrees_east', 'valid_range':(-180.0,180.0)}

But caveat emptor: by saving dictionaries directly as attributes, 
PyTables is auto-magically pickling them, and they cannot be read by 
another HDF5 tool than PyTables.  This might be important or not, 
depending on your needs.  Anyway, I'd like to add the possibility to 
warn the user whenever she might be writing an HDF5 file that cannot be 
read by other tools:

http://pytables.org/trac/ticket/315

-- 
Francesc Alted

------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today
http://p.sf.net/sfu/msIE9-sfdev2dev
_______________________________________________
Pytables-users mailing list
Pytables-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pytables-users

Reply via email to