Hello List,

a while ago, I proposed an extension to pytables
which would allow for HDF5 dimension scales to
be read. Not on a high level, though, just
giving access to the kind of attributes that is used
in their implementation, especially references
and variable-length list attributes.

After some more suggestions from this list, I figured
out that a completely different approach is better,
and so I reimplemented the same as follows:

I introduced a new numpy data type, conveniently
called reference, which corresponds to a HDF5
reference. Now one can make arrays of references,
even record arrays of references, and also store them
(via pytables) into a HDF5 file.

Secondly, I modified setAttr so that if it is given
a list of numpy arrays of all same datatype, a variable
length array is created as an attribute.

To illustrate that, I give a little example:

-------------- snip ----------------
from __future__ import with_statement
import tables
from tables import reference
from numpy import array, arange

with tables.openFile("test.h5", mode="w", title="test") as file:
    group = file.createGroup("/", "G", "group")

    dataA = file.createArray(group, "A", array([1,2,3]), "data")
    dataB = file.createArray(group, "B", array([4,5,6]), "data")
    dataC = file.createArray(group, "C", array([7,8,9]), "data")
    file.flush()

    ref = tables.reference(dataA)
    print array([ref])
    dataB.attrs.dataA = array([ref])
    a = array([(2, ref), (3, ref)], dtype=[("l", "i"), ("s", "r")])
    print a.dtype
    print a.dtype.base
    dataB.attrs.dataL = a
    dataB.attrs.list = [ arange(7), arange(9) ]
    dataB.attrs.reflist = [ array([ref]),
        array([ref, tables.reference(dataB)]) ]
    print dataB.attrs.reflist

    dataB.attrs.dataR = ref
    print ref
    print ref.deref(file)
    l = ref
    ref = tables.reference(dataB)

print "-----------"

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Pytables-users mailing list
Pytables-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pytables-users

Reply via email to