Coverage for tests / test_EvaluateLocalCalibration.py: 27%

77 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-05-06 08:36 +0000

1# This file is part of ap_association. 

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/>. 

21 

22import logging 

23import numpy as np 

24import unittest 

25 

26import lsst.geom 

27import lsst.utils.tests 

28import lsst.meas.base.tests 

29 

30 

31class TestLocalPhotoCalibration(lsst.meas.base.tests.AlgorithmTestCase, 

32 lsst.utils.tests.TestCase): 

33 

34 def setUp(self): 

35 self.pluginName = "base_LocalPhotoCalib" 

36 self.center = lsst.geom.Point2D(50.1, 49.8) 

37 self.bbox = lsst.geom.Box2I(lsst.geom.Point2I(-20, -30), 

38 lsst.geom.Extent2I(140, 160)) 

39 self.dataset = lsst.meas.base.tests.TestDataset(self.bbox) 

40 self.dataset.addSource(100000.0, self.center) 

41 

42 def tearDown(self): 

43 del self.center 

44 del self.bbox 

45 del self.dataset 

46 

47 def testPhotoCalib(self): 

48 task = self.makeSingleFrameMeasurementTask(self.pluginName) 

49 exposure, catalog = self.dataset.realize(10.0, task.schema, randomSeed=0) 

50 task.run(catalog, exposure) 

51 record = catalog[0] 

52 

53 calib = exposure.getPhotoCalib().getLocalCalibration(self.center) 

54 calibErr = exposure.getPhotoCalib().getCalibrationErr() 

55 self.assertEqual(record.get(self.pluginName), calib) 

56 self.assertEqual(record.get(self.pluginName + "Err"), calibErr) 

57 

58 def testPhotoCalibIsNone(self): 

59 with self.assertNoLogs(level=logging.WARNING) and self.assertLogs(level=logging.DEBUG): 

60 task = self.makeSingleFrameMeasurementTask(self.pluginName) 

61 exposure, catalog = self.dataset.realize(10.0, task.schema, randomSeed=0) 

62 exposure.setPhotoCalib(None) 

63 task.run(catalog, exposure) 

64 record = catalog[0] 

65 

66 self.assertTrue(np.isnan(record.get(self.pluginName))) 

67 self.assertTrue(np.isnan(record.get(self.pluginName + "Err"))) 

68 self.assertTrue(record.get(self.pluginName + "_flag")) 

69 

70 

71class TestLocalWcs(lsst.meas.base.tests.AlgorithmTestCase, 

72 lsst.utils.tests.TestCase): 

73 

74 def setUp(self): 

75 self.pluginName = "base_LocalWcs" 

76 self.center = lsst.geom.Point2D(50.1, 49.8) 

77 self.bbox = lsst.geom.Box2I(lsst.geom.Point2I(-20, -30), 

78 lsst.geom.Extent2I(140, 160)) 

79 self.dataset = lsst.meas.base.tests.TestDataset(self.bbox) 

80 self.dataset.addSource(100000.0, self.center) 

81 

82 def tearDown(self): 

83 del self.center 

84 del self.bbox 

85 del self.dataset 

86 

87 def testMatrix(self): 

88 task = self.makeSingleFrameMeasurementTask(self.pluginName) 

89 exposure, catalog = self.dataset.realize(10.0, 

90 task.schema, 

91 randomSeed=0) 

92 task.run(catalog, exposure) 

93 record = catalog[0] 

94 

95 # Get CdMatrix from afw. Convert from degrees to radians. 

96 trueCdMatrix = np.radians(exposure.getWcs().getCdMatrix()) 

97 self.assertAlmostEqual(record.get(self.pluginName + "_CDMatrix_1_1"), 

98 trueCdMatrix[0, 0]) 

99 self.assertAlmostEqual(record.get(self.pluginName + "_CDMatrix_2_1"), 

100 trueCdMatrix[1, 0]) 

101 self.assertAlmostEqual(record.get(self.pluginName + "_CDMatrix_1_2"), 

102 trueCdMatrix[0, 1]) 

103 self.assertAlmostEqual(record.get(self.pluginName + "_CDMatrix_2_2"), 

104 trueCdMatrix[1, 1]) 

105 self.assertAlmostEqual( 

106 exposure.getWcs().getPixelScale(record.getCentroid()).asRadians(), 

107 np.sqrt(np.fabs(record.get(self.pluginName + "_CDMatrix_1_1") 

108 * record.get(self.pluginName + "_CDMatrix_2_2") 

109 - record.get(self.pluginName + "_CDMatrix_2_1") 

110 * record.get(self.pluginName + "_CDMatrix_1_2")))) 

111 

112 def testWcsIsNone(self): 

113 with self.assertNoLogs(level=logging.WARNING) and self.assertLogs(level=logging.DEBUG): 

114 task = self.makeSingleFrameMeasurementTask(self.pluginName) 

115 exposure, catalog = self.dataset.realize(10.0, task.schema, randomSeed=0) 

116 exposure.setWcs(None) 

117 task.run(catalog, exposure) 

118 record = catalog[0] 

119 

120 self.assertTrue(np.isnan(record.get(self.pluginName + "_CDMatrix_1_1"))) 

121 self.assertTrue(np.isnan(record.get(self.pluginName + "_CDMatrix_2_1"))) 

122 self.assertTrue(np.isnan(record.get(self.pluginName + "_CDMatrix_1_2"))) 

123 self.assertTrue(np.isnan(record.get(self.pluginName + "_CDMatrix_2_2"))) 

124 self.assertTrue(record.get(self.pluginName + "_flag")) 

125 

126 

127class MemoryTester(lsst.utils.tests.MemoryTestCase): 

128 pass 

129 

130 

131def setup_module(module): 

132 lsst.utils.tests.init() 

133 

134 

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()