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

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 # Docstring inherited.
80 return self._instrument.getCamera()[id]
82 def readImage(self):
83 # Docstring inherited.
84 return self.readFull().getImage()
86 def readFull(self):
87 # Docstring inherited.
88 rawFile = self.fileDescriptor.location.path
89 ccd = self.getDetector(self.observationInfo.detector_num)
90 ampExps = readRawAmps(rawFile, ccd)
91 exposure = fixAmpsAndAssemble(ampExps, rawFile)
92 self.attachComponentsFromMetadata(exposure)
93 return exposure
96class LatissRawFormatter(LsstCamRawFormatter):
97 translatorClass = LatissTranslator
98 _instrument = Latiss
99 filterDefinitions = Latiss.filterDefinitions
100 wcsFlipX = True
103class LsstCamImSimRawFormatter(LsstCamRawFormatter):
104 translatorClass = LsstCamImSimTranslator
105 _instrument = LsstCamImSim
106 filterDefinitions = LsstCamImSim.filterDefinitions
109class LsstCamPhoSimRawFormatter(LsstCamRawFormatter):
110 translatorClass = LsstCamPhoSimTranslator
111 _instrument = LsstCamPhoSim
112 filterDefinitions = LsstCamPhoSim.filterDefinitions
115class LsstTS8RawFormatter(LsstCamRawFormatter):
116 translatorClass = LsstTS8Translator
117 _instrument = LsstTS8
118 filterDefinitions = LsstTS8.filterDefinitions
121class LsstTS3RawFormatter(LsstCamRawFormatter):
122 translatorClass = LsstTS3Translator
123 _instrument = LsstTS3
124 filterDefinitions = LsstTS3.filterDefinitions
127class LsstComCamRawFormatter(LsstCamRawFormatter):
128 translatorClass = LsstComCamTranslator
129 _instrument = LsstComCam
130 filterDefinitions = LsstComCam.filterDefinitions
133class LsstUCDCamRawFormatter(LsstCamRawFormatter):
134 translatorClass = LsstUCDCamTranslator
135 _instrument = LsstUCDCam
136 filterDefinitions = LsstUCDCam.filterDefinitions