Coverage for python/lsst/obs/lsst/translators/lsstCam.py : 31%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# This file is currently part of obs_lsst but is written to allow it
2# to be migrated to the astro_metadata_translator package at a later date.
3#
4# This product includes software developed by the LSST Project
5# (http://www.lsst.org).
6# See the LICENSE file in this directory for details of code ownership.
7#
8# Use of this source code is governed by a 3-clause BSD-style
9# license that can be found in the LICENSE file.
11"""Metadata translation code for the main LSST Camera"""
13__all__ = ("LsstCamTranslator", )
15import logging
16import astropy.units as u
18from astro_metadata_translator import cache_translation
19from astro_metadata_translator.translators.helpers import is_non_science
21from .lsst import LsstBaseTranslator, SIMONYI_TELESCOPE, FILTER_DELIMITER
23log = logging.getLogger(__name__)
25# Normalized name of the LSST Camera
26LSST_CAM = "LSSTCam"
29def is_non_science_or_lab(self):
30 """Pseudo method to determine whether this is a lab or non-science
31 header.
33 Raises
34 ------
35 KeyError
36 If this is a science observation and on the mountain.
37 """
38 if is_non_science(self):
39 return
40 if not self._is_on_mountain():
41 return
42 raise KeyError("Required key is missing and this is a mountain science observation")
45class LsstCamTranslator(LsstBaseTranslator):
46 """Metadata translation for the main LSST Camera."""
48 name = LSST_CAM
49 """Name of this translation class"""
51 supported_instrument = LSST_CAM
52 """Supports the lsstCam instrument."""
54 _const_map = {
55 "instrument": LSST_CAM,
56 "telescope": SIMONYI_TELESCOPE,
57 # Migrate these to full translations once test data appears that
58 # includes them
59 "boresight_rotation_coord": "unknown",
60 "boresight_rotation_angle": None,
61 "boresight_airmass": None,
62 "tracking_radec": None,
63 "altaz_begin": None,
64 "object": "UNKNOWN",
65 "relative_humidity": None,
66 "temperature": None,
67 "pressure": None,
68 }
70 _trivial_map = {
71 "detector_group": "RAFTBAY",
72 "detector_name": "CCDSLOT",
73 "observation_id": "OBSID",
74 "exposure_time": ("EXPTIME", dict(unit=u.s)),
75 "detector_serial": "LSST_NUM",
76 "science_program": ("RUNNUM", dict(default="unknown"))
77 }
79 # Use Imsim raft definitions until a true lsstCam definition exists
80 cameraPolicyFile = "policy/lsstCam.yaml"
82 @classmethod
83 def fix_header(cls, header):
84 """See https://astro-metadata-translator.lsst.io/py-api/astro_metadata_translator.FitsTranslator.html#astro_metadata_translator.FitsTranslator.fix_header""" # noqa: E501, W505
86 if "FILTER" not in header and header.get("FILTER2") is not None:
87 obsid = header.get("OBSID", "unknown")
88 ccdslot = header.get("CCDSLOT", "unknown")
89 raftbay = header.get("RAFTBAY", "unknown")
91 log.warn("%s %s_%s: No FILTER key found but FILTER2=\"%s\" (removed)",
92 obsid, raftbay, ccdslot, header["FILTER2"])
93 header["FILTER2"] = None
95 return True
97 return False
99 @classmethod
100 def can_translate(cls, header, filename=None):
101 """Indicate whether this translation class can translate the
102 supplied header.
104 Parameters
105 ----------
106 header : `dict`-like
107 Header to convert to standardized form.
108 filename : `str`, optional
109 Name of file being translated.
111 Returns
112 -------
113 can : `bool`
114 `True` if the header is recognized by this class. `False`
115 otherwise.
116 """
117 # INSTRUME keyword might be of two types
118 if "INSTRUME" in header:
119 instrume = header["INSTRUME"].lower()
120 if instrume == cls.supported_instrument.lower():
121 return True
122 return False
124 @cache_translation
125 def to_physical_filter(self):
126 """Calculate the physical filter name.
128 Returns
129 -------
130 filter : `str`
131 Name of filter. Can be a combination of FILTER and FILTER2
132 headers joined by a "~" if FILTER2 is set and not empty.
133 Returns "UNKNOWN" if no filter is declared.
134 """
135 physical_filter = self._determine_primary_filter()
137 filter2 = None
138 if self.is_key_ok("FILTER2"):
139 self._used_these_cards("FILTER2")
140 filter2 = self._header["FILTER2"]
141 if self._is_filter_empty(filter2):
142 filter2 = None
144 if filter2:
145 physical_filter = f"{physical_filter}{FILTER_DELIMITER}{filter2}"
147 return physical_filter