metadata4Ing#

Metadata4Ing is an ontology developed within the NFDI Consortium NFDI4Ing “with the aim of providing a thorough framework for the semantic description of research data, with a particular focus on engineering sciences and neighbouring disciplines.”

import h5rdmtoolbox as h5tbx
_ = h5tbx.set_config(auto_create_h5tbx_version=False)

Simple example using m4i:NumericalVariable#

The most basic example of using M4I with HDF5 is to semantify an HDF5 dataset with m4i:NumericalVariable

from ontolutils.namespacelib import M4I, QUDT_UNIT
with h5tbx.File() as h5:
    ds = h5.create_dataset("velocity", data=4.5, attrs={"units": "m/s"})
    ds.rdf.type = M4I.NumericalVariable
    ds.rdf.data_predicate = M4I.hasNumericalValue
    ds.rdf["units"].predicate = M4I.hasUnit
    ds.rdf["units"].object = QUDT_UNIT.M_PER_SEC

    h5.dump(collapsed=False)

    print(h5.serialize("ttl", structural=False, file_uri="https://example.org#"))
@prefix m4i: <http://w3id.org/nfdi4ing/metadata4ing#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<https://example.org#tmp0.hdf/velocity> a m4i:NumericalVariable ;
    m4i:hasNumericalValue "4.5"^^xsd:float ;
    m4i:hasUnit <http://qudt.org/vocab/unit/M-PER-SEC> .

Reading in the Metadata4Ing-Example#

The h5RDMtoolbox allows translating JSON-LD data into the HDF5 structure and wise versa (see here). This way, engineering process metadata can be added easily to the HDF5 file.

Consider the following example file taken from the m4i ontology “first steps guide”, which describes an experimental investigation. You can find the full content of the JSON-LD file here, the following shows an excerpt:

import h5rdmtoolbox as h5tbx
_ = h5tbx.set_config(auto_create_h5tbx_version=False)

With a single call (h5tbx.jsonld.to_hdf) it is possible to read in the JSON-LD data and parse it into the HDF5 structure:

with h5tbx.File() as h5:
    h5.create_group('metadata')
    h5tbx.jsonld.to_hdf(h5.metadata, source='min_m4i_ex.jsonld')
print(h5tbx.serialize(h5.hdf_filename, format="ttl", structural=False, file_uri="https://local-domain.org/"))
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix m4i: <http://w3id.org/nfdi4ing/metadata4ing#> .
@prefix ns1: <http://purl.obolibrary.org/obo/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix schema: <https://schema.org/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<https://local-domain.org/tmp1.hdf/metadata/FileSet> schema:about <https://local-domain.org/output/xrct-data> .

<https://local-domain.org/tmp1.hdf/metadata/FineTec%20FORE%20180.01C%20TT> schema:about <https://local-domain.org/xray_source_finetec_180.01ctt_0001> .

<https://local-domain.org/tmp1.hdf/metadata/Image%20Processing%20and%20Reconstruction> schema:about <https://local-domain.org/reconstruction_0001> .

<https://local-domain.org/tmp1.hdf/metadata/Person> schema:about <https://local-domain.org/alex> .

<https://local-domain.org/tmp1.hdf/metadata/Post%20Processing> schema:about <https://local-domain.org/postprocessing_0001> .

<https://local-domain.org/tmp1.hdf/metadata/Sample%20preparation%20and%20parameter%20definition> schema:about <https://local-domain.org/preparation_0001> .

<https://local-domain.org/tmp1.hdf/metadata/Standard%20cone%20beam%20scanning> schema:about <https://local-domain.org/cone_beam_scanning> .

<https://local-domain.org/tmp1.hdf/metadata/Standard%20cone%20beam%20scanning/parameter> schema:about <https://local-domain.org/xray_tube_voltage> .

<https://local-domain.org/tmp1.hdf/metadata/XRCT-Scan> schema:about <https://local-domain.org/xrctscan_0001> .

<https://local-domain.org/alex> a foaf:Person ;
    m4i:orcidId "0000-0000-0123-4567" ;
    foaf:lastName "Test" .

<https://local-domain.org/cone_beam_scanning> a m4i:Method ;
    rdfs:label "scanning" ;
    dcterms:description "sample" ;
    m4i:hasParameter <https://local-domain.org/xray_tube_voltage> .

<https://local-domain.org/output/xrct-data> a m4i:FileSet ;
    dcterms:description "image-files" ;
    m4i:includes "tiff" .

<https://local-domain.org/postprocessing_0001> a m4i:ProcessingStep ;
    rdfs:label "Processing" .

<https://local-domain.org/preparation_0001> a m4i:ProcessingStep ;
    rdfs:label "definition" ;
    ns1:RO_0000057 "alex" ;
    schema:startTime "2026-04-22T00:00:00"^^xsd:dateTime .

<https://local-domain.org/reconstruction_0001> a m4i:ProcessingStep ;
    rdfs:label "Reconstruction" ;
    ns1:RO_0002233 "xrct_data_0001" .

<https://local-domain.org/xray_source_finetec_180.01ctt_0001> a m4i:Tool ;
    rdfs:label "TT" .

<https://local-domain.org/xrctscan_0001> a m4i:ProcessingStep ;
    rdfs:label "XRCT-Scan" ;
    ns1:RO_0002234 "xrct-data" ;
    m4i:hasEmployedTool "xray_source_finetec_180.01ctt_0001" ;
    m4i:investigates <https://www.wikidata.org/wiki/Q189259> ;
    m4i:investigatesProperty <https://www.wikidata.org/wiki/Q256699> ;
    m4i:realizesMethod "cone_beam_scanning" .

<https://local-domain.org/xray_tube_voltage> a m4i:NumericalVariable ;
    rdfs:label "Voltage" ;
    m4i:hasKindOfQuantity <http://qudt.org/vocab/quantitykind/ElectricPotential> ;
    m4i:hasNumericalValue "140" ;
    m4i:hasUnit <http://qudt.org/vocab/unit/KiloV> .
print(
    h5tbx.serialize(
        h5.hdf_filename,
        format="ttl",
        structural=False,
        file_uri="https://local-domain.org/",
        context={"@import": "https://w3id.org/nfdi4ing/metadata4ing/m4i_context.jsonld"})
)
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix m4i: <http://w3id.org/nfdi4ing/metadata4ing#> .
@prefix ns1: <http://purl.obolibrary.org/obo/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix schema: <https://schema.org/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<https://local-domain.org/tmp1.hdf/metadata/FileSet> schema:about <https://local-domain.org/output/xrct-data> .

<https://local-domain.org/tmp1.hdf/metadata/FineTec%20FORE%20180.01C%20TT> schema:about <https://local-domain.org/xray_source_finetec_180.01ctt_0001> .

<https://local-domain.org/tmp1.hdf/metadata/Image%20Processing%20and%20Reconstruction> schema:about <https://local-domain.org/reconstruction_0001> .

<https://local-domain.org/tmp1.hdf/metadata/Person> schema:about <https://local-domain.org/alex> .

<https://local-domain.org/tmp1.hdf/metadata/Post%20Processing> schema:about <https://local-domain.org/postprocessing_0001> .

<https://local-domain.org/tmp1.hdf/metadata/Sample%20preparation%20and%20parameter%20definition> schema:about <https://local-domain.org/preparation_0001> .

<https://local-domain.org/tmp1.hdf/metadata/Standard%20cone%20beam%20scanning> schema:about <https://local-domain.org/cone_beam_scanning> .

<https://local-domain.org/tmp1.hdf/metadata/Standard%20cone%20beam%20scanning/parameter> schema:about <https://local-domain.org/xray_tube_voltage> .

<https://local-domain.org/tmp1.hdf/metadata/XRCT-Scan> schema:about <https://local-domain.org/xrctscan_0001> .

<https://local-domain.org/alex> a foaf:Person ;
    m4i:orcidId "0000-0000-0123-4567" ;
    foaf:lastName "Test" .

<https://local-domain.org/cone_beam_scanning> a m4i:Method ;
    rdfs:label "scanning" ;
    dcterms:description "sample" ;
    m4i:hasParameter <https://local-domain.org/xray_tube_voltage> .

<https://local-domain.org/output/xrct-data> a m4i:FileSet ;
    dcterms:description "image-files" ;
    m4i:includes "tiff" .

<https://local-domain.org/postprocessing_0001> a m4i:ProcessingStep ;
    rdfs:label "Processing" .

<https://local-domain.org/preparation_0001> a m4i:ProcessingStep ;
    rdfs:label "definition" ;
    ns1:RO_0000057 "alex" ;
    schema:startTime "2026-04-22T00:00:00"^^xsd:dateTime .

<https://local-domain.org/reconstruction_0001> a m4i:ProcessingStep ;
    rdfs:label "Reconstruction" ;
    ns1:RO_0002233 "xrct_data_0001" .

<https://local-domain.org/xray_source_finetec_180.01ctt_0001> a m4i:Tool ;
    rdfs:label "TT" .

<https://local-domain.org/xrctscan_0001> a m4i:ProcessingStep ;
    rdfs:label "XRCT-Scan" ;
    ns1:RO_0002234 "xrct-data" ;
    m4i:hasEmployedTool "xray_source_finetec_180.01ctt_0001" ;
    m4i:investigates <https://www.wikidata.org/wiki/Q189259> ;
    m4i:investigatesProperty <https://www.wikidata.org/wiki/Q256699> ;
    m4i:realizesMethod "cone_beam_scanning" .

<https://local-domain.org/xray_tube_voltage> a m4i:NumericalVariable ;
    rdfs:label "Voltage" ;
    m4i:hasKindOfQuantity <http://qudt.org/vocab/quantitykind/ElectricPotential> ;
    m4i:hasNumericalValue "140" ;
    m4i:hasUnit <http://qudt.org/vocab/unit/KiloV> .