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

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

58 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 elif 'expId' in dataId: 

73 visit = dataId['expId'] 

74 else: 

75 if "controller" in dataId: 

76 controller = dataId["controller"] 

77 else: 

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

79 controller = "C" 

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

81 controller) 

82 

83 if "detector" in dataId: 

84 detector = dataId["detector"] 

85 if detector != 0: 

86 logging.getLogger("lsst.LsstLatissMapper").warning("Got detector %d for LATISS when it should" 

87 " always be 0", detector) 

88 else: 

89 detector = 0 

90 

91 return LatissTranslator.compute_detector_exposure_id(visit, detector) 

92 

93 

94class LatissParseTask(LsstCamParseTask): 

95 """Parser suitable for LATISS raw data. 

96 """ 

97 

98 _mapperClass = LatissMapper 

99 _translatorClass = LatissTranslator 

100 

101 def translate_seqNum(self, md): 

102 """Return the sequence number. 

103 

104 Parameters 

105 ---------- 

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

107 Image metadata. 

108 

109 Returns 

110 ------- 

111 seqnum : `int` 

112 The sequence number identifier valid within a day. 

113 """ 

114 

115 if "SEQNUM" in md: 

116 return md.getScalar("SEQNUM") 

117 # 

118 # Oh dear. Extract it from the filename 

119 # 

120 seqNum = 0 

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

122 if k not in md: 

123 continue 

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

125 # Trim trailing extensions 

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

127 

128 # Want final digits 

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

130 if mat: 

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

132 break 

133 

134 if seqNum == 0: 

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

136 logger.warning( 

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

138 

139 return seqNum