Group creation#
The default group creation is not much different, except that you can optionally pass attributes as a dictionary during group initialization.
Furthermore, it is also possible to overwrite an existing group by passing overwrite=True.
If the group should not be overwritten but only the attributes, pass update_attrs=True. Note, that this will update the existing matching attributes.
import h5rdmtoolbox as h5tbx
h5tbx.use(None)
using("h5py")
with h5tbx.File() as h5:
h5.create_group('mygrp')
h5.create_group('mygrp', overwrite=True)
with h5tbx.File() as h5:
h5.create_group('mygrp', attrs=dict(one=2, two='a second attr'))
# create the same group again but indicate that only the attributes should be overwritten:
h5.create_group('mygrp', attrs=dict(one=2, two='a second attr which is overwritten'), update_attrs=True)
Group exploration#
Sometimes it is helpful to get all groups of a current group.
with h5tbx.File(h5.hdf_filename) as h5:
print(h5.get_groups())
[<HDF5 wrapper group "/mygrp" (members: 0, convention: "h5py")>]
With recursive=True all subgroups are returned, too, however the default is False.
with h5tbx.File(h5.hdf_filename) as h5:
print(h5.get_groups(recursive=True))
[<HDF5 wrapper group "/" (members: 1, convention: "h5py")>, <HDF5 wrapper group "/mygrp" (members: 0, convention: "h5py")>]