Coverage for tests / test_associationUtils.py: 27%
43 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-07 08:39 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-05-07 08:39 +0000
1# This file is part of pipe_tasks.
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.
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.
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.
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 hpgeom as hpg
23import numpy as np
24import unittest
26from lsst.pipe.tasks.associationUtils import query_disc, obj_id_to_ss_object_id, ss_object_id_to_obj_id
27import lsst.utils.tests
30class TestAssociationUtils(lsst.utils.tests.TestCase):
32 def test_queryDisc(self):
33 """Test that doing a circle query of hpgeom using our wrapper works as
34 expected.
36 Most other calculations are very simple and not worth testing.
37 """
38 # Find nearest pixel to r=45, dec=45.
39 nside = 128
40 testRa = 225
41 testDec = 45
42 centerPixNumber = hpg.angle_to_pixel(nside, testRa, testDec, nest=False)
43 ra, dec = hpg.pixel_to_angle(nside, centerPixNumber, nest=False)
44 # Test that only one pixel is found.
45 pixelReturn = query_disc(nside, ra, dec, np.radians(0.1))
46 self.assertEqual(len(pixelReturn), 1)
47 self.assertTrue(centerPixNumber in pixelReturn)
48 # Test that nearby pixels are returned.
49 pixelReturn = query_disc(nside, ra, dec, np.radians(1))
50 self.assertEqual(len(pixelReturn), 17)
51 self.assertTrue(centerPixNumber in pixelReturn)
52 # Test excluding the central pixel
53 pixelReturn = query_disc(
54 nside, ra, dec, np.radians(1), np.radians(0.01))
55 self.assertEqual(len(pixelReturn), 16)
56 self.assertFalse(centerPixNumber in pixelReturn)
58 def test_conversions_between_obj_id_and_ss_object_id(self):
59 """Convert between ssObjectIDs and MPC packed designations
60 """
61 allowed_strings = ['J95X00A', 'J95X01L', 'J95F13B', 'J98SA8Q', 'J98SC7V', 'J98SG2S'] \
62 + ['K99AJ3Z', 'K08Aa0A', 'K07Tf8A', 'PLS2040', 'T1S3138', 'T2S1010', 'T3S4101'] \
63 + ['PJ48Q010']
64 for allowed_string in allowed_strings:
65 returned_string = ss_object_id_to_obj_id(obj_id_to_ss_object_id(allowed_string), packed=True)
66 print(allowed_string, returned_string)
67 self.assertEqual(allowed_string, returned_string)
69 def test_invalid_conversions_between_obj_id_and_ss_object_id(self):
70 """Convert between ssObjectIDs and MPC packed designations
71 """
72 disallowed_strings = [''] + [ch for ch in 'ABCDEFGHIJKMNOPQRSTUVWXYZ0123456789 -'] \
73 + ['A' * i for i in range(2, 7)] + ['Z' * i for i in range(2, 7)] \
74 + ['Ā', '🔭', 'A' * 9, ' ' * 9, 'A' * 128]
75 disallowed_ssObjectIDs = [-1, 1 << 64, 1 << 64 + 1, 2 << 65]
76 for disallowed_ssObjectID in disallowed_ssObjectIDs:
77 with self.assertRaises(ValueError):
78 ss_object_id_to_obj_id(disallowed_ssObjectID)
79 for disallowed_string in disallowed_strings:
80 with self.assertRaises(ValueError):
81 obj_id_to_ss_object_id(disallowed_string)
84class MemoryTestCase(lsst.utils.tests.MemoryTestCase):
85 pass
88def setup_module(module):
89 lsst.utils.tests.init()
92if __name__ == "__main__": 92 ↛ 93line 92 didn't jump to line 93 because the condition on line 92 was never true
93 lsst.utils.tests.init()
94 unittest.main()