Coverage for tests/test_formatter.py : 36%

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 gen3 DECam raw formatter, which has to determine which
23HDU a given detector is in in a multi-extension FITS file.
24"""
26import astro_metadata_translator
27import unittest
28import os
30import lsst.utils.tests
31import lsst.obs.decam
32import lsst.daf.butler
33import lsst.afw.image
35testDataPackage = "testdata_decam"
36try:
37 testDataDirectory = lsst.utils.getPackageDir(testDataPackage)
38except LookupError:
39 testDataDirectory = None
42@unittest.skipIf(testDataDirectory is None, "testdata_decam must be set up")
43class DarkEnergyCameraRawFormatterTestCase(lsst.utils.tests.TestCase):
44 def setUp(self):
45 self.filename = os.path.join(testDataDirectory, 'rawData/2013-09-01/z/decam0229388.fits.fz')
46 location = lsst.daf.butler.Location(testDataDirectory, 'rawData/2013-09-01/z/decam0229388.fits.fz')
47 self.fileDescriptor = lsst.daf.butler.FileDescriptor(location, None)
49 def check_readMetadata(self, dataId, expected):
50 formatter = lsst.obs.decam.DarkEnergyCameraRawFormatter(self.fileDescriptor, dataId)
51 metadata = formatter.readMetadata()
52 self.assertEqual(metadata, expected)
54 def test_readMetadata(self):
55 dataId = {'detector': 25}
56 # detector 25 is in HDU 1
57 expected = lsst.afw.image.readMetadata(self.filename, 1)
58 self.assertEqual(expected['CCDNUM'], 25) # sanity check
59 self.check_readMetadata(dataId, expected)
61 dataId = {'detector': 1}
62 # detector 1 is in HDU 2
63 expected = lsst.afw.image.readMetadata(self.filename, 2)
64 astro_metadata_translator.fix_header(expected)
65 self.assertEqual(expected['CCDNUM'], 1) # sanity check
66 self.check_readMetadata(dataId, expected)
68 def test_readMetadata_raises(self):
69 dataId = {'detector': 70}
70 formatter = lsst.obs.decam.DarkEnergyCameraRawFormatter(self.fileDescriptor, dataId)
71 with self.assertRaisesRegex(ValueError, "detectorId=70"):
72 formatter.readMetadata()
74 def check_readImage(self, dataId, expected):
75 formatter = lsst.obs.decam.DarkEnergyCameraRawFormatter(self.fileDescriptor, dataId)
76 image = formatter.readImage()
77 self.assertImagesEqual(image, expected)
79 def test_readImage(self):
80 dataId = {'detector': 25}
81 # detector 25 is in HDU 1
82 expected = lsst.afw.image.ImageI(self.filename, 1)
83 self.check_readImage(dataId, expected)
85 dataId = {'detector': 1}
86 # detector 1 is in HDU 2
87 expected = lsst.afw.image.ImageI(self.filename, 2)
88 self.check_readImage(dataId, expected)
90 def test_readMetadata_full_file(self):
91 """Test reading a file with all HDUs, and with all HDUs in a shuffled
92 order.
93 """
95 full_file = 'rawData/raw/c4d_150227_012718_ori-stripped.fits.fz'
96 full_location = lsst.daf.butler.Location(testDataDirectory, full_file)
97 full_fileDescriptor = lsst.daf.butler.FileDescriptor(full_location, None)
99 shuffled_file = 'rawData/raw/c4d_150227_012718_ori-stripped-shuffled.fits.fz'
100 shuffled_location = lsst.daf.butler.Location(testDataDirectory, shuffled_file)
101 shuffled_fileDescriptor = lsst.daf.butler.FileDescriptor(shuffled_location, None)
103 for detector in range(1, 63):
104 formatter = lsst.obs.decam.DarkEnergyCameraRawFormatter(full_fileDescriptor, detector)
105 full_index, full_metadata = formatter._determineHDU(detector)
106 formatter = lsst.obs.decam.DarkEnergyCameraRawFormatter(shuffled_fileDescriptor, detector)
107 shuffled_index, shuffled_metadata = formatter._determineHDU(detector)
109 # The shuffled file should have different indices,
110 self.assertNotEqual(full_index, shuffled_index)
111 # but the metadata should be the same in both files.
112 self.assertEqual(shuffled_metadata, full_metadata)
115def setup_module(module):
116 lsst.utils.tests.init()
119if __name__ == "__main__": 119 ↛ 120line 119 didn't jump to line 120, because the condition on line 119 was never true
120 lsst.utils.tests.init()
121 unittest.main()