Coverage for tests/test_forcedPhot.py: 37%
55 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-11-01 10:01 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-11-01 10:01 +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/>.
22"""Tests of the various forced photometry tasks.
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"""
28import unittest
30import numpy as np
32import lsst.afw.image
33from lsst.afw.math import ChebyshevBoundedField
34from lsst.afw.table import CoordKey
35from lsst.meas.base import ForcedPhotCcdTask, ForcedPhotCcdFromDataFrameTask
36import lsst.meas.base.tests
37import lsst.utils.tests
39skyCenter = lsst.geom.SpherePoint(245.0, -45.0, lsst.geom.degrees)
42class ForcedPhotometryTests:
43 """Base class for tests of forced photometry tasks.
45 Creates a simple test image and catalog to run forced photometry on.
46 """
47 def setUp(self):
48 bbox = lsst.geom.Box2I(lsst.geom.Point2I(0, 0), lsst.geom.Point2I(100, 100))
49 dataset = lsst.meas.base.tests.TestDataset(bbox, crval=skyCenter)
50 dataset.addSource(instFlux=1000, centroid=lsst.geom.Point2D(30, 30))
51 dataset.addSource(instFlux=10000, centroid=lsst.geom.Point2D(60, 70))
53 schema = dataset.makeMinimalSchema()
54 # Add coordinate error fields needed by updateSourceCoords below:
55 CoordKey.addErrorFields(schema)
56 self.exposure, self.refCat = dataset.realize(noise=10, schema=schema)
57 lsst.afw.table.updateSourceCoords(self.exposure.wcs, self.refCat)
58 # Simple aperture correction map in case the task needs it.
59 apCorrMap = lsst.afw.image.ApCorrMap()
60 apCorrMap["base_PsfFlux_instFlux"] = ChebyshevBoundedField(bbox, np.array([[2.0]]))
61 apCorrMap["base_PsfFlux_instFluxErr"] = ChebyshevBoundedField(bbox, np.array([[3.0]]))
62 self.exposure.info.setApCorrMap(apCorrMap)
63 self.exposure.mask.addMaskPlane("STREAK") # add empty streak mask plane in lieu of maskStreaksTask
65 # Offset WCS so that the forced coordinates don't match the truth.
66 self.offsetWcs = dataset.makePerturbedWcs(self.exposure.wcs)
69class ForcedPhotCcdTaskTestCase(ForcedPhotometryTests, lsst.utils.tests.TestCase):
70 def testRun(self):
71 config = ForcedPhotCcdTask.ConfigClass()
72 task = ForcedPhotCcdTask(refSchema=self.refCat.schema, config=config)
73 measCat = task.measurement.generateMeasCat(self.exposure, self.refCat, self.exposure.wcs)
75 task.run(measCat, self.exposure, self.refCat, self.offsetWcs)
77 # Check that something was measured.
78 self.assertTrue(np.isfinite(measCat["base_TransformedCentroid_x"]).all())
79 self.assertTrue(np.isfinite(measCat["base_TransformedCentroid_y"]).all())
80 self.assertTrue(np.isfinite(measCat["base_PsfFlux_instFlux"]).all())
81 # We use an offset WCS, so the transformed centroids should not exactly
82 # match the original positions.
83 self.assertFloatsNotEqual(measCat["base_TransformedCentroid_x"], self.refCat['truth_x'])
84 self.assertFloatsNotEqual(measCat["base_TransformedCentroid_y"], self.refCat['truth_y'])
87class ForcedPhotCcdFromDataFrameTaskTestCase(ForcedPhotometryTests, lsst.utils.tests.TestCase):
88 def testRun(self):
89 """Testing run() for this task ignores the dataframe->SourceCatalog
90 conversion that happens in runQuantum, but that should be tested
91 separately.
92 """
93 config = ForcedPhotCcdFromDataFrameTask.ConfigClass()
94 task = ForcedPhotCcdFromDataFrameTask(refSchema=self.refCat.schema, config=config)
95 measCat = task.measurement.generateMeasCat(self.exposure, self.refCat, self.exposure.wcs)
97 task.run(measCat, self.exposure, self.refCat, self.offsetWcs)
99 # Check that something was measured.
100 self.assertTrue(np.isfinite(measCat["base_TransformedCentroidFromCoord_x"]).all())
101 self.assertTrue(np.isfinite(measCat["base_TransformedCentroidFromCoord_y"]).all())
102 self.assertTrue(np.isfinite(measCat["base_PsfFlux_instFlux"]).all())
103 # We use an offset WCS, so the transformed centroids should not exactly
104 # match the original positions.
105 self.assertFloatsNotEqual(measCat["base_TransformedCentroidFromCoord_x"], self.refCat['truth_x'])
106 self.assertFloatsNotEqual(measCat["base_TransformedCentroidFromCoord_y"], self.refCat['truth_y'])
109class MemoryTester(lsst.utils.tests.MemoryTestCase):
110 pass
113def setup_module(module):
114 lsst.utils.tests.init()
117if __name__ == "__main__": 117 ↛ 118line 117 didn't jump to line 118, because the condition on line 117 was never true
118 lsst.utils.tests.init()
119 unittest.main()