read_metadata
- stdatamodels.jwst.datamodels.read_metadata(fname, model_type=None, flatten=True)
Load a metadata tree from a file without loading the entire datamodel into memory.
The metadata dictionary will be returned in a flat format by default, such that each key is a dot-separated name. For example, the schema element meta.observation.date will end up in the result as:
("meta.observation.date": "2012-04-22T03:22:05.432")
If flatten is set to False, the metadata will be returned as a nested dictionary, with the keys being the schema elements.
For FITS files, the output dictionary contains all metadata attributes that are present in the FITS header and mapped to a schema element, as well as any extra attributes that are present in the ASDF extension of the FITS file. (If a header keyword is not mapped to a schema element, it will not be included.)
For ASDF files, the output dictionary simply contains the entire ASDF tree.
WCS objects are not loaded, as they can be recursive and can be large.
Warning
This function entirely bypasses schema validation. Although validation is done when saving a datamodel to file, if a model is modified and then saved with something other than datamodels.save (e.g. astropy.fits.writeto), the schema will not be validated and invalid data could be loaded here.
- Parameters:
- fnamestr or Path
Path to a JWSTDataModel file.
- model_typestr, optional
The model type used to figure out which schema to load. If not provided, the model type will be determined from the file’s header information (“DATAMODL” keyword for FITS files). Has no effect for ASDF input.
- flattenbool, optional
If True, the metadata will be returned as a flat dictionary. If False, the metadata will be returned as a nested dictionary. Default is True.
- Returns:
- dict
The metadata tree.