Run the interactive online version of this notebook (takes 1-2 minutes to load): Binder badge

2. Adding custom metadata#

It is possible to attach and store arbitrary metadata to WelDX objects as python attributes. The WelDX API reserves the attribute names wx_metadata and wx_user for these use cases.

The wx_metadata field is intended for additional information that might be required as part of a custom Quality Standard. The wx_user attribute is intended to add any user data and should only be used for additional information that will not get accessed by the API.

2.1. A small example#

Let’s say we want to use metadata to add a custom information to a current-sensor used during a welding experiment. As an example we want to add a timestamp to indicate when the sensor was last calibrated.

We start by creating the sensor object as a MeasurementEquipment:

from weldx.measurement import MeasurementEquipment

HKS_sensor = MeasurementEquipment(name="HKS P1000-S3")

Now we want to add the timestamp of the last time the sensor was calibrated as additional metadata. To do this we simple assign a new .wx_metadata attribute to the sensor. We will also add a small personal note to wx_user.

Note: By convention the metadata fields should be python dictionaries.

import pandas as pd

HKS_sensor.wx_metadata = {"calibration": pd.Timestamp("2020-06-01")}
HKS_sensor.wx_user = {"notes": ["wallmounted", "The cable seems to be a bit loose."]}

Now let’s look at the ASDF file contents with our metadata. We will find our data at the very end after the ASDF header.

from weldx import WeldxFile

file = WeldxFile(tree={"sensor": HKS_sensor}, mode="rw")
#ASDF 1.0.0
%YAML 1.1
%TAG !
%TAG !weldx! asdf://
--- !core/asdf-1.1.0
asdf_library: !core/software-1.0.0 {author: The ASDF Developers, homepage: '',
  name: asdf, version: 2.13.0}
  - !core/extension_metadata-1.0.0
    extension_class: asdf.extension.BuiltinExtension
    software: !core/software-1.0.0 {name: asdf, version: 2.13.0}
  - !core/extension_metadata-1.0.0
    extension_class: weldx.asdf.extension.WeldxExtension
    extension_uri: asdf://
    software: !core/software-1.0.0 {name: weldx, version: 0.6.2.dev51+ga617b06.d20221107}
sensor: !weldx!equipment/measurement_equipment-0.1.0
  name: HKS P1000-S3
  sources: []
  transformations: []
  wx_metadata: {calibration: !weldx!time/timestamp-0.1.0 '2020-06-01T00:00:00'}
    notes: [wallmounted, The cable seems to be a bit loose.]

As we can see, our custom metadata gets serialized into the ASDF tree:

    calibration: !<asdf://> {value: '2020-06-01T00:00:00'}
    notes: [wallmounted, The cable seems to be a bit loose.]

Let’s check if we keep the information upon reading the file:

in_memory_file = WeldxFile(file.write_to())

{'calibration': Timestamp('2020-06-01 00:00:00')}
{'notes': ['wallmounted', 'The cable seems to be a bit loose.']}

Generated by nbsphinx from a Jupyter notebook.