Coverage for tests/test_filterDiaSourceCatalog.py: 29%
45 statements
« prev ^ index » next coverage.py v7.5.0, created at 2024-05-02 04:31 -0700
« prev ^ index » next coverage.py v7.5.0, created at 2024-05-02 04:31 -0700
1# This file is part of ap_association.
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
24from lsst.ap.association.filterDiaSourceCatalog import (FilterDiaSourceCatalogConfig,
25 FilterDiaSourceCatalogTask)
26import lsst.geom as geom
27import lsst.meas.base.tests as measTests
28import lsst.utils.tests
31class TestFilterDiaSourceCatalogTask(unittest.TestCase):
33 def setUp(self):
34 self.nSources = 10
35 self.nSkySources = 5
36 self.yLoc = 100
37 self.expId = 4321
38 self.bbox = geom.Box2I(geom.Point2I(0, 0),
39 geom.Extent2I(1024, 1153))
40 dataset = measTests.TestDataset(self.bbox)
41 for srcIdx in range(self.nSources):
42 dataset.addSource(10000.0, geom.Point2D(srcIdx, self.yLoc))
43 schema = dataset.makeMinimalSchema()
44 schema.addField("sky_source", type="Flag", doc="Sky objects.")
45 _, self.diaSourceCat = dataset.realize(10.0, schema, randomSeed=1234)
46 self.diaSourceCat[0:self.nSkySources]["sky_source"] = True
47 self.config = FilterDiaSourceCatalogConfig()
49 def test_run_without_filter(self):
50 self.config.doRemoveSkySources = False
51 self.config.doWriteRejectedSources = True
52 filterDiaSourceCatalogTask = FilterDiaSourceCatalogTask(config=self.config)
53 result = filterDiaSourceCatalogTask.run(self.diaSourceCat)
54 self.assertEqual(len(result.filteredDiaSourceCat), len(self.diaSourceCat))
55 self.assertEqual(len(result.rejectedDiaSources), 0)
56 self.assertEqual(len(self.diaSourceCat), self.nSources)
58 def test_run_with_filter(self):
59 self.config.doRemoveSkySources = True
60 self.config.doWriteRejectedSources = True
61 filterDiaSourceCatalogTask = FilterDiaSourceCatalogTask(config=self.config)
62 result = filterDiaSourceCatalogTask.run(self.diaSourceCat)
63 nExpectedFilteredSources = self.nSources - self.nSkySources
64 self.assertEqual(len(result.filteredDiaSourceCat),
65 len(self.diaSourceCat[~self.diaSourceCat['sky_source']]))
66 self.assertEqual(len(result.filteredDiaSourceCat), nExpectedFilteredSources)
67 self.assertEqual(len(result.rejectedDiaSources), self.nSkySources)
68 self.assertEqual(len(self.diaSourceCat), self.nSources)
71class MemoryTester(lsst.utils.tests.MemoryTestCase):
72 pass
75def setup_module(module):
76 lsst.utils.tests.init()
79if __name__ == "__main__": 79 ↛ 80line 79 didn't jump to line 80, because the condition on line 79 was never true
80 lsst.utils.tests.init()
81 unittest.main()