Coverage for tests/test_mergeResults.py: 17%
67 statements
« prev ^ index » next coverage.py v6.5.0, created at 2024-03-15 21:23 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2024-03-15 21:23 +0000
1# This file is part of cp_verify.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://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 <https://www.gnu.org/licenses/>.
22import numpy as np
23import unittest
25import lsst.utils.tests
26import lsst.afw.cameraGeom as cameraGeom
27import lsst.cp.verify as cpVerify
30class MergeResultsTestCase(lsst.utils.tests.TestCase):
31 """Unit test for merge code.
32 """
34 def setUp(self):
35 # Generate a camera.
36 self.camera = cameraGeom.testUtils.CameraWrapper(isLsstLike=False).camera
38 # Fix the seed so we can expect consistent results.
39 np.random.seed(12345)
41 # Make first exposure
42 self.detectorResults1 = list()
43 self.detectorDimensions1 = list()
44 for detector in self.camera:
45 dimensions = {'exposure': 1, 'detector': detector.getId()}
46 self.detectorDimensions1.append(dimensions)
47 self.detectorResults1.append(self.generateDetectorResults(detector))
49 # Make second exposure
50 self.detectorResults2 = list()
51 self.detectorDimensions2 = list()
52 for detector in self.camera:
53 dimensions = {'exposure': 2, 'detector': detector.getId()}
54 self.detectorDimensions2.append(dimensions)
55 self.detectorResults2.append(self.generateDetectorResults(detector))
57 def test_merging(self):
58 """Generate simulated verify statistics, and prove they merge
59 correctly.
60 """
62 expMergeTask = cpVerify.CpVerifyExpMergeTask()
64 expResults1 = expMergeTask.run(self.detectorResults1, self.camera, self.detectorDimensions1)
65 expResults2 = expMergeTask.run(self.detectorResults2, self.camera, self.detectorDimensions2)
66 self.assertTrue(expResults1.outputStats['SUCCESS'])
67 self.assertFalse(expResults2.outputStats['SUCCESS']) # Expected to have one failure
69 # Prep inputs to full calibration run merge.
70 inputStats = [expResults1.outputStats, expResults2.outputStats]
71 inputDims = [{'exposure': 1}, {'exposure': 2}]
73 runMergeTask = cpVerify.CpVerifyRunMergeTask()
75 runResults = runMergeTask.run(inputStats, inputDims)
76 self.assertFalse(runResults.outputStats['SUCCESS'])
78 # We know this one failed.
79 failureList = runResults.outputStats[2]['FAILURES']
80 self.assertEqual(len(failureList), 1)
81 self.assertEqual(failureList[0], "R:1,0 S:1,0 C:0,2 SIGMA_TEST")
83 def generateDetectorResults(self, detector, mean=10.0, sigma=1.2, threshold=14.0):
84 """Make the simulated verify statistics.
86 Parameters
87 ----------
88 detector : `lsst.afw.cameraGeom.Detector`
89 Detector geometry to make statistics for.
90 mean : `float`
91 Center of the random normal distribution to pull
92 statistics from.
93 sigma : `float`
94 Sigma of the normal distribution.
95 threshold : `float`
96 Test threshold above which a test is a "failure".
98 Returns
99 -------
100 detectorStats : `dict` [`str`, `dict`]
101 Nested dictionary of verify statistics.
102 """
104 valueNames = ['MEAN', 'SIGMA', 'VALUE']
106 ampDict = dict()
107 detDict = dict()
108 catDict = dict()
109 success = True
110 for amp in detector.getAmplifiers():
111 ampName = amp.getName()
112 ampDict[ampName] = dict()
113 for value in valueNames:
114 ampDict[ampName][value] = np.random.normal(10.0, 1.2)
116 ampVerify = dict()
117 detVerify = dict()
118 catVerify = dict()
119 for ampName in ampDict:
120 ampVerify[ampName] = dict()
121 ampSuccess = True
122 for value in valueNames:
123 if ampDict[ampName][value] < threshold:
124 ampVerify[ampName][value + "_TEST"] = True
125 else:
126 ampVerify[ampName][value + "_TEST"] = False
127 ampSuccess = False
128 success = False
129 ampVerify[ampName]['SUCCESS'] = ampSuccess
130 return {'SUCCESS': success, 'AMP': ampDict, 'DET': detDict, 'CATALOG': catDict,
131 'VERIFY': {'AMP': ampVerify, 'DET': detVerify, 'CATALOG': catVerify}}
134class MemoryTester(lsst.utils.tests.MemoryTestCase):
135 pass
138def setup_module(module):
139 lsst.utils.tests.init()
142if __name__ == "__main__": 142 ↛ 143line 142 didn't jump to line 143, because the condition on line 142 was never true
143 lsst.utils.tests.init()
144 unittest.main()