Metadata

All Group and Dataset objects contain Metadata. A Metadata object is a dict that can be made read only and allows for accessing the keys of the dict as class attributes (see Accessing Keys as Class Attributes for more information).

For example, suppose that a file is read with the Root Group having the following Metadata

>>> root.metadata
<Metadata '/' {'voltage': 1.2, 'voltage_unit': 'V'}>

A value can be accessed by specifying a key

>>> root.metadata['voltage']
1.2

or as a class attribute

>>> root.metadata.voltage
1.2

When a file is read, the Root object is returned in read-only mode so you cannot modify the metadata

>>> root.metadata.voltage = 7.64
Traceback (most recent call last):
  ...
ValueError: Cannot modify <Metadata '/' {'voltage': 1.2, 'voltage_unit': 'V'}>. It is accessed in read-only mode.

However, you can allow root to be modified by setting the read_only property to be False

>>> root.metadata.read_only = False
>>> root.metadata.voltage = 7.64
>>> root.add_metadata(current=10.3, current_unit='mA')
>>> root.metadata
<Metadata '/' {'voltage': 7.64, 'voltage_unit': 'V', 'current': 10.3, 'current_unit': 'mA'}>