Skip to content

Latest commit

 

History

History
61 lines (43 loc) · 1.8 KB

metadata.rst

File metadata and controls

61 lines (43 loc) · 1.8 KB

Metadata

All msl-io-group and msl-io-dataset objects contain ~msl.io.metadata.Metadata. A ~msl.io.metadata.Metadata object is a dict that can be made read only and allows for accessing the keys of the dict as class attributes (see attribute-key-limitations for more information).

For example, suppose that a file is read with the ~msl.io.base.Root msl-io-group having the following ~msl.io.metadata.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 ~msl.io.base.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 ~msl.io.dictionary.Dictionary.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'}>