Coverage for python/lsst/obs/lsst/_instrument.py : 59%

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 part of obs_lsst.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (http://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <http://www.gnu.org/licenses/>.
22__all__ = ("LsstCam", "LsstImSim", "LsstPhoSim", "LsstTS8",
23 "Latiss", "LsstTS3", "LsstUCDCam", "LsstComCam")
25import os.path
27import lsst.obs.base.yamlCamera as yamlCamera
28from lsst.daf.butler.core.utils import getFullTypeName
29from lsst.utils import getPackageDir
30from lsst.obs.base import Instrument
31from lsst.obs.base.gen2to3 import TranslatorFactory
32from .filters import LSSTCAM_FILTER_DEFINITIONS, LATISS_FILTER_DEFINITIONS, \
33 LSST_IMSIM_FILTER_DEFINITIONS
35from .translators import LatissTranslator, LsstCamTranslator, \
36 LsstUCDCamTranslator, LsstTS3Translator, LsstComCamTranslator, \
37 LsstPhoSimTranslator, LsstTS8Translator, LsstImSimTranslator
39PACKAGE_DIR = getPackageDir("obs_lsst")
42class LsstCam(Instrument):
43 """Gen3 Butler specialization for the LSST Main Camera.
45 Parameters
46 ----------
47 camera : `lsst.cameraGeom.Camera`
48 Camera object from which to extract detector information.
49 filters : `list` of `FilterDefinition`
50 An ordered list of filters to define the set of PhysicalFilters
51 associated with this instrument in the registry.
53 While both the camera geometry and the set of filters associated with a
54 camera are expected to change with time in general, their Butler Registry
55 representations defined by an Instrument do not. Instead:
57 - We only extract names, IDs, and purposes from the detectors in the
58 camera, which should be static information that actually reflects
59 detector "slots" rather than the physical sensors themselves. Because
60 the distinction between physical sensors and slots is unimportant in
61 the vast majority of Butler use cases, we just use "detector" even
62 though the concept really maps better to "detector slot". Ideally in
63 the future this distinction between static and time-dependent
64 information would be encoded in cameraGeom itself (e.g. by making the
65 time-dependent Detector class inherit from a related class that only
66 carries static content).
68 - The Butler Registry is expected to contain physical_filter entries for
69 all filters an instrument has ever had, because we really only care
70 about which filters were used for particular observations, not which
71 filters were *available* at some point in the past. And changes in
72 individual filters over time will be captured as changes in their
73 TransmissionCurve datasets, not changes in the registry content (which
74 is really just a label). While at present Instrument and Registry
75 do not provide a way to add new physical_filters, they will in the
76 future.
77 """
78 filterDefinitions = LSSTCAM_FILTER_DEFINITIONS
79 instrument = "LSSTCam"
80 policyName = "lsstCam"
81 translatorClass = LsstCamTranslator
82 obsDataPackage = "obs_lsst_data"
84 @property
85 def configPaths(self):
86 return [os.path.join(PACKAGE_DIR, "config"),
87 os.path.join(PACKAGE_DIR, "config", self.policyName)]
89 @classmethod
90 def getName(cls):
91 # Docstring inherited from Instrument.getName
92 return cls.instrument
94 @classmethod
95 def getCamera(cls):
96 # Constructing a YAML camera takes a long time but we rely on
97 # yamlCamera to cache for us.
98 cameraYamlFile = os.path.join(PACKAGE_DIR, "policy", f"{cls.policyName}.yaml")
99 camera = yamlCamera.makeCamera(cameraYamlFile)
100 if camera.getName() != cls.getName():
101 raise RuntimeError(f"Expected to read camera geometry for {cls.instrument}"
102 f" but instead got geometry for {cls._camera.getName()}")
103 return camera
105 def getRawFormatter(self, dataId):
106 # Docstring inherited from Instrument.getRawFormatter
107 # local import to prevent circular dependency
108 from .rawFormatter import LsstCamRawFormatter
109 return LsstCamRawFormatter
111 def register(self, registry):
112 # Docstring inherited from Instrument.register
113 # The maximum values below make Gen3's ObservationDataIdPacker produce
114 # outputs that match Gen2's ccdExposureId.
115 obsMax = self.translatorClass.max_detector_exposure_id()
116 registry.insertDimensionData("instrument",
117 {"name": self.getName(),
118 "detector_max": self.translatorClass.DETECTOR_MAX,
119 "visit_max": obsMax,
120 "exposure_max": obsMax,
121 "class_name": getFullTypeName(self),
122 })
124 records = [self.extractDetectorRecord(detector) for detector in self.getCamera()]
125 registry.insertDimensionData("detector", *records)
127 self._registerFilters(registry)
129 def extractDetectorRecord(self, camGeomDetector):
130 """Create a Gen3 Detector entry dict from a cameraGeom.Detector.
131 """
132 # All of the LSST instruments have detector names like R??_S??; we'll
133 # split them up here, and instruments with only one raft can override
134 # to change the group to something else if desired.
135 # Long-term, we should get these fields into cameraGeom separately
136 # so there's no need to specialize at this stage.
137 # They are separate in ObservationInfo
138 group, name = camGeomDetector.getName().split("_")
140 # getType() returns a pybind11-wrapped enum, which unfortunately
141 # has no way to extract the name of just the value (it's always
142 # prefixed by the enum type name).
143 purpose = str(camGeomDetector.getType()).split(".")[-1]
145 return dict(
146 instrument=self.getName(),
147 id=camGeomDetector.getId(),
148 full_name=camGeomDetector.getName(),
149 name_in_raft=name,
150 purpose=purpose,
151 raft=group,
152 )
154 def makeDataIdTranslatorFactory(self) -> TranslatorFactory:
155 # Docstring inherited from lsst.obs.base.Instrument.
156 factory = TranslatorFactory()
157 factory.addGenericInstrumentRules(self.getName(), detectorKey="detector", exposureKey="expId")
158 return factory
161class LsstComCam(LsstCam):
162 """Gen3 Butler specialization for ComCam data.
163 """
165 instrument = "LSSTComCam"
166 policyName = "comCam"
167 translatorClass = LsstComCamTranslator
169 def getRawFormatter(self, dataId):
170 # local import to prevent circular dependency
171 from .rawFormatter import LsstComCamRawFormatter
172 return LsstComCamRawFormatter
175class LsstImSim(LsstCam):
176 """Gen3 Butler specialization for ImSim simulations.
177 """
179 instrument = "LSST-ImSim"
180 policyName = "imsim"
181 translatorClass = LsstImSimTranslator
182 filterDefinitions = LSST_IMSIM_FILTER_DEFINITIONS
184 def getRawFormatter(self, dataId):
185 # local import to prevent circular dependency
186 from .rawFormatter import LsstImSimRawFormatter
187 return LsstImSimRawFormatter
190class LsstPhoSim(LsstCam):
191 """Gen3 Butler specialization for Phosim simulations.
192 """
194 instrument = "LSST-PhoSim"
195 policyName = "phosim"
196 translatorClass = LsstPhoSimTranslator
198 def getRawFormatter(self, dataId):
199 # local import to prevent circular dependency
200 from .rawFormatter import LsstPhoSimRawFormatter
201 return LsstPhoSimRawFormatter
204class LsstTS8(LsstCam):
205 """Gen3 Butler specialization for raft test stand data.
206 """
208 instrument = "LSST-TS8"
209 policyName = "ts8"
210 translatorClass = LsstTS8Translator
212 def getRawFormatter(self, dataId):
213 # local import to prevent circular dependency
214 from .rawFormatter import LsstTS8RawFormatter
215 return LsstTS8RawFormatter
218class LsstUCDCam(LsstCam):
219 """Gen3 Butler specialization for UCDCam test stand data.
220 """
222 instrument = "LSST-UCDCam"
223 policyName = "ucd"
224 translatorClass = LsstUCDCamTranslator
226 def getRawFormatter(self, dataId):
227 # local import to prevent circular dependency
228 from .rawFormatter import LsstUCDCamRawFormatter
229 return LsstUCDCamRawFormatter
232class LsstTS3(LsstCam):
233 """Gen3 Butler specialization for TS3 test stand data.
234 """
236 instrument = "LSST-TS3"
237 policyName = "ts3"
238 translatorClass = LsstTS3Translator
240 def getRawFormatter(self, dataId):
241 # local import to prevent circular dependency
242 from .rawFormatter import LsstTS3RawFormatter
243 return LsstTS3RawFormatter
246class Latiss(LsstCam):
247 """Gen3 Butler specialization for AuxTel LATISS data.
248 """
249 filterDefinitions = LATISS_FILTER_DEFINITIONS
250 instrument = "LATISS"
251 policyName = "latiss"
252 translatorClass = LatissTranslator
254 def extractDetectorRecord(self, camGeomDetector):
255 # Override to remove group (raft) name, because LATISS only has one
256 # detector.
257 record = super().extractDetectorRecord(camGeomDetector)
258 record["raft"] = None
259 record["name_in_raft"] = record["full_name"]
260 return record
262 def getRawFormatter(self, dataId):
263 # local import to prevent circular dependency
264 from .rawFormatter import LatissRawFormatter
265 return LatissRawFormatter