merge_headers¶
- astro_metadata_translator.merge_headers(headers: Sequence[MutableMapping[str, Any]], mode: str = 'overwrite', sort: bool = False, first: Sequence[str] | None = None, last: Sequence[str] | None = None) MutableMapping[str, Any] ¶
Merge multiple headers into a single dict.
Given a list of dict-like data headers, combine them following the specified mode.
- Parameters:
- headers
list
ofdict
(ordict
-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. If a key only appears in a subset of the headers, and is identical in those, it will be retained.'diff'
: As fordrop
but the dropped values are stored in alist
ofdict
in the returned merged header in key__DIFF__
. The order used matches the supplied order or the sorted order if specified. This allows a simple header diff to be performed and associated with the original headers. Only keys that appear in all headers will be retained in the merged one. Unlike for'drop'
headers that are identical and only present in a subset will always be included in the diff.'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
ortuple
, 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 asDATE-OBS
andAZSTART
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
ortuple
, 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 asDATE-END
andAZEND
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.
- headers
- Returns:
Notes
If
first
andlast
are supplied, the keys fromfirst
are handled first, followed by the keys fromlast
. No check is made to ensure that the keys do not overlap.