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__ = ("LsstCamRawFormatter", "LatissRawFormatter")
27from astro_metadata_translator import fix_header, merge_headers
29import lsst.afw.fits
30from lsst.obs.base import FitsRawFormatterBase
32from ._instrument import LsstCam, Latiss, \
33 LsstImSim, LsstPhoSim, LsstTS8, \
34 LsstTS3, LsstUCDCam, LsstComCam
35from .translators import LatissTranslator, LsstCamTranslator, \
36 LsstUCDCamTranslator, LsstTS3Translator, LsstComCamTranslator, \
37 LsstPhoSimTranslator, LsstTS8Translator, LsstImSimTranslator
38from .assembly import fixAmpsAndAssemble, readRawAmps
41class LsstCamRawFormatter(FitsRawFormatterBase):
42 translatorClass = LsstCamTranslator
43 filterDefinitions = LsstCam.filterDefinitions
44 _instrument = LsstCam
46 def readMetadata(self):
47 """Read all header metadata directly into a PropertyList.
49 Specialist version since some of our data does not
50 set INHERIT=T so we have to merge the headers manually.
52 Returns
53 -------
54 metadata : `~lsst.daf.base.PropertyList`
55 Header metadata.
56 """
57 file = self.fileDescriptor.location.path
58 phdu = lsst.afw.fits.readMetadata(file, 0)
59 if "INHERIT" in phdu: 59 ↛ 61line 59 didn't jump to line 61, because the condition on line 59 was never true
60 # Trust the inheritance flag
61 return super().readMetadata()
63 # Merge ourselves
64 md = merge_headers([phdu, lsst.afw.fits.readMetadata(file)],
65 mode="overwrite")
66 fix_header(md)
67 return md
69 def getDetector(self, id):
70 return self._instrument.getCamera()[id]
72 def readImage(self):
73 """Read just the image component of the Exposure.
75 Returns
76 -------
77 image : `~lsst.afw.image.Image`
78 In-memory image component.
79 """
80 return self.readFull().getImage()
82 def readFull(self, parameters=None):
83 """Read the complete exposure.
85 This correctly fixes amplifier bounding box deviations from
86 the camera definitions, and so should provide the safest
87 interface to the data.
89 Parameters
90 ----------
91 parameters : `dict`, optional
92 No parameters are currently used.
94 Returns
95 -------
96 exposure : `~lsst.afw.image.Exposure`
97 Complete in-memory exposure representation.
99 """
100 rawFile = self.fileDescriptor.location.path
101 ccd = self.getDetector(self.observationInfo.detector_num)
102 ampExps = readRawAmps(rawFile, ccd)
103 exposure = fixAmpsAndAssemble(ampExps, rawFile)
105 mask = self.readMask()
106 if mask is not None: 106 ↛ 107line 106 didn't jump to line 107, because the condition on line 106 was never true
107 exposure.setMask(mask)
108 variance = self.readVariance()
109 if variance is not None: 109 ↛ 110line 109 didn't jump to line 110, because the condition on line 109 was never true
110 exposure.setVariance(variance)
112 info = exposure.getInfo()
113 info.setFilter(self.makeFilter())
114 info.setVisitInfo(self.makeVisitInfo())
115 info.setWcs(self.makeWcs(info.getVisitInfo(), info.getDetector()))
117 exposure.setMetadata(self.metadata)
119 return exposure
122class LatissRawFormatter(LsstCamRawFormatter):
123 translatorClass = LatissTranslator
124 _instrument = Latiss
125 filterDefinitions = Latiss.filterDefinitions
128class LsstImSimRawFormatter(LsstCamRawFormatter):
129 translatorClass = LsstImSimTranslator
130 _instrument = LsstImSim
131 filterDefinitions = LsstImSim.filterDefinitions
134class LsstPhoSimRawFormatter(LsstCamRawFormatter):
135 translatorClass = LsstPhoSimTranslator
136 _instrument = LsstPhoSim
137 filterDefinitions = LsstPhoSim.filterDefinitions
140class LsstTS8RawFormatter(LsstCamRawFormatter):
141 translatorClass = LsstTS8Translator
142 _instrument = LsstTS8
143 filterDefinitions = LsstTS8.filterDefinitions
146class LsstTS3RawFormatter(LsstCamRawFormatter):
147 translatorClass = LsstTS3Translator
148 _instrument = LsstTS3
149 filterDefinitions = LsstTS3.filterDefinitions
152class LsstComCamRawFormatter(LsstCamRawFormatter):
153 translatorClass = LsstComCamTranslator
154 _instrument = LsstComCam
155 filterDefinitions = LsstComCam.filterDefinitions
158class LsstUCDCamRawFormatter(LsstCamRawFormatter):
159 translatorClass = LsstUCDCamTranslator
160 _instrument = LsstUCDCam
161 filterDefinitions = LsstUCDCam.filterDefinitions