Coverage for tests/test_isrMockLSST.py: 23%
66 statements
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-15 02:10 -0700
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-15 02:10 -0700
1#
2# LSST Data Management System
3# Copyright 2008-2017 AURA/LSST.
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 <https://www.lsstcorp.org/LegalNotices/>.
21#
23import unittest
24import numpy as np
26import lsst.utils.tests
28import lsst.afw.image as afwImage
29import lsst.ip.isr.isrMockLSST as isrMockLSST
32class IsrMockLSSTCases(lsst.utils.tests.TestCase):
33 """Test the generation of IsrMockLSST data.
34 """
35 def setUp(self):
36 self.inputExp = isrMockLSST.TrimmedRawMockLSST().run()
37 self.mi = self.inputExp.getMaskedImage()
39 def test_simple(self):
40 """Check trimmed raw data are generated as expected,
41 taking the same approach as in test_isrMock.
42 """
44 initialMean = np.median(self.mi.getImage().getArray()[:])
45 initialStd = np.std(self.mi.getImage().getArray()[:])
47 # Build and subtract a bias calibration
48 bias = isrMockLSST.BiasMockLSST().run()
49 self.mi.getImage().getArray()[:] = (self.mi.getImage().getArray()[:]
50 - bias.getMaskedImage().getImage().getArray()[:])
51 newMean = np.median(self.mi.getImage().getArray()[:])
52 newStd = np.std(self.mi.getImage().getArray()[:])
54 self.assertAlmostEqual(newStd, initialStd)
56 initialMean = newMean
57 initialStd = newStd
59 dark = isrMockLSST.DarkMockLSST().run()
60 self.mi.getImage().getArray()[:] = (self.mi.getImage().getArray()[:]
61 - dark.getMaskedImage().getImage().getArray()[:])
62 newMean = np.median(self.mi.getImage().getArray()[:])
63 newStd = np.std(self.mi.getImage().getArray()[:])
65 self.assertLess(newMean, initialMean)
67 initialMean = newMean
68 initialStd = newStd
70 flat = isrMockLSST.FlatMockLSST().run()
71 self.mi.getImage().getArray()[:] = (self.mi.getImage().getArray()[:]
72 - flat.getMaskedImage().getImage().getArray()[:])
73 newMean = np.median(self.mi.getImage().getArray()[:])
74 newStd = np.std(self.mi.getImage().getArray()[:])
76 self.assertAlmostEqual(newMean, initialMean, -2)
77 self.assertLess(newStd, initialStd)
79 initialMean = newMean
80 initialStd = newStd
82 fringe = isrMockLSST.FringeMockLSST().run()
83 self.mi.getImage().getArray()[:] = (self.mi.getImage().getArray()[:]
84 - fringe.getMaskedImage().getImage().getArray()[:])
85 newMean = np.median(self.mi.getImage().getArray()[:])
86 newStd = np.std(self.mi.getImage().getArray()[:])
88 self.assertAlmostEqual(newMean, initialMean, -1)
89 self.assertAlmostEqual(newStd, initialStd, -1)
91 def test_untrimmedSimple(self):
92 """Test untrimmed mocks are genetared.
93 """
94 exposureLowNoise = isrMockLSST.RawMockLSST().run()
96 rawMock = isrMockLSST.RawMockLSST()
97 rawMock.config.readNoise = 100.
98 exposureHighNoise = rawMock.run()
100 lowNoiseStd = np.std(exposureLowNoise.getMaskedImage().getImage().getArray()[:])
101 highNoiseStd = np.std(exposureHighNoise.getMaskedImage().getImage().getArray()[:])
103 self.assertLess(lowNoiseStd, highNoiseStd)
105 def test_productTypes(self):
106 """Tests non-image data are returned as the expected type,
107 taking the same approach as in test_isrMock.
108 """
109 self.assertIsInstance(isrMockLSST.BfKernelMockLSST().run(), np.ndarray)
110 self.assertIsInstance(isrMockLSST.CrosstalkCoeffMockLSST().run(), np.ndarray)
112 self.assertIsInstance(isrMockLSST.DefectMockLSST().run()[0], lsst.meas.algorithms.Defect)
113 self.assertIsInstance(isrMockLSST.TransmissionMockLSST().run(), afwImage.TransmissionCurve)
115 def test_edgeCases(self):
116 """Tests that improperly specified configurations do not return data,
117 taking the same approach as in test_isrMock
118 """
119 config = isrMockLSST.IsrMockLSSTConfig()
120 self.assertIsNone(isrMockLSST.IsrMockLSST(config=config).run())
122 with self.assertRaises(RuntimeError):
123 config.doGenerateData = True
124 isrMockLSST.IsrMockLSST(config=config).run()
127class MemoryTester(lsst.utils.tests.MemoryTestCase):
128 pass
131def setup_module(module):
132 lsst.utils.tests.init()
135if __name__ == "__main__": 135 ↛ 136line 135 didn't jump to line 136, because the condition on line 135 was never true
136 lsst.utils.tests.init()
137 unittest.main()