Coverage for tests/test_InvalidPsfFlag.py: 47%
58 statements
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-16 03:37 -0700
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-16 03:37 -0700
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/>.
22import unittest
23import lsst.utils.tests
25from lsst.meas.base.sfm import SingleFramePluginConfig, SingleFramePlugin
26from lsst.afw.detection import InvalidPsfError
27from lsst.meas.base.tests import AlgorithmTestCase
28from lsst.meas.base.pluginRegistry import register
29from lsst.meas.base import FlagDefinitionList, FlagHandler
32class InvalidPsfPluginConfig(SingleFramePluginConfig):
33 pass
36@register("test_InvalidPsfPlugin")
37class InvalidPsfPlugin(SingleFramePlugin):
38 ConfigClass = InvalidPsfPluginConfig
40 def __init__(self, config, name, schema, metadata):
41 SingleFramePlugin.__init__(self, config, name, schema, metadata)
42 flagDefs = FlagDefinitionList()
43 self.FAILURE = flagDefs.addFailureFlag()
44 self.flagHandler = FlagHandler.addFields(schema, name, flagDefs)
46 @classmethod
47 def getExecutionOrder(cls):
48 return cls.FLUX_ORDER
50 def measure(self, measRecord, exposure):
51 raise InvalidPsfError("This record has an invalid PSF!")
53 def fail(self, measRecord, error=None):
54 self.flagHandler.handleFailure(measRecord)
57class InvalidPsfFlagTestCase(AlgorithmTestCase, lsst.utils.tests.TestCase):
58 def setUp(self):
59 self.algName = "test_InvalidPsfPlugin"
60 bbox = lsst.geom.Box2I(lsst.geom.Point2I(0, 0), lsst.geom.Point2I(100, 100))
61 self.dataset = lsst.meas.base.tests.TestDataset(bbox)
62 self.dataset.addSource(instFlux=1E5, centroid=lsst.geom.Point2D(25, 26))
63 config = lsst.meas.base.SingleFrameMeasurementConfig()
64 config.plugins = [self.algName]
65 config.slots.centroid = None
66 config.slots.apFlux = None
67 config.slots.calibFlux = None
68 config.slots.gaussianFlux = None
69 config.slots.modelFlux = None
70 config.slots.psfFlux = None
71 config.slots.shape = None
72 config.slots.psfShape = None
73 self.config = config
75 def tearDown(self):
76 del self.config
77 del self.dataset
79 def testInvalidPsfFlag(self):
80 schema = self.dataset.makeMinimalSchema()
81 task = lsst.meas.base.SingleFrameMeasurementTask(schema=schema, config=self.config)
82 exposure, cat = self.dataset.realize(noise=100.0, schema=schema, randomSeed=0)
83 task.run(cat, exposure)
85 # Check the plugin failure flag.
86 self.assertTrue(cat[0][f"{self.algName}_flag"])
87 # And the general invalid psf flag.
88 self.assertTrue(cat[0]["base_InvalidPsf_flag"])
91class TestMemory(lsst.utils.tests.MemoryTestCase):
92 pass
95def setup_module(module):
96 lsst.utils.tests.init()
99if __name__ == "__main__": 99 ↛ 100line 99 didn't jump to line 100, because the condition on line 99 was never true
100 lsst.utils.tests.init()
101 unittest.main()