ObservationInfo#
- class astro_metadata_translator.ObservationInfo(header=None, filename=None, translator_class=None, pedantic=False, search_path=None, required=None, subset=None, **kwargs)#
Bases:
BaseModelStandardized representation of an instrument header for a single exposure observation.
- Parameters:
header (
dict-like) – Representation of an instrument header accessible as adict. May be updated with header corrections if corrections are found.filename (
str, optional) – Name of the file whose header is being translated. For some datasets with missing header information this can sometimes allow for some fixups in translations.translator_class (
MetadataTranslator-class, optional) – If notNone, the class to use to translate the supplied headers into standard form. Otherwise each registered translator class will be asked in turn if it knows how to translate the supplied header.pedantic (
bool, optional) – If True the translation must succeed for all properties. If False individual property translations must all be implemented but can fail and a warning will be issued. Only used if aheaderis specified.search_path (
Iterable, optional) – Override search paths to use during header fix up. Only used if aheaderis specified.required (
set, optional) – This parameter can be used to confirm that all properties contained in the set must translate correctly and also be non-None. For the case wherepedanticisTruethis will still check that the resulting value is notNone. Only used if aheaderis specified.subset (
set, optional) – If notNone, controls the translations that will be performed during construction. This can be useful if the caller is only interested in a subset of the properties and knows that some of the others might be slow to compute (for example the airmass if it has to be derived). Only used if aheaderis specified.**kwargs (
typing.Any) – Property name/value pairs for kwargs-based construction mode. This mode creates anObservationInfodirectly from supplied properties rather than by translating a header. Ifheaderis provided it is an error to also providekwargs.
- Raises:
ValueError – Raised if the supplied header was not recognized by any of the registered translators. Also raised if the request property subset is not a subset of the known properties or if a header is given along with kwargs.
TypeError – Raised if the supplied translator class was not a MetadataTranslator.
KeyError – Raised if a required property cannot be calculated, or if pedantic mode is enabled and any translations fails.
NotImplementedError – Raised if the selected translator does not support a required property.
Notes
There is a core set of instrumental properties that are pre-defined. Additional properties may be defined, either through the
makeObservationInfofactory function by providing theextensionsdefinitions, or through the regularObservationInfoconstructor when the extensions have been defined in theMetadataTranslatorfor the instrument of interest (or in the providedtranslator_class).There are two forms of the constructor. If the
headeris given then a translator will be determined and the properties will be populated accordingly. No generic keyword arguments will be expected and the remaining parameters control the behavior of the translator.If the header is not given it is assumed that the keyword arguments are direct specifications of observation properties. In this mode only the
filenameandtranslator_classparameters will be used. The latter is used to determine any extensions that are being provided, although when using standard serializations the special_translatorkey will be used instead to specify the name of the registered translator from which to extract extension definitions.Headers will be corrected if correction files are located and this will modify the header provided to the constructor. Modifying the supplied header after construction will modify the internal cached header.
Values of the properties are read-only.
Attributes Summary
Header cards used for the translation.
Configuration for the model, should be a dictionary conforming to [
ConfigDict][pydantic.config.ConfigDict].Methods Summary
from_header(header, *[, filename, ...])Create an
ObservationInfoby translating a metadata header.from_json(json_str)Create
ObservationInfofrom JSON string.from_simple(simple)Convert the entity returned by
to_simpleback into anObservationInfo.makeObservationInfo(*[, extensions, ...])Construct an
ObservationInfofrom the supplied parameters.model_post_init(context, /)This function is meant to behave like a BaseModel method to initialise private attributes.
Return a copy of the supplied header with used keywords removed.
to_json()Serialize the object to JSON string.
Convert the contents of this object to simple dict form.
Attributes Documentation
- cards_used#
Header cards used for the translation.
- model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'forbid', 'ser_json_inf_nan': 'constants', 'validate_assignment': False}#
Configuration for the model, should be a dictionary conforming to [
ConfigDict][pydantic.config.ConfigDict].
Methods Documentation
- classmethod from_header(header, *, filename=None, translator_class=None, pedantic=False, search_path=None, required=None, subset=None)#
Create an
ObservationInfoby translating a metadata header.- Parameters:
header (
dict-like) – Header mapping to translate.filename (
str, optional) – Name of file associated with this header.translator_class (
MetadataTranslator-class, optional) – Translator class to use. IfNone, translator will be auto-determined.pedantic (
bool, optional) – IfTrue, translation failures are fatal.search_path (
Sequence[str], optional) – Search paths for header corrections.required (
set[str], optional) – Properties that must be translated and non-None.subset (
set[str], optional) – Restrict translation to this subset of properties.
- Returns:
obsinfo – Translated observation metadata.
- Return type:
- classmethod from_json(json_str)#
Create
ObservationInfofrom JSON string.- Parameters:
json_str (
str) – The JSON representation.- Returns:
obsinfo – Reconstructed object.
- Return type:
Notes
Round-tripping of extension properties requires that the
ObservationInfowas created with the help of a registeredMetadataTranslator(which contains the extension property definitions).
- classmethod from_simple(simple)#
Convert the entity returned by
to_simpleback into anObservationInfo.- Parameters:
- Returns:
obsinfo – New object constructed from the dict.
- Return type:
Notes
Round-tripping of extension properties requires that the
ObservationInfowas created with the help of a registeredMetadataTranslator(which contains the extension property definitions).
- classmethod makeObservationInfo(*, extensions=None, translator_class=None, **kwargs)#
Construct an
ObservationInfofrom the supplied parameters.- Parameters:
extensions (
dict[str:PropertyDefinition], optional) – Optional extension definitions, indexed by extension name (without theext_prefix, which will be added byObservationInfo).translator_class (
MetadataTranslator-class, optional) – Optional translator class defining the extension properties. If provided, this can be used instead ofextensionsand will be stored in the instance for JSON round-tripping.**kwargs (
Any) – Name-value pairs for any properties to be set. In the case of extension properties, the names should include theext_prefix.
- Return type:
Notes
The supplied parameters should use names matching the property. The type of the supplied value will be checked against the property. Any properties not supplied will be assigned a value of
None.
- model_post_init(context, /)#
This function is meant to behave like a BaseModel method to initialise private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- Args:
self: The BaseModel instance. context: The context.
- stripped_header()#
Return a copy of the supplied header with used keywords removed.
- Returns:
stripped – Same class as header supplied to constructor, but with the headers used to calculate the generic information removed.
- Return type:
dict-like
- to_json()#
Serialize the object to JSON string.
- Returns:
j – The properties of the ObservationInfo in JSON string form.
- Return type:
Notes
Round-tripping of extension properties requires that the
ObservationInfowas created with the help of a registeredMetadataTranslator(which contains the extension property definitions).
- to_simple()#
Convert the contents of this object to simple dict form.
The keys of the dict are the standard properties but the values can be simplified to support JSON serialization. For example a SkyCoord might be represented as an ICRS RA/Dec tuple rather than a full SkyCoord representation.
Any properties with
Nonevalue will be skipped.Can be converted back to an
ObservationInfousingfrom_simple.Notes
Round-tripping of extension properties requires that the
ObservationInfowas created with the help of a registeredMetadataTranslator(which contains the extension property definitions).