Coverage for python/lsst/obs/subaru/gen3/hsc/gen2to3.py : 93%

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_subaru.
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 GNU General Public License
20# along with this program. If not, see <http://www.gnu.org/licenses/>.
22"""Gen2->Gen3 Data repo conversion specializations for Hyper Suprime-Cam
23"""
25from lsst.obs.base.gen2to3 import Translator, KeyHandler, ConstantKeyHandler, CopyKeyHandler
27from ....hsc.hscFilters import HSC_FILTER_DEFINITIONS
30__all__ = ()
33class HscAbstractFilterKeyHandler(KeyHandler):
34 """KeyHandler for HSC filter keys that should be mapped to AbstractFilters.
35 """
37 __slots__ = ("_map",)
39 def __init__(self):
40 super().__init__("abstract_filter")
41 self._map = {d.physical_filter: d.abstract_filter for d in HSC_FILTER_DEFINITIONS
42 if d.physical_filter is not None}
44 def extract(self, gen2id, skyMap, skyMapName, datasetTypeName):
45 physical = gen2id["filter"]
46 return self._map.get(physical, physical)
49# Add instrument to Gen3 data ID if Gen2 contains "visit" or "ccd".
50# (Both rules will match, so we'll actually set instrument in the same dict twice).
51Translator.addRule(ConstantKeyHandler("instrument", "HSC"),
52 instrument="HSC", gen2keys=("visit",), consume=False)
53Translator.addRule(ConstantKeyHandler("instrument", "HSC"),
54 instrument="HSC", gen2keys=("ccd",), consume=False)
56# Copy Gen2 'visit' to Gen3 'exposure' for raw only. Also consume filter,
57# since that's implied by 'exposure' in Gen3.
58Translator.addRule(CopyKeyHandler("exposure", "visit"),
59 instrument="HSC", datasetTypeName="raw", gen2keys=("visit",),
60 consume=("visit", "filter"))
62# Copy Gen2 'visit' to Gen3 'visit' otherwise. Also consume filter.
63Translator.addRule(CopyKeyHandler("visit"), instrument="HSC", gen2keys=("visit",),
64 consume=("visit", "filter"))
66# Copy Gen2 'ccd' to Gen3 'detector;
67Translator.addRule(CopyKeyHandler("detector", "ccd"), instrument="HSC", gen2keys=("ccd",))
69# Translate Gen2 `filter` to AbstractFilter if it hasn't been consumed yet and gen2keys includes tract.
70Translator.addRule(HscAbstractFilterKeyHandler(), instrument="HSC", gen2keys=("filter", "tract"),
71 consume=("filter",))
73# Add instrument for HSC transmission curve datasets (transmission_sensor is
74# already handled by the above translators).
75Translator.addRule(ConstantKeyHandler("instrument", "HSC"),
76 instrument="HSC", datasetTypeName="transmission_optics")
77Translator.addRule(ConstantKeyHandler("instrument", "HSC"),
78 instrument="HSC", datasetTypeName="transmission_atmosphere")
79Translator.addRule(ConstantKeyHandler("instrument", "HSC"),
80 instrument="HSC", datasetTypeName="transmission_filter")
81Translator.addRule(CopyKeyHandler("physical_filter", "filter"),
82 instrument="HSC", datasetTypeName="transmission_filter")
84# Add calibration mapping for filter for filter dependent types
85for calibType in ('flat', 'sky', 'fringe'):
86 Translator.addRule(CopyKeyHandler("physical_filter", "filter"),
87 instrument="HSC", datasetTypeName=calibType)