Activate a Convention#
This section will take you through the steps of activating a convention and find out about registered ones.
from h5rdmtoolbox import convention
import h5rdmtoolbox as h5tbx
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[1], line 1
----> 1 from h5rdmtoolbox import convention
2 import h5rdmtoolbox as h5tbx
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'
Conventions are registered. If we design a new one, it will only be usable if it is registered.
To list all available convention, call get_registered_conventions().
convention.get_registered_conventions()
{'h5tbx': Convention("h5tbx"),
'h5py': Convention("h5py"),
'MyFirstConvention': Convention("MyFirstConvention"),
'h5rdmtoolbox-tuturial-convention': Convention("h5rdmtoolbox-tuturial-convention"),
'h5rdmtoolbox-tutorial-convention': Convention("h5rdmtoolbox-tutorial-convention")}
Standard conventions#
Two conventions are shipped with the toolbox: “h5py” and “h5tbx”. Without activating any convention, “h5py” will be in place. In fact, it does nothing and mimics the behavior of the h5py package. This means, that methods like create_dataset do not expect other parameters, as we know from the h5py-package.
Which convention is currently activated?
cv = convention.get_current_convention()
cv
Convention("h5py")
Activating a convention#
To activate a convention, call use() and pass its name:
h5tbx.use('h5tbx')
using("h5tbx")
To deactivate a convention, pass None or “h5py”
h5tbx.use(None)
using("h5py")
We can also use a context manager to activate a convention only for part of the code:
print(convention.get_current_convention().name)
with h5tbx.use('h5tbx'):
print(convention.get_current_convention().name)
print(convention.get_current_convention().name)
h5py
h5tbx
h5py
To find out how to work with a convention, please go to the next section.