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 

30 

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

32 

33 

34class LatissMakeRawVisitInfo(LsstCamMakeRawVisitInfo): 

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

36 metadataTranslator = LatissTranslator 

37 

38 

39class LatissMapper(LsstCamMapper): 

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

41 

42 MakeRawVisitInfoClass = LatissMakeRawVisitInfo 

43 

44 _cameraName = "latiss" 

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

46 filterDefinitions = LATISS_FILTER_DEFINITIONS 

47 

48 def _extractDetectorName(self, dataId): 

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

50 

51 def _computeCcdExposureId(self, dataId): 

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

53 

54 Parameters 

55 ---------- 

56 dataId : `dict` 

57 Data identifier including dayObs and seqNum. 

58 

59 Returns 

60 ------- 

61 id : `int` 

62 Integer identifier for a CCD exposure. 

63 """ 

64 if len(dataId) == 0: 

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

66 

67 if 'visit' in dataId: 

68 visit = dataId['visit'] 

69 else: 

70 if "controller" in dataId: 

71 controller = dataId["controller"] 

72 else: 

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

74 controller = "C" 

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

76 controller) 

77 

78 if "detector" in dataId: 

79 detector = dataId["detector"] 

80 if detector != 0: 

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

82 " always be 0", detector) 

83 else: 

84 detector = 0 

85 

86 return LatissTranslator.compute_detector_exposure_id(visit, detector) 

87 

88 

89class LatissParseTask(LsstCamParseTask): 

90 """Parser suitable for LATISS raw data. 

91 """ 

92 

93 _mapperClass = LatissMapper 

94 _translatorClass = LatissTranslator 

95 

96 def translate_seqNum(self, md): 

97 """Return the sequence number. 

98 

99 Parameters 

100 ---------- 

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

102 Image metadata. 

103 

104 Returns 

105 ------- 

106 seqnum : `int` 

107 The sequence number identifier valid within a day. 

108 """ 

109 

110 if "SEQNUM" in md: 

111 return md.getScalar("SEQNUM") 

112 # 

113 # Oh dear. Extract it from the filename 

114 # 

115 seqNum = 0 

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

117 if k not in md: 

118 continue 

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

120 # Trim trailing extensions 

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

122 

123 # Want final digits 

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

125 if mat: 

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

127 break 

128 

129 if seqNum == 0: 

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

131 logger.warn( 

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

133 

134 return seqNum