Coverage for tests/test_flaggedSourceSelector.py: 34%
44 statements
« prev ^ index » next coverage.py v7.2.3, created at 2023-04-27 03:07 -0700
« prev ^ index » next coverage.py v7.2.3, created at 2023-04-27 03:07 -0700
1#!/usr/bin/env python
2#
3# LSST Data Management System
4#
5# Copyright 2008-2016 AURA/LSST.
6#
7# This product includes software developed by the
8# LSST Project (http://www.lsst.org/).
9#
10# This program is free software: you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation, either version 3 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the LSST License Statement and
21# the GNU General Public License along with this program. If not,
22# see <https://www.lsstcorp.org/LegalNotices/>.
23#
24import unittest
26import lsst.geom
27import lsst.afw.table as afwTable
28from lsst.meas.algorithms import sourceSelector
29import lsst.meas.base.tests
30import lsst.utils.tests
33def addGoodSource(src, num=0):
34 """Insert a likely-good source into the catalog. Num is added to various
35 values to distinguish them in catalogs with multiple objects.
36 """
37 record = src.addNew()
38 record['coord_ra'] = (1. + num) * lsst.geom.degrees
39 record['coord_dec'] = (2. + num) * lsst.geom.degrees
40 record['slot_Centroid_x'] = 10. + num
41 record['slot_Centroid_y'] = 20. + num
42 record['slot_ApFlux_instFlux'] = 100. + num
43 record['slot_ApFlux_instFluxErr'] = 1.
44 record.set("calib_psf_used", True)
47class TestFlaggedSourceSelector(lsst.utils.tests.TestCase):
49 def setUp(self):
50 schema = lsst.meas.base.tests.TestDataset.makeMinimalSchema()
51 schema.addField("slot_ApFlux_instFlux", type=float)
52 schema.addField("slot_ApFlux_instFluxErr", type=float)
53 schema.addField("calib_psf_used", type="Flag")
55 self.src = afwTable.SourceCatalog(schema)
56 self.sourceSelector = sourceSelector.sourceSelectorRegistry['flagged']()
58 def tearDown(self):
59 del self.src
60 del self.sourceSelector
62 def testSelectSourcesGood(self):
63 """Insert good sources and check that they were selected."""
64 for i in range(5):
65 addGoodSource(self.src, i)
66 result = self.sourceSelector.run(self.src)
67 for x in self.src['id']:
68 self.assertIn(x, result.sourceCat['id'])
70 def testSelectSourcesBad(self):
71 """Add a source that fails the source selector test and check
72 that our output array is indeed empty.
73 """
74 addGoodSource(self.src, 1)
75 self.src[0].set('calib_psf_used', False)
76 result = self.sourceSelector.run(self.src)
77 self.assertNotIn(self.src['id'][0], result.sourceCat['id'])
80class TestMemory(lsst.utils.tests.MemoryTestCase):
81 pass
84def setup_module(module):
85 lsst.utils.tests.init()
88if __name__ == "__main__": 88 ↛ 89line 88 didn't jump to line 89, because the condition on line 88 was never true
89 lsst.utils.tests.init()
90 unittest.main()