Coverage for tests/test_ssoAssociationTask.py: 28%
42 statements
« prev ^ index » next coverage.py v7.2.1, created at 2023-03-12 10:45 +0000
« prev ^ index » next coverage.py v7.2.1, created at 2023-03-12 10:45 +0000
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 numpy as np
23import unittest
25from lsst.ap.association.ssoAssociation import SolarSystemAssociationTask
26import lsst.geom as geom
27import lsst.meas.base.tests as measTests
28import lsst.utils.tests
31class TestSolarSystemAssociation(unittest.TestCase):
33 def setUp(self):
34 # Make fake sources
35 self.nSources = 10
36 self.bbox = geom.Box2I(geom.Point2I(0, 0),
37 geom.Extent2I(1024, 1153))
38 self.xyLoc = 100
39 dataset = measTests.TestDataset(self.bbox)
40 for srcIdx in range(self.nSources):
41 dataset.addSource(100000.0,
42 geom.Point2D(srcIdx*self.xyLoc,
43 srcIdx*self.xyLoc))
44 schema = dataset.makeMinimalSchema()
45 schema.addField("base_PixelFlags_flag", type="Flag")
46 schema.addField("base_PixelFlags_flag_offimage", type="Flag")
47 exposure, catalog = dataset.realize(
48 10.0, schema, randomSeed=1234)
49 for src in catalog:
50 src.setCoord(exposure.getWcs().pixelToSky(src.getCentroid()))
52 # Convert to task required format
53 self.testDiaSources = catalog.asAstropy().to_pandas()
54 self.testDiaSources.rename(columns={"coord_ra": "ra",
55 "coord_dec": "decl"},
56 inplace=True,)
57 self.testDiaSources.loc[:, "ra"] = np.rad2deg(self.testDiaSources["ra"])
58 self.testDiaSources.loc[:, "decl"] = np.rad2deg(self.testDiaSources["decl"])
59 self.testDiaSources["ssObjectId"] = 0
61 # Grab a subset to treat as solar system objects
62 self.testSsObjects = self.testDiaSources[2:8].reset_index()
63 # Assign them ids starting from 1.
64 self.testSsObjects.loc[:, "ssObjectId"] = np.arange(
65 1, len(self.testSsObjects) + 1, dtype=int,)
67 def test_run(self):
68 """Test that association and id assignment work as expected.
69 """
70 ssAssocTask = SolarSystemAssociationTask()
71 results = ssAssocTask.run(self.testDiaSources, self.testSsObjects)
72 self.assertEqual(self.nSources,
73 len(results.ssoAssocDiaSources)
74 + len(results.unAssocDiaSources))
75 self.assertEqual(len(self.testSsObjects),
76 len(results.ssoAssocDiaSources))
77 self.assertEqual(self.nSources - len(self.testSsObjects),
78 len(results.unAssocDiaSources))
79 for idx, ssObject in self.testSsObjects.iterrows():
80 self.assertEqual(
81 ssObject["ssObjectId"],
82 results.ssoAssocDiaSources.iloc[idx]["ssObjectId"])
85class MemoryTester(lsst.utils.tests.MemoryTestCase):
86 pass
89def setup_module(module):
90 lsst.utils.tests.init()
93if __name__ == "__main__": 93 ↛ 94line 93 didn't jump to line 94, because the condition on line 93 was never true
94 lsst.utils.tests.init()
95 unittest.main()