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

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(f"{self._log_prefix}: 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, instrument, obsid, filename=None):
84 """Fix LSSTCam headers.
86 Notes
87 -----
88 See `~astro_metadata_translator.fix_header` for details of the general
89 process.
90 """
92 modified = False
94 # Calculate the standard label to use for log messages
95 log_label = cls._construct_log_prefix(obsid, filename)
97 if "FILTER" not in header and header.get("FILTER2") is not None:
98 ccdslot = header.get("CCDSLOT", "unknown")
99 raftbay = header.get("RAFTBAY", "unknown")
101 log.warn("%s %s_%s: No FILTER key found but FILTER2=\"%s\" (removed)",
102 log_label, raftbay, ccdslot, header["FILTER2"])
103 header["FILTER2"] = None
104 modified = True
106 return modified
108 @classmethod
109 def can_translate(cls, header, filename=None):
110 """Indicate whether this translation class can translate the
111 supplied header.
113 Parameters
114 ----------
115 header : `dict`-like
116 Header to convert to standardized form.
117 filename : `str`, optional
118 Name of file being translated.
120 Returns
121 -------
122 can : `bool`
123 `True` if the header is recognized by this class. `False`
124 otherwise.
125 """
126 # INSTRUME keyword might be of two types
127 if "INSTRUME" in header:
128 instrume = header["INSTRUME"].lower()
129 if instrume == cls.supported_instrument.lower():
130 return True
131 return False
133 @cache_translation
134 def to_physical_filter(self):
135 """Calculate the physical filter name.
137 Returns
138 -------
139 filter : `str`
140 Name of filter. Can be a combination of FILTER and FILTER2
141 headers joined by a "~" if FILTER2 is set and not empty.
142 Returns "UNKNOWN" if no filter is declared.
143 """
144 physical_filter = self._determine_primary_filter()
146 filter2 = None
147 if self.is_key_ok("FILTER2"):
148 self._used_these_cards("FILTER2")
149 filter2 = self._header["FILTER2"]
150 if self._is_filter_empty(filter2):
151 filter2 = None
153 if filter2:
154 physical_filter = f"{physical_filter}{FILTER_DELIMITER}{filter2}"
156 return physical_filter