Hide keyboard shortcuts

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/>. 

21 

22"""Gen3 Butler Formatters for LSST raw data. 

23""" 

24 

25__all__ = ( 

26 "LsstCamRawFormatter", 

27 "LatissRawFormatter", 

28 "LsstCamImSimRawFormatter", 

29 "LsstCamPhoSimRawFormatter", 

30 "LsstTS8RawFormatter", 

31 "LsstTS3RawFormatter", 

32 "LsstComCamRawFormatter", 

33 "LsstUCDCamRawFormatter", 

34) 

35 

36from astro_metadata_translator import fix_header, merge_headers 

37 

38import lsst.afw.fits 

39from lsst.obs.base import FitsRawFormatterBase 

40 

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 

48 

49 

50class LsstCamRawFormatter(FitsRawFormatterBase): 

51 translatorClass = LsstCamTranslator 

52 filterDefinitions = LsstCam.filterDefinitions 

53 _instrument = LsstCam 

54 

55 def readMetadata(self): 

56 """Read all header metadata directly into a PropertyList. 

57 

58 Specialist version since some of our data does not 

59 set INHERIT=T so we have to merge the headers manually. 

60 

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() 

71 

72 # Merge ourselves 

73 md = merge_headers([phdu, lsst.afw.fits.readMetadata(file)], 

74 mode="overwrite") 

75 fix_header(md) 

76 return md 

77 

78 def getDetector(self, id): 

79 return self._instrument.getCamera()[id] 

80 

81 def readImage(self): 

82 """Read just the image component of the Exposure. 

83 

84 Returns 

85 ------- 

86 image : `~lsst.afw.image.Image` 

87 In-memory image component. 

88 """ 

89 return self.readFull().getImage() 

90 

91 def readFull(self, parameters=None): 

92 """Read the complete exposure. 

93 

94 This correctly fixes amplifier bounding box deviations from 

95 the camera definitions, and so should provide the safest 

96 interface to the data. 

97 

98 Parameters 

99 ---------- 

100 parameters : `dict`, optional 

101 No parameters are currently used. 

102 

103 Returns 

104 ------- 

105 exposure : `~lsst.afw.image.Exposure` 

106 Complete in-memory exposure representation. 

107 

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) 

113 

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) 

120 

121 info = exposure.getInfo() 

122 info.setFilterLabel(self.makeFilterLabel()) 

123 info.setVisitInfo(self.makeVisitInfo()) 

124 info.setWcs(self.makeWcs(info.getVisitInfo(), info.getDetector())) 

125 

126 exposure.setMetadata(self.metadata) 

127 

128 return exposure 

129 

130 

131class LatissRawFormatter(LsstCamRawFormatter): 

132 translatorClass = LatissTranslator 

133 _instrument = Latiss 

134 filterDefinitions = Latiss.filterDefinitions 

135 wcsFlipX = True 

136 

137 

138class LsstCamImSimRawFormatter(LsstCamRawFormatter): 

139 translatorClass = LsstCamImSimTranslator 

140 _instrument = LsstCamImSim 

141 filterDefinitions = LsstCamImSim.filterDefinitions 

142 

143 

144class LsstCamPhoSimRawFormatter(LsstCamRawFormatter): 

145 translatorClass = LsstCamPhoSimTranslator 

146 _instrument = LsstCamPhoSim 

147 filterDefinitions = LsstCamPhoSim.filterDefinitions 

148 

149 

150class LsstTS8RawFormatter(LsstCamRawFormatter): 

151 translatorClass = LsstTS8Translator 

152 _instrument = LsstTS8 

153 filterDefinitions = LsstTS8.filterDefinitions 

154 

155 

156class LsstTS3RawFormatter(LsstCamRawFormatter): 

157 translatorClass = LsstTS3Translator 

158 _instrument = LsstTS3 

159 filterDefinitions = LsstTS3.filterDefinitions 

160 

161 

162class LsstComCamRawFormatter(LsstCamRawFormatter): 

163 translatorClass = LsstComCamTranslator 

164 _instrument = LsstComCam 

165 filterDefinitions = LsstComCam.filterDefinitions 

166 

167 

168class LsstUCDCamRawFormatter(LsstCamRawFormatter): 

169 translatorClass = LsstUCDCamTranslator 

170 _instrument = LsstUCDCam 

171 filterDefinitions = LsstUCDCam.filterDefinitions