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 LSST License Statement and 

20# the GNU General Public License along with this program. If not, 

21# see <http://www.lsstcorp.org/LegalNotices/>. 

22# 

23import os.path 

24import re 

25import lsst.log 

26from . import LsstCamMapper, LsstCamMakeRawVisitInfo 

27from .ingest import LsstCamParseTask 

28from .translators import LatissTranslator 

29from .filters import LATISS_FILTER_DEFINITIONS 

30from ._instrument import Latiss 

31 

32__all__ = ["LatissMapper", "LatissParseTask"] 

33 

34 

35class LatissMakeRawVisitInfo(LsstCamMakeRawVisitInfo): 

36 """Make a VisitInfo from the FITS header of a raw image.""" 

37 metadataTranslator = LatissTranslator 

38 

39 

40class LatissMapper(LsstCamMapper): 

41 """The Mapper for the LATISS camera.""" 

42 

43 MakeRawVisitInfoClass = LatissMakeRawVisitInfo 

44 _gen3instrument = Latiss 

45 

46 _cameraName = "latiss" 

47 yamlFileList = ["latiss/latissMapper.yaml"] + list(LsstCamMapper.yamlFileList) 

48 filterDefinitions = LATISS_FILTER_DEFINITIONS 

49 

50 def _extractDetectorName(self, dataId): 

51 return f"{LatissTranslator.DETECTOR_GROUP_NAME}_{LatissTranslator.DETECTOR_NAME}" 

52 

53 def _computeCcdExposureId(self, dataId): 

54 """Compute the 64-bit (long) identifier for a CCD exposure. 

55 

56 Parameters 

57 ---------- 

58 dataId : `dict` 

59 Data identifier including dayObs and seqNum. 

60 

61 Returns 

62 ------- 

63 id : `int` 

64 Integer identifier for a CCD exposure. 

65 """ 

66 if len(dataId) == 0: 

67 return 0 # give up. Useful if reading files without a butler 

68 

69 if 'visit' in dataId: 

70 visit = dataId['visit'] 

71 else: 

72 if "controller" in dataId: 

73 controller = dataId["controller"] 

74 else: 

75 lsst.log.Log.getLogger("LsstLatissMapper").warn("Controller unknown, using 'C'") 

76 controller = "C" 

77 visit = LatissTranslator.compute_exposure_id(dataId['dayObs'], dataId["seqNum"], 

78 controller) 

79 

80 if "detector" in dataId: 

81 detector = dataId["detector"] 

82 if detector != 0: 

83 lsst.log.Log.getLogger("LatissMapper").warn("Got detector %d for LATISS when it should" 

84 " always be 0", detector) 

85 else: 

86 detector = 0 

87 

88 return LatissTranslator.compute_detector_exposure_id(visit, detector) 

89 

90 

91class LatissParseTask(LsstCamParseTask): 

92 """Parser suitable for LATISS raw data. 

93 """ 

94 

95 _mapperClass = LatissMapper 

96 _translatorClass = LatissTranslator 

97 

98 def translate_seqNum(self, md): 

99 """Return the sequence number. 

100 

101 Parameters 

102 ---------- 

103 md : `~lsst.daf.base.PropertyList` or `~lsst.daf.base.PropertySet` 

104 Image metadata. 

105 

106 Returns 

107 ------- 

108 seqnum : `int` 

109 The sequence number identifier valid within a day. 

110 """ 

111 

112 if "SEQNUM" in md: 

113 return md.getScalar("SEQNUM") 

114 # 

115 # Oh dear. Extract it from the filename 

116 # 

117 seqNum = 0 

118 for k in ("IMGNAME", "FILENAME"): 

119 if k not in md: 

120 continue 

121 name = md.getScalar(k) # e.g. AT-O-20180816-00008 

122 # Trim trailing extensions 

123 name = os.path.splitext(name)[0] 

124 

125 # Want final digits 

126 mat = re.search(r"(\d+)$", name) 

127 if mat: 

128 seqNum = int(mat.group(1)) # 00008 

129 break 

130 

131 if seqNum == 0: 

132 logger = lsst.log.Log.getLogger('obs.lsst.LatissParseTask') 

133 logger.warn( 

134 'Could not determine sequence number. Assuming %d ', seqNum) 

135 

136 return seqNum