Metadata information associated with a data model is accessed through its meta member. For example, to access the date that an observation was made:


Metadata values are automatically type-checked against the schema when they are set. Therefore, setting a attribute which expects a number to a string will raise an exception.

from roman_datamodels.testing.factories import create_wfi_image
from roman_datamodels import datamodels as rdmfrom romancal.datamodels import ImageModel
model = rdm.ImageModel(create_wfi_image()) = "foo"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/ddavis/miniconda3/envs/rcal_dev/lib/python3.9/site-packages/roman_datamodels/", line 183, in __setattr__
    if schema is None or _validate(key, value, schema, self.ctx):
  File "/Users/ddavis/miniconda3/envs/rcal_dev/lib/python3.9/site-packages/roman_datamodels/", line 97, in _validate
    return _value_change(attr, tagged_tree, schema, False, strict_validation, ctx)
  File "/Users/ddavis/miniconda3/envs/rcal_dev/lib/python3.9/site-packages/roman_datamodels/", line 68, in _value_change
    raise jsonschema.ValidationError(errmsg)
jsonschema.exceptions.ValidationError: While validating ra the following error occurred:
'foo' is not of type 'number'

Failed validating 'type' in schema:
    {'$schema': '',
     'archive_catalog': {'datatype': 'float',
                         'destination': ['ScienceCommon.ra']},
     'sdf': {'source': {'origin': 'PSS:fixed_target.ra_computed'},
             'special_processing': 'VALUE_REQUIRED'},
     'title': 'Target RA at mid time of exposure',
     'type': 'number'}

On instance:

The set of available metadata elements is defined in a YAML Schema that is installed with roman_datamodels from the RAD (Roman Attribute Dictionary).

There is also a utility method for finding the schema associated with a given model.

from roman_datamodels import datamodels as rdm
from roman_datamodels.testing.factories import create_wfi_science_raw
# Create a model of the desired type
raw = create_wfi_science_raw()
raw_science = rdm.ScienceRawModel(raw)
# find the associated Schema

An alternative method to get and set metadata values is to use a dot-separated name as a dictionary lookup. This is useful for databases, such as CRDS, where the path to the metadata element is most conveniently stored as a string. The following two lines are equivalent:


In addtion the times are stored as Astropy time objects and so the date can be displayed using various formats:

2028-12-22 05:17:56.203