Reputation: 171
I am trying to export scientific data via h5py into an HDF5 container format to be read by other software.
I have a 7-dimensional numpy array for which I create a dataset via h5py.File.create_dataset(). This works fine.
However, I cannot find any way to assign any physical scale (say meters, kg, angle, …) to these 7 dimensions in h5py. I could not find any documentation on how to do this.
This is possible according to the HDF5 reference.
Is this implemented in h5py? I know that it is possible with HDF5.
Thanks for your help!
Upvotes: 3
Views: 2341
Reputation: 5471
Dimension scales in HDF5 are simply another dataset that is associated with your first dataset. They can be used to define spatial coordinates, for example. If you want to indicate that a particular dimension has certain physical units you can label the dimension, which is done using the HDF5 dimension scale API: H5DSset_label()
.
Dimension scales are possible in h5py, using h5py.dims.create_scale()
and h5py.dims.attach_scale()
, and h5py.dims.label
to set the label.
For example, to indicate that the first dimension of foo.dat:/data
is in kg and the second in metres, you can set its label as follows (with f
being the HDF5 file):
f['data'].dims[0].label = 'kg'
f['data'].dims[1].label = 'm'
To add a dataset as a height scale to the second dimension, you first need to create a scale, then attach the dataset:
f['data'].dims.create_scale(f['h'], 'height')
f['data'].dims[1].attach_scale(f['h'])
You can then access the labels with
[dim.label for dim in f['data'].dims]
and the dimension scales themselves with
f['data'].dims[1][0]
or
f['data'].dims[1]['height']
Upvotes: 8
Reputation: 310287
You probably want an attribute:
http://code.google.com/p/h5py/wiki/HowTo#Reading_and_writing_attributes
Upvotes: 0