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)
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[1], line 1
----> 1 import h5rdmtoolbox as h5tbx
3 h5tbx.use(None)
File ~/checkouts/readthedocs.org/user_builds/h5rdmtoolbox/checkouts/v1.7.0/h5rdmtoolbox/__init__.py:129
125 with File(src) as h5:
126 return h5.dumps()
--> 129 from h5rdmtoolbox.wrapper.ld.hdf.file import get_ld as hdf_get_ld
130 from h5rdmtoolbox.wrapper.ld.user.file import get_ld as user_get_ld
133 def get_ld(
134 hdf_filename: Union[str, pathlib.Path],
135 structural: bool = True,
136 semantic: bool = True,
137 blank_node_iri_base: Optional[str] = None,
138 **kwargs) -> rdflib.Graph:
File ~/checkouts/readthedocs.org/user_builds/h5rdmtoolbox/checkouts/v1.7.0/h5rdmtoolbox/wrapper/ld/__init__.py:1
----> 1 import ssnolib.ssno.standard_name
2 from ontolutils.namespacelib import M4I
3 from ontolutils.namespacelib import SCHEMA
ModuleNotFoundError: No module named 'ssnolib'
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")>]