Coverage for python/lsst/obs/lsst/latiss.py: 37%

Shortcuts 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

56 statements  

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 logging 

24import os.path 

25import re 

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 translatorClass = LatissTranslator 

50 

51 def _extractDetectorName(self, dataId): 

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

53 

54 def _computeCcdExposureId(self, dataId): 

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

56 

57 Parameters 

58 ---------- 

59 dataId : `dict` 

60 Data identifier including dayObs and seqNum. 

61 

62 Returns 

63 ------- 

64 id : `int` 

65 Integer identifier for a CCD exposure. 

66 """ 

67 if len(dataId) == 0: 

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

69 

70 if 'visit' in dataId: 

71 visit = dataId['visit'] 

72 else: 

73 if "controller" in dataId: 

74 controller = dataId["controller"] 

75 else: 

76 logging.getLogger("LsstLatissMapper").warning("Controller unknown, using 'C'") 

77 controller = "C" 

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

79 controller) 

80 

81 if "detector" in dataId: 

82 detector = dataId["detector"] 

83 if detector != 0: 

84 logging.getLogger("LatissMapper").warning("Got detector %d for LATISS when it should" 

85 " always be 0", detector) 

86 else: 

87 detector = 0 

88 

89 return LatissTranslator.compute_detector_exposure_id(visit, detector) 

90 

91 

92class LatissParseTask(LsstCamParseTask): 

93 """Parser suitable for LATISS raw data. 

94 """ 

95 

96 _mapperClass = LatissMapper 

97 _translatorClass = LatissTranslator 

98 

99 def translate_seqNum(self, md): 

100 """Return the sequence number. 

101 

102 Parameters 

103 ---------- 

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

105 Image metadata. 

106 

107 Returns 

108 ------- 

109 seqnum : `int` 

110 The sequence number identifier valid within a day. 

111 """ 

112 

113 if "SEQNUM" in md: 

114 return md.getScalar("SEQNUM") 

115 # 

116 # Oh dear. Extract it from the filename 

117 # 

118 seqNum = 0 

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

120 if k not in md: 

121 continue 

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

123 # Trim trailing extensions 

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

125 

126 # Want final digits 

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

128 if mat: 

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

130 break 

131 

132 if seqNum == 0: 

133 logger = logging.getLogger('obs.lsst.LatissParseTask') 

134 logger.warning( 

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

136 

137 return seqNum