I have an HDF5 file which contains groups and subgroups inside which there are datasets. I want to open the file and add some datasets to the groups. I took the following approach which is quite simple in python.
import h5py
f = h5py.File('filename.h5','w')
f.create_dataset('/Group1/subgroup1/dataset4', data=pngfile)
f.close()
The before file looked like this
After File looks like this
but I want it to not delete other datasets and groups but rather just append the dataset4 in the line.
One of the most powerful features of HDF5 is its ability to store and modify compressed data. The HDF5 Library comes with two pre-defined compression methods, GNUzip (Gzip) and Szip and has the capability of using third-party compression methods as well.
This is probably due to your chunk layout - the more chunk sizes are small the more your HDF5 file will be bloated. Try to find an optimal balance between chunk sizes (to solve your use-case properly) and the overhead (size-wise) that they introduce in the HDF5 file.
HDF5 files are organized in a hierarchical structure, with two primary structures: groups and datasets. HDF5 group: a grouping structure containing instances of zero or more groups or datasets, together with supporting metadata. HDF5 dataset: a multidimensional array of data elements, together with supporting metadata.
HDF5 supports two string encodings: ASCII and UTF-8. We recommend using UTF-8 when creating HDF5 files, and this is what h5py does by default with Python str objects.
Just like with the Python open() function, 'w' will truncate any existing file. Use the 'a' mode to add content to the file:
import h5py
f = h5py.File('filename.h5','a')
f.create_dataset('/Group1/subgroup1/dataset4', data=pngfile)
f.close()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With