Coverage for tests/test_isr.py: 33%
64 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-10 09:47 +0000
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-10 09:47 +0000
1# This file is part of obs_cfht.
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/>.
21#
22import os
23import unittest
25import lsst.afw.image as afwImage
26import lsst.utils.tests
28from lsst.obs.cfht import MegaPrime
29from lsst.obs.cfht.cfhtIsrTask import CfhtIsrTask
32testDataPackage = "testdata_cfht"
33try:
34 testDataDirectory = lsst.utils.getPackageDir(testDataPackage)
35except LookupError:
36 testDataDirectory = None
39@unittest.skipIf(testDataDirectory is None, "Skipping tests as testdata_cfht is not setup")
40class CfhtIsrTestCase(lsst.utils.tests.TestCase):
41 """Test for the CFHT IsrTask wrapper."""
43 def setUp(self):
44 # We'll need a detector, so get the first one.
45 self.camera = MegaPrime().getCamera()
46 detector = self.camera[0]
48 # Get the override.
49 self.configPath = "resource://lsst.obs.cfht/resources/config/isr.py"
50 # Read the image data.
51 imageLocation = os.path.join(testDataDirectory, "DATA/raw/08BL05/w2.+2+2/2008-11-01/i2",
52 "1038843o.fits.fz")
53 self.exposure = self.imageHandler(imageLocation, detector)
55 @staticmethod
56 def imageHandler(location, detector=None):
57 """Quick method to handle image reading.
59 Parameters
60 ----------
61 location : `str`
62 FITS file location.
63 detector : `lsst.afw.cameraGeom.Detector`, optional
64 Detector to attach to the exposure.
66 Returns
67 -------
68 exp : `lsst.afw.image.Exposure`
69 Fully constructed exposure.
70 """
71 if detector:
72 hdu = detector.getId() + 1
73 else:
74 hdu = 1
76 reader = afwImage.ExposureFitsReader(location)
77 imReader = afwImage.ImageFitsReader(location, hdu=hdu)
79 exp = afwImage.makeExposure(afwImage.makeMaskedImage(imReader.read()))
80 exp.setMetadata(reader.readMetadata())
81 exp.setInfo(reader.readExposureInfo())
83 if detector:
84 exp.setDetector(detector)
86 return exp
88 def test_processing(self):
89 # Process image and confirm it doesn't fail.
91 config = CfhtIsrTask.ConfigClass()
93 # Manually fix config.
94 config.doDark = False
95 config.doDefect = False
96 config.doFlat = False
97 config.doBias = False
98 config.doFringe = False
99 config.fringeAfterFlat = False
100 config.doWrite = False
101 config.fringe.filters = ["i.MP9701", "i.MP9702", "z.MP9801"]
102 config.fringe.pedestal = True
103 config.fringe.small = 1
104 config.fringe.large = 50
105 config.doAssembleIsrExposures = True
106 config.doSuspect = False
107 config.fluxMag0T1 = {"i.MP9702": 100.0}
109 task = CfhtIsrTask(config=config)
110 results = task.run(self.exposure, camera=self.camera)
111 md = results.exposure.getMetadata()
112 amplifiers = list(results.exposure.getDetector().getAmplifiers())
114 # Check that saturation level are set correctly.
115 self.assertEqual(md['SATURATE'], 65535)
117 # Check that the gain and read noise match what is in the
118 # GAINA and GAINB/RDNOISEA RDNOISEB fields.
119 self.assertEqual(md['GAINA'], amplifiers[0].getGain())
120 self.assertEqual(md['GAINB'], amplifiers[1].getGain())
121 self.assertEqual(md['RDNOISEA'], amplifiers[0].getReadNoise())
122 self.assertEqual(md['RDNOISEB'], amplifiers[1].getReadNoise())
125class MemoryTester(lsst.utils.tests.MemoryTestCase):
126 pass
129def setup_module(module):
130 lsst.utils.tests.init()
133if __name__ == "__main__": 133 ↛ 134line 133 didn't jump to line 134 because the condition on line 133 was never true
134 lsst.utils.tests.init()
135 unittest.main()