hispecdrp.datamodels.meta_data

Functions

_merge_fiber_state(values)

get_meta_schema([instrument_name, config])

Get the metadata schema for a given instrument.

merge_meta(models)

Merge the meta information from multiple DataModel instances.

read_meta_schema(filepath)

Classes

MetaModel(schema[, meta, validate])

Small helper class for handling metadata based on JSON schema.

class MetaModel(schema, meta=None, validate=True)[source]

Bases: MutableMapping

Small helper class for handling metadata based on JSON schema.

Parameters:
  • schema (dict) – The metadata schema.

  • meta (dict | None, optional) – Initial metadata values. Defaults to None.

  • validate (bool, optional) – Whether to validate metadata values against the schema. Defaults to True.

boolean_columns()[source]

Return a set of columns that are logically booleans (for PostgreSQL)

property fields

Return a view of metadata fields names, including those with None values.

group_meta_by_section(flat=False)[source]

Group metadata properties by their FITS section.

Parameters:

flat (bool, optional) – Whether to return a flat dictionary instead of grouped by section. Defaults to False.

Returns:

dict – Dictionary of metadata grouped by FITS section. Keys are section names and values are dictionaries of metadata properties. Sections are ordered as they first appear in the metadata schema YAML file (self._schema['properties'] preserves that order).

pprint(show_none=False, header_style=True)[source]

Pretty-print the metadata, grouped by FITS section.

Parameters:

show_none (bool, optional) – Whether to show metadata fields with None values. Defaults to False.

set_default(prop_name, value)[source]

Set a default value for a specific metadata field.

Parameters:
  • prop_name (str) – The property name for which to set the default value.

  • value (Any) – The default value to set if the property is not already set.

set_default_values()[source]

Set default values for metadata fields based on the schema.

to_fits_header(extname='PRIMARY', include_missing_metadata=False)[source]

Convert the metadata to a FITS header.

Parameters:
  • extname (str, optional) – The extension name for which to create the header. Defaults to ‘PRIMARY’.

  • include_missing_metadata (bool, optional) – Whether to include None (unset) metadata values in the header. Defaults to False.

Returns:

header (fits.Header) – The FITS header containing the metadata.

to_record()[source]

Convert the metadata to a dictionary record.

Returns:

record (dict) – The metadata as a dictionary.

validate(prop_name, value)[source]

Validate a metadata field against the schema.

Parameters:
  • prop_name (str) – The property name to validate.

  • value (Any) – The value to validate.

Raises:

ValueError – If the value does not conform to the schema.

_merge_fiber_state(values)[source]
get_instrument_config(input=None, instrument_name=None)[source]

Get the instrument configuration class from either a FITS filename or an HDUList.

Parameters:
  • input (str or fits.HDUList, optional) – Either a FITS filename path or an already-opened HDUList object. The INSTRUME keyword will be read from the primary header.

  • instrument_name (str, optional) – The instrument name. If provided, this will be used instead of reading the instrument name from the FITS header.

Returns:

config_class (type) – The instrument config class if found.

Raises:
  • TypeError – If input is neither a string nor an HDUList.

  • ValueError – If no INSTRUME keyword is found in the header, or if the instrument config is not found in INSTRUMENT_CONFIGS.

get_meta_schema(instrument_name=None, config=None)[source]

Get the metadata schema for a given instrument.

Parameters:
  • instrument_name (str | None) – Name of the instrument. Optional.

  • config (type | None) – Instrument configuration class. Optional.

Returns:

meta (dict) – The metadata schema with defaults applied.

merge_meta(models)[source]

Merge the meta information from multiple DataModel instances.

Parameters:

models (list[DataModel]) – List of DataModel instances to merge meta information from.

Returns:

meta_merged (MetaModel) – Merged metadata.

read_meta_schema(filepath)[source]