Coverage for tests/test_parseCalibsGen2.py : 33%

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_decam.
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"""Unit tests for gen2 DECam calibration product parsing, a precursor to ingestion.
23"""
25import unittest
26import os
27import lsst.utils.tests
28from lsst.obs.decam import ingestCalibs
29import lsst.daf.persistence as dafPersist
30from lsst.afw.fits import readMetadata
32testDataPackage = "testdata_decam"
33try:
34 testDataDirectory = lsst.utils.getPackageDir(testDataPackage)
35except LookupError:
36 testDataDirectory = None
39@unittest.skipIf(testDataDirectory is None, "testdata_decam must be set up")
40class DecamCalibsParseTaskTestCase(lsst.utils.tests.TestCase):
41 """Test the methods in DecamCalibsParseTask.
43 Uses a bias+flat pair of LSST-Science-Pipeline-built calibs as well as
44 a bias+flat pair of DECam Community Pipeline calibs, all full of zeros,
45 which live in testdata_decam.
46 """
47 def setUp(self):
48 self.task = ingestCalibs.DecamCalibsParseTask(name='ItsATest')
50 # LSST-Science-Pipeline-built calibration products, full of zeros
51 self.biasFile = os.path.join(testDataDirectory, "pipeline-calibs", "BIAS", "BIAS-47.fits")
52 self.flatFile = os.path.join(testDataDirectory, "pipeline-calibs", "FLAT", "FLAT-g-47.fits")
54 # DECam Community Pipeline calibration products, also full of zeros
55 cpBiasFilename = "c4d_150218_191721_zci_v1.fits.fz"
56 self.cpBiasFile = os.path.join(testDataDirectory, "hits2015-zeroed", cpBiasFilename)
57 cpFlatFilename = "c4d_150218_200522_fci_g_v1.fits.fz"
58 self.cpFlatFile = os.path.join(testDataDirectory, "hits2015-zeroed", cpFlatFilename)
60 # A Butler repository with ingested raws and Community Pipeline calibs
61 repo = os.path.join(testDataDirectory, "ingested")
62 calibRepo = os.path.join(testDataDirectory, "calibingested")
63 self.butler = dafPersist.Butler(root=repo, calibRoot=calibRepo)
65 def checkGetInfo(self, filename):
66 """Test that the filepath and a calib_hdu value of 1 is in the info.
67 """
68 phuInfo, infoList = self.task.getInfo(filename)
69 self.assertEqual(phuInfo['calib_hdu'], 1)
70 self.assertIn('path', phuInfo)
71 for item in infoList:
72 self.assertEqual(item['calib_hdu'], 1)
73 self.assertIn('path', item)
75 def testLsstCalibsGetInfo(self):
76 """Test that the filepath and a calib_hdu value of 1 is in the info.
77 """
78 # LSST-Science-Pipelines-built bias
79 self.checkGetInfo(self.biasFile)
81 # LSST-Science-Pipelines-built flat
82 self.checkGetInfo(self.flatFile)
84 def testLsstCalibsGetDestination(self):
85 """Test that file path destinations conform to the mapper templates.
86 """
87 # LSST-Science-Pipelines-built bias
88 dataId = {'ccdnum': 1, 'date': '2015-02-18'}
89 filename = self.task.getDestination(self.butler, dataId, self.biasFile)
90 self.assertIn(f"BIAS/{dataId['date']}/BIAS-{dataId['date']}-{dataId['ccdnum']:02}.fits", filename)
91 self.assertNotIn('[', filename)
93 # LSST-Science-Pipelines-built flat
94 dataId = {'ccdnum': 1, 'date': '2015-02-18', 'filter': 'g'}
95 filename = self.task.getDestination(self.butler, dataId, self.flatFile)
96 self.assertIn(f"FLAT/{dataId['date']}/{dataId['filter']}/"
97 + f"FLAT-{dataId['date']}-{dataId['ccdnum']:02}.fits", filename)
98 self.assertNotIn('[', filename)
100 def testLsstCalibsTranslateFilter(self):
101 """Test that filter is set to "NONE" for the bias and "g" for the flat.
102 """
103 # LSST-Science-Pipelines-built bias
104 md = readMetadata(self.biasFile, self.task.config.hdu)
105 biasFilter = self.task.translate_filter(md)
106 self.assertEqual(biasFilter, "NONE")
108 # LSST-Science-Pipelines-built flat
109 md = readMetadata(self.flatFile, self.task.config.hdu)
110 flatFilter = self.task.translate_filter(md)
111 self.assertEqual(flatFilter, "g")
113 def testCpCalibsGetInfo(self):
114 """Test that the filepath and a calib_hdu value of 1 is in the info.
115 """
116 # DECam Community Pipeline bias
117 self.checkGetInfo(self.cpBiasFile)
119 # DECam Community Pipeline flat
120 self.checkGetInfo(self.cpFlatFile)
122 def testCpCalibsGetDestination(self):
123 """Test that file path destinations conform to the mapper templates.
124 """
125 # DECam Community Pipeline bias
126 dataId = {'ccdnum': 1, 'date': '2015-02-18'}
127 filename = self.task.getDestination(self.butler, dataId, self.cpBiasFile)
128 self.assertIn(f"cpBIAS/{dataId['date']}/BIAS-{dataId['date']}.fits", filename)
129 self.assertNotIn('[', filename)
131 # DECam Community Pipeline flat
132 dataId = {'ccdnum': 1, 'date': '2015-02-18', 'filter': 'g'}
133 filename = self.task.getDestination(self.butler, dataId, self.cpFlatFile)
134 self.assertIn(f"cpFLAT/{dataId['date']}/{dataId['filter']}/FLAT-{dataId['date']}.fits", filename)
135 self.assertNotIn('[', filename)
137 def testCpCalibsTranslateFilter(self):
138 """Test that filter is set to "NONE" for the cpBias and "g" for the cpFlat.
139 """
140 # DECam Community Pipeline bias
141 md = readMetadata(self.cpBiasFile, self.task.config.hdu)
142 cpBiasFilter = self.task.translate_filter(md)
143 self.assertEqual(cpBiasFilter, "NONE")
145 # DECam Community Pipeline flat
146 md = readMetadata(self.cpFlatFile, self.task.config.hdu)
147 cpFlatFilter = self.task.translate_filter(md)
148 self.assertEqual(cpFlatFilter, "g")
151def setup_module(module):
152 lsst.utils.tests.init()
155if __name__ == "__main__": 155 ↛ 156line 155 didn't jump to line 156, because the condition on line 155 was never true
156 lsst.utils.tests.init()
157 unittest.main()