Interfaceing HDF5 files following the Standard Name Convention

Interfaceing HDF5 files following the Standard Name Convention#

Let’s remember, that standard names are set to identify certain datasets in the HDF5 file. Those datasets have a special meaning to the user and are likely to be frequently used in the analysis of the data.

For this purpose a high-level interface HDF5StandardNameInterface is written, which facilitates the work with such HDF5 data. It scans the HDF5 file for all standard names and creates a class property for each

import h5rdmtoolbox as h5tbx

from h5rdmtoolbox.convention.standard_names import HDF5StandardNameInterface

import numpy as np

cv = h5tbx.convention.from_zenodo('https://zenodo.org/record/8357399')
cv.properties[h5tbx.File]['data_type'].make_optional()
cv.properties[h5tbx.File]['contact'].make_optional()
h5tbx.use(cv)
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[1], line 1
----> 1 import h5rdmtoolbox as h5tbx
      3 from h5rdmtoolbox.convention.standard_names import HDF5StandardNameInterface
      5 import numpy as np

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_dataset('x', data=[-4, 1, 3, 5, 10],
                      standard_name='x_coordinate',
                      units='m', make_scale=True)
    h5.create_dataset('y', data=[10, 11, 13],
                      standard_name='y_coordinate',
                      units='m', make_scale=True)
    h5.create_dataset('u', np.random.rand(3, 5),
                      standard_name='x_velocity',
                      units='m/s',
                      attach_scales=('y', 'x'))
    h5.create_dataset('v', np.random.rand(3, 5),
                      standard_name='y_velocity',
                      units='m/s',
                      attach_scales=('y', 'x'))
    h5.create_dataset('dudx', np.random.rand(3, 5),
                      standard_name='derivative_of_x_velocity_wrt_x_coordinate',
                      units='1/s')
h5sni = HDF5StandardNameInterface.from_hdf(h5.hdf_filename)
h5sni.standard_names
['x_coordinate',
 'y_coordinate',
 'derivative_of_x_velocity_wrt_x_coordinate',
 'y_velocity',
 'x_velocity']
h5sni.velocity.plot()
h5sni.velocity.plot.quiver()
<matplotlib.quiver.Quiver at 0x21c24e93a90>
../../../_images/4a010dfea46330febc7b0408fffdc6e1b5ae65f213e0596c47e3b6a05509e487.png