Coverage for python/lsst/obs/lsst/translators/ts3.py : 65%

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 LSST BNL TestStand 3 headers"""
13__all__ = ("LsstTS3Translator", )
15import logging
16import re
17import os.path
19import astropy.units as u
20from astropy.time import Time, TimeDelta
22from astro_metadata_translator import cache_translation
24from .lsst import LsstBaseTranslator
26log = logging.getLogger(__name__)
28# There is only a single sensor at a time so define a
29# fixed sensor name
30_DETECTOR_NAME = "S00"
33class LsstTS3Translator(LsstBaseTranslator):
34 """Metadata translator for LSST BNL Test Stand 3 data.
35 """
37 name = "LSST-TS3"
38 """Name of this translation class"""
40 _const_map = {
41 # TS3 is not attached to a telescope so many translations are null.
42 "instrument": "LSST-TS3",
43 "telescope": None,
44 "location": None,
45 "boresight_rotation_coord": None,
46 "boresight_rotation_angle": None,
47 "boresight_airmass": None,
48 "tracking_radec": None,
49 "altaz_begin": None,
50 "object": "UNKNOWN",
51 "relative_humidity": None,
52 "temperature": None,
53 "pressure": None,
54 "detector_name": _DETECTOR_NAME, # Single sensor
55 }
57 _trivial_map = {
58 "detector_serial": "LSST_NUM",
59 "physical_filter": "FILTER",
60 "exposure_time": ("EXPTIME", dict(unit=u.s)),
61 }
63 DETECTOR_NAME = _DETECTOR_NAME
64 """Fixed name of single sensor."""
66 DETECTOR_MAX = 999
67 """Maximum number of detectors to use when calculating the
68 detector_exposure_id."""
70 cameraPolicyFile = "policy/ts3.yaml"
72 _ROLLOVER_TIME = TimeDelta(8*60*60, scale="tai", format="sec")
73 """Time delta for the definition of a Rubin Test Stand start of day."""
75 @classmethod
76 def can_translate(cls, header, filename=None):
77 """Indicate whether this translation class can translate the
78 supplied header.
80 There is no usable ``INSTRUME`` header in TS3 data. Instead we use
81 the ``TSTAND`` header.
83 Parameters
84 ----------
85 header : `dict`-like
86 Header to convert to standardized form.
87 filename : `str`, optional
88 Name of file being translated.
90 Returns
91 -------
92 can : `bool`
93 `True` if the header is recognized by this class. `False`
94 otherwise.
95 """
96 return cls.can_translate_with_options(header, {"TSTAND": "BNL-TS3-2-Janeway"}, filename=filename)
98 @staticmethod
99 def compute_exposure_id(dateobs, seqnum=0, controller=None):
100 """Helper method to calculate the TS3 exposure_id.
102 Parameters
103 ----------
104 dateobs : `str`
105 Date of observation in FITS ISO format.
106 seqnum : `int`, unused
107 Sequence number. Ignored.
108 controller : `str`, unused
109 Controller type. Ignored.
111 Returns
112 -------
113 exposure_id : `int`
114 Exposure ID.
115 """
116 # There is worry that seconds are too coarse so use 10th of second
117 # and read the first 21 characters.
118 exposure_id = re.sub(r"\D", "", dateobs[:21])
119 return int(exposure_id)
121 @cache_translation
122 def to_datetime_begin(self):
123 # Docstring will be inherited. Property defined in properties.py
124 self._used_these_cards("MJD-OBS")
125 return Time(self._header["MJD-OBS"], scale="utc", format="mjd")
127 def to_exposure_id(self):
128 """Generate a unique exposure ID number
130 Note that SEQNUM is not unique for a given day in TS3 data
131 so instead we convert the ISO date of observation directly to an
132 integer.
134 Returns
135 -------
136 exposure_id : `int`
137 Unique exposure number.
138 """
139 iso = self._header["DATE-OBS"]
140 self._used_these_cards("DATE-OBS")
142 return self.compute_exposure_id(iso)
144 # For now assume that visit IDs and exposure IDs are identical
145 to_visit_id = to_exposure_id
147 @cache_translation
148 def to_science_program(self):
149 """Calculate the science program information.
151 There is no header recording this in TS3 data so instead return
152 the observing day in YYYY-MM-DD format.
154 Returns
155 -------
156 run : `str`
157 Observing day in YYYY-MM-DD format.
158 """
159 # Get a copy so that we can edit the default formatting
160 date = self.to_datetime_begin().copy()
161 date.format = "iso"
162 date.out_subfmt = "date" # YYYY-MM-DD format
163 return str(date)
165 @cache_translation
166 def to_observation_id(self):
167 # Docstring will be inherited. Property defined in properties.py
168 filename = self._header["FILENAME"]
169 self._used_these_cards("FILENAME")
170 return os.path.splitext(filename)[0]
172 @cache_translation
173 def to_detector_group(self):
174 # Docstring will be inherited. Property defined in properties.py
175 serial = self.to_detector_serial()
176 detector_info = self.compute_detector_info_from_serial(serial)
177 return detector_info[0]