Coverage for tests/test_matcherSourceSelector.py: 27%
81 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-02-22 03:43 -0800
« prev ^ index » next coverage.py v6.5.0, created at 2023-02-22 03:43 -0800
1#
2# LSST Data Management System
3#
4# Copyright 2008-2016 AURA/LSST.
5#
6# This product includes software developed by the
7# LSST Project (http://www.lsst.org/).
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 LSST License Statement and
20# the GNU General Public License along with this program. If not,
21# see <https://www.lsstcorp.org/LegalNotices/>.
22#
24import unittest
25import numpy as np
27import lsst.afw.table as afwTable
28from lsst.meas.algorithms import sourceSelector
29import lsst.meas.base.tests
30import lsst.utils.tests
32badFlags = [
33 "slot_Centroid_flag",
34 "slot_ApFlux_flag",
35 "base_PixelFlags_flag_edge",
36 "base_PixelFlags_flag_interpolatedCenter",
37 "base_PixelFlags_flag_saturated",
38]
41def add_good_source(src, num=0):
42 """Insert a likely-good source into the catalog."""
43 """
44 num is added to various values to distinguish them in catalogs with multiple objects.
45 """
46 src.addNew()
47 src['coord_ra'][-1] = 1. + num
48 src['coord_dec'][-1] = 2. + num
49 src['slot_Centroid_x'][-1] = 10. + num
50 src['slot_Centroid_y'][-1] = 20. + num
51 src['slot_ApFlux_instFlux'][-1] = 100. + num
52 src['slot_ApFlux_instFluxErr'][-1] = 1.
55class TestMatcherSourceSelector(lsst.utils.tests.TestCase):
57 def setUp(self):
58 schema = lsst.meas.base.tests.TestDataset.makeMinimalSchema()
59 schema.addField("slot_ApFlux_instFlux", type=float)
60 schema.addField("slot_ApFlux_instFluxErr", type=float)
61 for flag in badFlags:
62 schema.addField(flag, type="Flag")
64 self.src = afwTable.SourceCatalog(schema)
65 self.sourceSelector = sourceSelector.sourceSelectorRegistry['matcher']()
67 def tearDown(self):
68 del self.src
69 del self.sourceSelector
71 def testSelectSources_good(self):
72 for i in range(5):
73 add_good_source(self.src, i)
74 result = self.sourceSelector.run(self.src)
75 # TODO: assertEqual doesn't work correctly on source catalogs.
76 # self.assertEqual(result.sourceCat, self.src)
77 for x in self.src['id']:
78 self.assertIn(x, result.sourceCat['id'])
80 def testSelectSources_bad_centroid(self):
81 add_good_source(self.src, 1)
82 self.src[0].set('slot_Centroid_x', np.nan)
83 result = self.sourceSelector.run(self.src)
84 self.assertNotIn(self.src['id'][0], result.sourceCat['id'])
86 def testSelectSources_is_parent(self):
87 add_good_source(self.src, 1)
88 self.src[0].set('parent', 1)
89 result = self.sourceSelector.run(self.src)
90 self.assertNotIn(self.src['id'][0], result.sourceCat['id'])
92 def testSelectSources_highSN_cut(self):
93 add_good_source(self.src, 1)
94 add_good_source(self.src, 2)
95 self.src['slot_ApFlux_instFlux'][0] = 20.
96 self.src['slot_ApFlux_instFlux'][1] = 1000.
98 self.sourceSelector.config.minSnr = 100
99 result = self.sourceSelector.run(self.src)
100 self.assertNotIn(self.src[0]['id'], result.sourceCat['id'])
101 self.assertIn(self.src[1]['id'], result.sourceCat['id'])
103 def testSelectSources_no_SN_cut(self):
104 self.sourceSelector.config.minSnr = 0
105 add_good_source(self.src, 1)
106 self.src['slot_ApFlux_instFlux'][0] = 0
107 result = self.sourceSelector.run(self.src)
108 self.assertIn(self.src[0]['id'], result.sourceCat['id'])
110 def testSelectSources_is_edge(self):
111 add_good_source(self.src, 1)
112 self.src[0].set('base_PixelFlags_flag_edge', 1)
113 result = self.sourceSelector.run(self.src)
114 self.assertNotIn(self.src['id'][0], result.sourceCat['id'])
116 def testSelectSources_is_interpolated(self):
117 add_good_source(self.src, 1)
118 self.src[0].set('base_PixelFlags_flag_interpolatedCenter', 1)
119 result = self.sourceSelector.run(self.src)
120 self.assertNotIn(self.src['id'][0], result.sourceCat['id'])
122 def testSelectSources_is_saturated(self):
123 add_good_source(self.src, 1)
124 self.src[0].set('base_PixelFlags_flag_saturated', 1)
125 result = self.sourceSelector.run(self.src)
126 self.assertNotIn(self.src['id'][0], result.sourceCat['id'])
129class TestMemory(lsst.utils.tests.MemoryTestCase):
130 pass
133def setup_module(module):
134 lsst.utils.tests.init()
137if __name__ == "__main__": 137 ↛ 138line 137 didn't jump to line 138, because the condition on line 137 was never true
138 lsst.utils.tests.init()
139 unittest.main()