dereferencing Matlab references

667 views
Skip to first unread message

kijoshua

unread,
Mar 18, 2011, 11:04:36 AM3/18/11
to h5py
I'm currently using h5py to read data from Matlab files. Everything
works well except for the HDF5 object reference types. For the
printout below, I'm trying to access the first string from a cell
array of strings. But I can't figure out how to make use of the HDF5
object reference. Am I missing something?



>>> data = h5py.File(path,'r')
>>> r = data['node_properties']['names'][0][0]
>>> r
<HDF5 object reference>
>>> type(r)
<type 'numpy.object_'>
>>> data[r]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib64/python2.6/site-packages/h5py-1.3.1-py2.6-
linux-x86_64.egg/h5py/highlevel.py", line 388, in __getitem__
return self._getref(name)
File "/usr/local/lib64/python2.6/site-packages/h5py-1.3.1-py2.6-
linux-x86_64.egg/h5py/highlevel.py", line 375, in _getref
h5g.TYPE: Datatype}.get(h5r.get_obj_type(ref, self.id))
File "h5r.pyx", line 104, in h5py.h5r.get_obj_type (h5py/h5r.c:1188)
TypeError: Argument 'ref' has incorrect type (expected
h5py.h5r.Reference, got numpy.object_)

Andrew Collette

unread,
Mar 18, 2011, 2:20:20 PM3/18/11
to h5...@googlegroups.com
Hi,

> I'm currently using h5py to read data from Matlab files. Everything
> works well except for the HDF5 object reference types. For the
> printout below, I'm trying to access the first string from a cell
> array of strings. But I can't figure out how to make use of the HDF5
> object reference. Am I missing something?

Hmmm... you seem to have got hold of a numpy.object_, whatever that
is, rather than the reference object. This could be a corner case of
how the slicing works. What happens if you try:

r2 = r[()]
output = data[r2]

Andrew

kijoshua

unread,
Mar 18, 2011, 2:27:05 PM3/18/11
to h5py
Unfortunately, didn't work:

>>> r2=r[()]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'h5py.h5r.Reference' object is unsubscriptable

kijoshua

unread,
Mar 18, 2011, 2:36:20 PM3/18/11
to h5py
Huh, got something that worked... For some reason, I decided to try
this:
>>> r=data['node_properties']['names'][0].item(3)
>>> data[r]
<HDF5 dataset "e": shape (6, 1), type "<u2">

Wishful thinking pays off occasionally.
Reply all
Reply to author
Forward
0 new messages