Coverage for tests/test_forcedPhot.py: 37%

52 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-11 09:14 +0000

1# This file is part of meas_base. 

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 

22"""Tests of the various forced photometry tasks. 

23 

24These tests primarily confirm that their respective Tasks can be configured and 

25run without errors, but do not check anything about their algorithmic quality. 

26""" 

27 

28import unittest 

29 

30import numpy as np 

31 

32import lsst.afw.image 

33from lsst.afw.math import ChebyshevBoundedField 

34from lsst.meas.base import ForcedPhotCcdTask, ForcedPhotCcdFromDataFrameTask 

35import lsst.meas.base.tests 

36import lsst.utils.tests 

37 

38skyCenter = lsst.geom.SpherePoint(245.0, -45.0, lsst.geom.degrees) 

39 

40 

41class ForcedPhotometryTests: 

42 """Base class for tests of forced photometry tasks. 

43 

44 Creates a simple test image and catalog to run forced photometry on. 

45 """ 

46 def setUp(self): 

47 bbox = lsst.geom.Box2I(lsst.geom.Point2I(0, 0), lsst.geom.Point2I(100, 100)) 

48 dataset = lsst.meas.base.tests.TestDataset(bbox, crval=skyCenter) 

49 dataset.addSource(instFlux=1000, centroid=lsst.geom.Point2D(30, 30)) 

50 dataset.addSource(instFlux=10000, centroid=lsst.geom.Point2D(60, 70)) 

51 

52 schema = dataset.makeMinimalSchema() 

53 self.exposure, self.refCat = dataset.realize(noise=10, schema=schema) 

54 lsst.afw.table.updateSourceCoords(self.exposure.wcs, self.refCat) 

55 # Simple aperture correction map in case the task needs it. 

56 apCorrMap = lsst.afw.image.ApCorrMap() 

57 apCorrMap["base_PsfFlux_instFlux"] = ChebyshevBoundedField(bbox, np.array([[2.0]])) 

58 apCorrMap["base_PsfFlux_instFluxErr"] = ChebyshevBoundedField(bbox, np.array([[3.0]])) 

59 self.exposure.info.setApCorrMap(apCorrMap) 

60 

61 # Offset WCS so that the forced coordinates don't match the truth. 

62 self.offsetWcs = dataset.makePerturbedWcs(self.exposure.wcs) 

63 

64 

65class ForcedPhotCcdTaskTestCase(ForcedPhotometryTests, lsst.utils.tests.TestCase): 

66 def testRun(self): 

67 config = ForcedPhotCcdTask.ConfigClass() 

68 task = ForcedPhotCcdTask(refSchema=self.refCat.schema, config=config) 

69 measCat = task.measurement.generateMeasCat(self.exposure, self.refCat, self.exposure.wcs) 

70 

71 task.run(measCat, self.exposure, self.refCat, self.offsetWcs) 

72 

73 # Check that something was measured. 

74 self.assertTrue(np.isfinite(measCat["base_TransformedCentroid_x"]).all()) 

75 self.assertTrue(np.isfinite(measCat["base_TransformedCentroid_y"]).all()) 

76 self.assertTrue(np.isfinite(measCat["base_PsfFlux_instFlux"]).all()) 

77 # We use an offset WCS, so the transformed centroids should not exactly 

78 # match the original positions. 

79 self.assertFloatsNotEqual(measCat["base_TransformedCentroid_x"], self.refCat['truth_x']) 

80 self.assertFloatsNotEqual(measCat["base_TransformedCentroid_y"], self.refCat['truth_y']) 

81 

82 

83class ForcedPhotCcdFromDataFrameTaskTestCase(ForcedPhotometryTests, lsst.utils.tests.TestCase): 

84 def testRun(self): 

85 """Testing run() for this task ignores the dataframe->SourceCatalog 

86 conversion that happens in runQuantum, but that should be tested 

87 separately. 

88 """ 

89 config = ForcedPhotCcdFromDataFrameTask.ConfigClass() 

90 task = ForcedPhotCcdFromDataFrameTask(refSchema=self.refCat.schema, config=config) 

91 measCat = task.measurement.generateMeasCat(self.exposure, self.refCat, self.exposure.wcs) 

92 

93 task.run(measCat, self.exposure, self.refCat, self.offsetWcs) 

94 

95 # Check that something was measured. 

96 self.assertTrue(np.isfinite(measCat["base_TransformedCentroidFromCoord_x"]).all()) 

97 self.assertTrue(np.isfinite(measCat["base_TransformedCentroidFromCoord_y"]).all()) 

98 self.assertTrue(np.isfinite(measCat["base_PsfFlux_instFlux"]).all()) 

99 # We use an offset WCS, so the transformed centroids should not exactly 

100 # match the original positions. 

101 self.assertFloatsNotEqual(measCat["base_TransformedCentroidFromCoord_x"], self.refCat['truth_x']) 

102 self.assertFloatsNotEqual(measCat["base_TransformedCentroidFromCoord_y"], self.refCat['truth_y']) 

103 

104 

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

106 pass 

107 

108 

109def setup_module(module): 

110 lsst.utils.tests.init() 

111 

112 

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

114 lsst.utils.tests.init() 

115 unittest.main()