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

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
32__all__ = ["LatissMapper", "LatissParseTask"]
35class LatissMakeRawVisitInfo(LsstCamMakeRawVisitInfo):
36 """Make a VisitInfo from the FITS header of a raw image."""
37 metadataTranslator = LatissTranslator
40class LatissMapper(LsstCamMapper):
41 """The Mapper for the LATISS camera."""
43 MakeRawVisitInfoClass = LatissMakeRawVisitInfo
44 _gen3instrument = Latiss
46 _cameraName = "latiss"
47 yamlFileList = ["latiss/latissMapper.yaml"] + list(LsstCamMapper.yamlFileList)
48 filterDefinitions = LATISS_FILTER_DEFINITIONS
49 translatorClass = LatissTranslator
51 def _extractDetectorName(self, dataId):
52 return f"{LatissTranslator.DETECTOR_GROUP_NAME}_{LatissTranslator.DETECTOR_NAME}"
54 def _computeCcdExposureId(self, dataId):
55 """Compute the 64-bit (long) identifier for a CCD exposure.
57 Parameters
58 ----------
59 dataId : `dict`
60 Data identifier including dayObs and seqNum.
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
70 if 'visit' in dataId:
71 visit = dataId['visit']
72 else:
73 if "controller" in dataId:
74 controller = dataId["controller"]
75 else:
76 lsst.log.Log.getLogger("LsstLatissMapper").warn("Controller unknown, using 'C'")
77 controller = "C"
78 visit = LatissTranslator.compute_exposure_id(dataId['dayObs'], dataId["seqNum"],
79 controller)
81 if "detector" in dataId:
82 detector = dataId["detector"]
83 if detector != 0:
84 lsst.log.Log.getLogger("LatissMapper").warn("Got detector %d for LATISS when it should"
85 " always be 0", detector)
86 else:
87 detector = 0
89 return LatissTranslator.compute_detector_exposure_id(visit, detector)
92class LatissParseTask(LsstCamParseTask):
93 """Parser suitable for LATISS raw data.
94 """
96 _mapperClass = LatissMapper
97 _translatorClass = LatissTranslator
99 def translate_seqNum(self, md):
100 """Return the sequence number.
102 Parameters
103 ----------
104 md : `~lsst.daf.base.PropertyList` or `~lsst.daf.base.PropertySet`
105 Image metadata.
107 Returns
108 -------
109 seqnum : `int`
110 The sequence number identifier valid within a day.
111 """
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]
126 # Want final digits
127 mat = re.search(r"(\d+)$", name)
128 if mat:
129 seqNum = int(mat.group(1)) # 00008
130 break
132 if seqNum == 0:
133 logger = lsst.log.Log.getLogger('obs.lsst.LatissParseTask')
134 logger.warn(
135 'Could not determine sequence number. Assuming %d ', seqNum)
137 return seqNum