Coverage for tests/test_ssoAssociationTask.py: 24%
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
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 self.exposure, catalog = dataset.realize(
48 10.0, schema, randomSeed=1234)
49 for src in catalog:
50 src.setCoord(self.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,)
66 self.testSsObjects["Err(arcsec)"] = np.ones(len(self.testSsObjects))
68 def test_run(self):
69 """Test that association and id assignment work as expected.
70 """
71 ssAssocTask = SolarSystemAssociationTask()
72 results = ssAssocTask.run(self.testDiaSources,
73 self.testSsObjects,
74 self.exposure)
75 self.assertEqual(self.nSources,
76 len(results.ssoAssocDiaSources)
77 + len(results.unAssocDiaSources))
78 self.assertEqual(len(self.testSsObjects),
79 len(results.ssoAssocDiaSources))
80 self.assertEqual(self.nSources - len(self.testSsObjects),
81 len(results.unAssocDiaSources))
82 for idx, ssObject in self.testSsObjects.iterrows():
83 self.assertEqual(
84 ssObject["ssObjectId"],
85 results.ssoAssocDiaSources.iloc[idx]["ssObjectId"])
87 def test_mask(self):
88 """Test that masking against the CCD bounding box works as expected.
89 """
90 ssAssocTask = SolarSystemAssociationTask()
91 # Test will all inside ccd
92 maskedObjects = ssAssocTask._maskToCcdRegion(self.testSsObjects,
93 self.exposure,
94 1.0)
95 self.assertEqual(len(maskedObjects), len(self.testSsObjects))
97 # Add a new SolarSystemObjects outside of the bbox and test that it
98 # is excluded.
99 testObjects = self.testSsObjects.loc[:1].reset_index(drop=True)
100 testObjects.loc[0, "ra"] = 150
101 testObjects.loc[0, "decl"] = 80
102 testObjects.loc[1, "ra"] = 150
103 testObjects.loc[1, "decl"] = -80
104 maskedObjects = ssAssocTask._maskToCcdRegion(
105 self.testSsObjects.append(testObjects),
106 self.exposure,
107 1.0)
108 self.assertEqual(len(maskedObjects), len(self.testSsObjects))
111class MemoryTester(lsst.utils.tests.MemoryTestCase):
112 pass
115def setup_module(module):
116 lsst.utils.tests.init()
119if __name__ == "__main__": 119 ↛ 120line 119 didn't jump to line 120, because the condition on line 119 was never true
120 lsst.utils.tests.init()
121 unittest.main()