Coverage for tests/test_mergeResults.py: 16%
69 statements
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-10 03:51 -0700
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-10 03:51 -0700
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 """
61 expMergeTask = cpVerify.CpVerifyExpMergeTask()
62 expResults1 = expMergeTask.run(self.detectorResults1, self.detectorDimensions1, self.camera)
63 expResults2 = expMergeTask.run(self.detectorResults2, self.detectorDimensions2, self.camera)
64 self.assertTrue(expResults1.outputStats['SUCCESS'])
65 self.assertFalse(expResults2.outputStats['SUCCESS']) # Expected to have one failure
66 self.assertEqual(expResults2.outputStats['R:1,0 S:1,0']['FAILURES'][0], "C:0,2 SIGMA_TEST")
68 # Prep inputs to full calibration run merge.
69 inputStats = [expResults1.outputStats, expResults2.outputStats]
70 inputDims = [{'exposure': 1}, {'exposure': 2}]
72 runMergeTask = cpVerify.CpVerifyRunMergeTask()
74 runResults = runMergeTask.run(inputStats, inputDims, self.camera)
75 self.assertFalse(runResults.outputStats['SUCCESS'])
77 # We know this one failed.
78 failureList = runResults.outputStats[2]['FAILURES']
79 self.assertEqual(len(failureList), 1)
80 self.assertEqual(failureList[0], "R:1,0 S:1,0 C:0,2 SIGMA_TEST")
82 def generateDetectorResults(self, detector, mean=10.0, sigma=1.2, threshold=14.0):
83 """Make the simulated verify statistics.
85 Parameters
86 ----------
87 detector : `lsst.afw.cameraGeom.Detector`
88 Detector geometry to make statistics for.
89 mean : `float`
90 Center of the random normal distribution to pull
91 statistics from.
92 sigma : `float`
93 Sigma of the normal distribution.
94 threshold : `float`
95 Test threshold above which a test is a "failure".
97 Returns
98 -------
99 detectorStats : `dict` [`str`, `dict`]
100 Nested dictionary of verify statistics.
101 """
103 valueNames = ['MEAN', 'SIGMA', 'VALUE']
105 ampDict = dict()
106 detDict = dict()
107 catDict = dict()
108 success = True
109 for amp in detector.getAmplifiers():
110 ampName = amp.getName()
111 ampDict[ampName] = dict()
112 for value in valueNames:
113 ampDict[ampName][value] = np.random.normal(10.0, 1.2)
115 ampVerify = dict()
116 detVerify = dict()
117 catVerify = dict()
118 expVerify = 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, 'EXP': expVerify}}
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()