Coverage for tests/test_EvaluateLocalCalibration.py: 33%

52 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-01-26 10:19 +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 numpy as np 

23import unittest 

24 

25import lsst.geom 

26import lsst.utils.tests 

27import lsst.meas.base.tests 

28 

29 

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

31 lsst.utils.tests.TestCase): 

32 

33 def setUp(self): 

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

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

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

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

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

39 

40 def tearDown(self): 

41 del self.center 

42 del self.bbox 

43 del self.dataset 

44 

45 def testPhotoCalib(self): 

46 task = self.makeSingleFrameMeasurementTask("base_LocalPhotoCalib") 

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

48 task.run(catalog, exposure) 

49 record = catalog[0] 

50 

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

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

53 self.assertEqual(record.get("base_LocalPhotoCalib"), calib) 

54 self.assertEqual(record.get("base_LocalPhotoCalibErr"), calibErr) 

55 

56 

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

58 lsst.utils.tests.TestCase): 

59 

60 def setUp(self): 

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

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

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

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

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

66 

67 def tearDown(self): 

68 del self.center 

69 del self.bbox 

70 del self.dataset 

71 

72 def testMatrix(self): 

73 task = self.makeSingleFrameMeasurementTask("base_LocalWcs") 

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

75 task.schema, 

76 randomSeed=0) 

77 task.run(catalog, exposure) 

78 record = catalog[0] 

79 

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

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

82 self.assertAlmostEqual(record.get("base_LocalWcs_CDMatrix_1_1"), 

83 trueCdMatrix[0, 0]) 

84 self.assertAlmostEqual(record.get("base_LocalWcs_CDMatrix_2_1"), 

85 trueCdMatrix[1, 0]) 

86 self.assertAlmostEqual(record.get("base_LocalWcs_CDMatrix_1_2"), 

87 trueCdMatrix[0, 1]) 

88 self.assertAlmostEqual(record.get("base_LocalWcs_CDMatrix_2_2"), 

89 trueCdMatrix[1, 1]) 

90 self.assertAlmostEqual( 

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

92 np.sqrt(np.fabs(record.get("base_LocalWcs_CDMatrix_1_1") 

93 * record.get("base_LocalWcs_CDMatrix_2_2") 

94 - record.get("base_LocalWcs_CDMatrix_2_1") 

95 * record.get("base_LocalWcs_CDMatrix_1_2")))) 

96 

97 

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

99 pass 

100 

101 

102def setup_module(module): 

103 lsst.utils.tests.init() 

104 

105 

106if __name__ == "__main__": 106 ↛ 107line 106 didn't jump to line 107, because the condition on line 106 was never true

107 lsst.utils.tests.init() 

108 unittest.main()