Is there a way to store and subsequently read attributes in an hdf file in order of creation?
I have an ordered list of tuples (string, value) in python which I want to add to an hdf group as attributes. I visit my list in order and the attributes end up sorted lexicographically (I assume) in the hdf file.
import h5py
a = [('attr1', -1.0), ('attr2', 8), ('attr3', 4000), ('attr4', 1000),\
('attr5', -1.0), ('attr6', 8), ('attr7', 4000), ('attr8', 1000),\
('attr9', -1.0), ('attr10', 8), ('attr11', 4000), ('attr12', 1000)]
with h5py.File('test.h5', 'a') as output_stream:
for k, v in a:
output_stream.attrs[k] = v
The h5dump of this is the one below and it doesn't seem to hold any time data on when it was created.
HDF5 "test.h5" {
GROUP "/" {
ATTRIBUTE "attr1" {
DATATYPE H5T_IEEE_F64LE
DATASPACE SCALAR
DATA {
(0): -1
}
}
ATTRIBUTE "attr10" {
DATATYPE H5T_STD_I32LE
DATASPACE SCALAR
DATA {
(0): 8
}
}
ATTRIBUTE "attr11" {
DATATYPE H5T_STD_I32LE
DATASPACE SCALAR
DATA {
(0): 4000
}
}
ATTRIBUTE "attr12" {
DATATYPE H5T_STD_I32LE
DATASPACE SCALAR
DATA {
(0): 1000
}
}
ATTRIBUTE "attr2" {
DATATYPE H5T_STD_I32LE
DATASPACE SCALAR
DATA {
(0): 8
}
}
... (ATTRIBUTE 3 to 8)
ATTRIBUTE "attr9" {
DATATYPE H5T_IEEE_F64LE
DATASPACE SCALAR
DATA {
(0): -1
}
}
}
}
I found in some hdf documentation that HDF5 is supposed to support iteration and lookup of attributes by creation order by using H5Pset_attr_creation_order but I don't know how to do this with h5py.
https://support.hdfgroup.org/HDF5/doc/ADGuide/WhatsNew180.html