merge_headers

astro_metadata_translator.merge_headers(headers, mode='overwrite', sort=False, first=None, last=None)

Merge multiple headers into a single dict.

Given a list of dict-like data headers, combine them following the specified mode.

Parameters:
headers : list of dict (or dict-like)

Collection of headers to combine. PropertyList is supported.

mode : str

Scheme to use when a header has the same key as another header but different value. Options are:

  • 'overwrite' : Value in later header overwrites earlier value.
  • 'drop' : Entire key is dropped.
  • 'first' : Retain first value encountered.
  • 'append' : Convert value to list with a value for each header (None if the key was not present). If the value is identical in multiple headers but key is missing in some, then the single identical header is stored.
sort : bool, optional

If True, sort the supplied headers into date order if possible. This affects the resulting merged output depending on the requested merge mode. An attempt will be made to extract a date from the headers.

first : list or tuple, optional

Keys to retain even if they differ. For all modes excepting append (where it is ignored) the value in the merged header will always be the value first encountered. This is usually to allow time-dependent headers such as DATE-OBS and AZSTART to be retained to allow the header to indicate the range of values. No exception is raised if a key can not be found in a header since this allows a range of expected headers to be listed covering multiple instruments.

last : list or tuple, optional

Keys to retain even if they differ. For all modes excepting append (where it is ignored) the value in the merged header will always be the final value encountered. This is usually to allow time-dependent headers such as DATE-END and AZEND to be retained to allow the header to indicate the range of values. No exception is raised if a key can not be found in a header since this allows a range of expected headers to be listed covering multiple instruments.

Returns:
merged : dict

Single dict combining all the headers using the specified combination mode.

Notes

If first and last are supplied, the keys from first are handled first, followed by the keys from last. No check is made to ensure that the keys do not overlap.