Coverage for python/lsst/obs/lsst/rawFormatter.py : 92%

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"""Gen3 Butler Formatters for LSST raw data.
23"""
25__all__ = (
26 "LsstCamRawFormatter",
27 "LatissRawFormatter",
28 "LsstCamImSimRawFormatter",
29 "LsstCamPhoSimRawFormatter",
30 "LsstTS8RawFormatter",
31 "LsstTS3RawFormatter",
32 "LsstComCamRawFormatter",
33 "LsstUCDCamRawFormatter",
34)
36from astro_metadata_translator import fix_header, merge_headers
38import lsst.afw.fits
39from lsst.obs.base import FitsRawFormatterBase
41from ._instrument import LsstCam, Latiss, \
42 LsstCamImSim, LsstCamPhoSim, LsstTS8, \
43 LsstTS3, LsstUCDCam, LsstComCam
44from .translators import LatissTranslator, LsstCamTranslator, \
45 LsstUCDCamTranslator, LsstTS3Translator, LsstComCamTranslator, \
46 LsstCamPhoSimTranslator, LsstTS8Translator, LsstCamImSimTranslator
47from .assembly import fixAmpsAndAssemble, readRawAmps
50class LsstCamRawFormatter(FitsRawFormatterBase):
51 translatorClass = LsstCamTranslator
52 filterDefinitions = LsstCam.filterDefinitions
53 _instrument = LsstCam
55 def readMetadata(self):
56 """Read all header metadata directly into a PropertyList.
58 Specialist version since some of our data does not
59 set INHERIT=T so we have to merge the headers manually.
61 Returns
62 -------
63 metadata : `~lsst.daf.base.PropertyList`
64 Header metadata.
65 """
66 file = self.fileDescriptor.location.path
67 phdu = lsst.afw.fits.readMetadata(file, 0)
68 if "INHERIT" in phdu: 68 ↛ 70line 68 didn't jump to line 70, because the condition on line 68 was never true
69 # Trust the inheritance flag
70 return super().readMetadata()
72 # Merge ourselves
73 md = merge_headers([phdu, lsst.afw.fits.readMetadata(file)],
74 mode="overwrite")
75 fix_header(md)
76 return md
78 def getDetector(self, id):
79 return self._instrument.getCamera()[id]
81 def readImage(self):
82 """Read just the image component of the Exposure.
84 Returns
85 -------
86 image : `~lsst.afw.image.Image`
87 In-memory image component.
88 """
89 return self.readFull().getImage()
91 def readFull(self, parameters=None):
92 """Read the complete exposure.
94 This correctly fixes amplifier bounding box deviations from
95 the camera definitions, and so should provide the safest
96 interface to the data.
98 Parameters
99 ----------
100 parameters : `dict`, optional
101 No parameters are currently used.
103 Returns
104 -------
105 exposure : `~lsst.afw.image.Exposure`
106 Complete in-memory exposure representation.
108 """
109 rawFile = self.fileDescriptor.location.path
110 ccd = self.getDetector(self.observationInfo.detector_num)
111 ampExps = readRawAmps(rawFile, ccd)
112 exposure = fixAmpsAndAssemble(ampExps, rawFile)
114 mask = self.readMask()
115 if mask is not None: 115 ↛ 116line 115 didn't jump to line 116, because the condition on line 115 was never true
116 exposure.setMask(mask)
117 variance = self.readVariance()
118 if variance is not None: 118 ↛ 119line 118 didn't jump to line 119, because the condition on line 118 was never true
119 exposure.setVariance(variance)
121 info = exposure.getInfo()
122 info.setFilter(self.makeFilter())
123 info.setVisitInfo(self.makeVisitInfo())
124 info.setWcs(self.makeWcs(info.getVisitInfo(), info.getDetector()))
126 exposure.setMetadata(self.metadata)
128 return exposure
131class LatissRawFormatter(LsstCamRawFormatter):
132 translatorClass = LatissTranslator
133 _instrument = Latiss
134 filterDefinitions = Latiss.filterDefinitions
135 wcsFlipX = True
138class LsstCamImSimRawFormatter(LsstCamRawFormatter):
139 translatorClass = LsstCamImSimTranslator
140 _instrument = LsstCamImSim
141 filterDefinitions = LsstCamImSim.filterDefinitions
144class LsstCamPhoSimRawFormatter(LsstCamRawFormatter):
145 translatorClass = LsstCamPhoSimTranslator
146 _instrument = LsstCamPhoSim
147 filterDefinitions = LsstCamPhoSim.filterDefinitions
150class LsstTS8RawFormatter(LsstCamRawFormatter):
151 translatorClass = LsstTS8Translator
152 _instrument = LsstTS8
153 filterDefinitions = LsstTS8.filterDefinitions
156class LsstTS3RawFormatter(LsstCamRawFormatter):
157 translatorClass = LsstTS3Translator
158 _instrument = LsstTS3
159 filterDefinitions = LsstTS3.filterDefinitions
162class LsstComCamRawFormatter(LsstCamRawFormatter):
163 translatorClass = LsstComCamTranslator
164 _instrument = LsstComCam
165 filterDefinitions = LsstComCam.filterDefinitions
168class LsstUCDCamRawFormatter(LsstCamRawFormatter):
169 translatorClass = LsstUCDCamTranslator
170 _instrument = LsstUCDCam
171 filterDefinitions = LsstUCDCam.filterDefinitions