Coverage for python/lsst/obs/cfht/ingest.py: 30%
53 statements
« prev ^ index » next coverage.py v6.4.1, created at 2022-06-05 03:19 -0700
« prev ^ index » next coverage.py v6.4.1, created at 2022-06-05 03:19 -0700
1#
2# LSST Data Management System
3# Copyright 2012 LSST Corporation.
4#
5# This product includes software developed by the
6# LSST Project (http://www.lsst.org/).
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation, either version 3 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the LSST License Statement and
19# the GNU General Public License along with this program. If not,
20# see <http://www.lsstcorp.org/LegalNotices/>.
21#
23__all__ = ["MegacamParseTask", "MegaPrimeRawIngestTask"]
25import re
27from deprecated.sphinx import deprecated
29import lsst.obs.base
31from lsst.pipe.tasks.ingest import ParseTask
32import lsst.pex.exceptions
34filters = {'u.MP9301': 'u',
35 'u.MP9302': 'u2',
36 'g.MP9401': 'g',
37 'g.MP9402': 'g2',
38 'r.MP9601': 'r',
39 'r.MP9602': 'r2',
40 'i.MP9701': 'i',
41 'i.MP9702': 'i2',
42 'i.MP9703': 'i3',
43 'z.MP9801': 'z',
44 'z.MP9901': 'z2',
45 }
48@deprecated(reason="MegaPrime no longer requires a specialist gen3 ingest task. Please use the default."
49 " Will be removed after v23.",
50 category=FutureWarning,
51 version="22.0")
52class MegaPrimeRawIngestTask(lsst.obs.base.RawIngestTask):
53 """Task for ingesting raw MegaPrime multi-extension FITS data into Gen3.
54 """
57class MegacamParseTask(ParseTask):
59 def translate_ccd(self, md):
60 try:
61 extname = self.getExtensionName(md)
62 return int(extname[3:]) # chop off "ccd"
63 except LookupError:
64 # Dummy value, intended for PHU (need something to get filename)
65 return 99
67 def translate_filter(self, md):
68 filtName = md.getScalar("FILTER").strip()
69 if filtName not in filters:
70 return "UNKNOWN"
71 return filters[filtName]
73 def translate_taiObs(self, md):
74 # Field name is "taiObs" but we're giving it UTC; shouldn't matter so
75 # long as we're consistent
76 (yr, month, day) = (md.getScalar("DATE-OBS").strip()).split("-")
77 (hr, min, sec) = (md.getScalar("UTC-OBS").strip()).split(":")
78 (sec1, sec2) = sec.split('.')
79 return "%04d-%02d-%02dT%02d:%02d:%02d.%02d"%(int(yr), int(month), int(day),
80 int(hr), int(min), int(sec1), int(sec2))
82 def translate_defects(self, md):
83 maskName = md.getScalar("IMRED_MK").strip()
84 maskName, ccd = maskName.split(".fits")
85 filter = md.getScalar("FILTER").strip().split('.')[0]
86 if filter in ["i", "i2", "i3", "z", "z2"]:
87 maskName = maskName+"_enlarged"
88 maskFile = maskName+".nn/"+ccd[1:6]+".fits"
89 return maskFile
91 def getInfo(self, filename):
92 phuInfo, infoList = super(MegacamParseTask, self).getInfo(filename)
93 match = re.search(r"\d+(?P<state>o|p)\.fits.*", filename)
94 if not match:
95 raise RuntimeError("Unable to parse filename: %s" % filename)
96 phuInfo['state'] = match.group('state')
97 phuInfo['extension'] = 0
98 for num, info in enumerate(infoList):
99 info['state'] = match.group('state')
100 info['extension'] = num + 1
101 return phuInfo, infoList
103 def getExtensionName(self, md):
104 """Get the name of an extension.
106 Parameters
107 ----------
108 md : `PropertySet`
109 Metadata to get the name from.
111 Returns
112 -------
113 name : `str` or None
114 Name of the extension if it exists. None otherwise.
115 """
116 # We have to overwrite this method because some (mostly recent) Megacam
117 # images have a different header where the keword "EXTNAME" appears one
118 # time instead of two. In the later case ext is a tuple while in the
119 # other case it is a single value
120 try:
121 # This returns a tuple
122 ext = md.getScalar("EXTNAME")
123 # Most of the time the EXTNAME keyword appears 2 times in the
124 # header (1st time to specify that the image is compressed) but
125 # sometimes it appears only once even if the image is compressed
126 if type(ext) == tuple or type(ext) == list:
127 return ext[1]
128 else:
129 return ext
130 except lsst.pex.exceptions.Exception:
131 return None