Tuesday, 15 May 2012

python - Delete dataset attribute from HDF5 file -



python - Delete dataset attribute from HDF5 file -

i have hdf5 file want modify deleting attribute of 1 of datasets , save file without farther changes. can in hdfview, need that's scriptable because needs applied big number of files.

i tried writing script in python, using h5py:

import h5py inf = h5py.file("filename.h5", 'r') dset = inf['/data/mydataset'] del dset.attrs['myattrname']

but next error:

traceback (most recent phone call last): file "", line 1, in file "/usr/lib/python2.7/dist-packages/h5py/_hl/attrs.py", line 75, in delitem h5a.delete(self._id, self._e(name)) file "h5a.pyx", line 135, in h5py.h5a.delete (h5py/h5a.c:2682) keyerror: "unable delete attribute (attribute: can't delete message)"

print dset.attrs['myattrname'] produces right value, proving can access attribute.

is there other ways this? maybe using h5repack?

i ended using 1 of hdf tools - h5copy:

h5copy -p -i inputfile.h5 -o outputfile.h5 -s /inputdatasetname -d /outputdatasetname -f noattr

since of files have process have same datasets , it's little number of dataset,s wrote shell script calls h5copy on each.

note running h5copy on grouping not remove attributes of datasets in group.

python hdf5 h5py hdf

No comments:

Post a Comment