Coverage for tests/test_associationUtils.py: 17%
60 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-06 02:11 -0800
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-06 02:11 -0800
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 + [' ', '\x00\x00\x00\x00\x00\x00\x00']
64 allowed_flags = [i for i in range(0, 256)]
65 allowed_ssObjectIDs = [0, 1 << 64 - 1] + [1 << n for n in range(64)]
66 for allowed_string in allowed_strings:
67 for allowed_flag in allowed_flags:
68 returned_string, returned_flag = ss_object_id_to_obj_id(
69 obj_id_to_ss_object_id(allowed_string, allowed_flag))
70 self.assertEqual((allowed_string, allowed_flag), (returned_string, returned_flag))
71 for allowed_ssObjectID in allowed_ssObjectIDs:
72 returned_ssObjectID = obj_id_to_ss_object_id(*ss_object_id_to_obj_id(allowed_ssObjectID))
73 self.assertEqual(allowed_ssObjectID, returned_ssObjectID)
75 def test_invalid_conversions_between_obj_id_and_ss_object_id(self):
76 """Convert between ssObjectIDs and MPC packed designations
77 """
78 allowed_strings = ['J95X00A', 'J95X01L', 'J95F13B', 'J98SA8Q', 'J98SC7V', 'J98SG2S'] \
79 + ['K99AJ3Z', 'K08Aa0A', 'K07Tf8A', 'PLS2040', 'T1S3138', 'T2S1010', 'T3S4101']
80 allowed_flags = [i for i in range(0, 256)]
81 disallowed_flags = [-999999999, -512, -256, -255, -1, 256, 512, 99999999]
82 disallowed_strings = [''] + [ch for ch in 'ABCDEFGHIJKMNOPQRSTUVWXYZ0123456789 -'] \
83 + ['A' * i for i in range(2, 7)] + ['Z' * i for i in range(2, 7)] \
84 + ['Ā', '🔭', 'A' * 8, ' ' * 8, 'A' * 128]
85 disallowed_ssObjectIDs = [-1, 1 << 64, 1 << 64 + 1, 2 << 65]
86 for allowed_string in allowed_strings:
87 for disallowed_flag in disallowed_flags:
88 with self.assertRaises(ValueError):
89 obj_id_to_ss_object_id(allowed_string, disallowed_flag)
90 for disallowed_string in disallowed_strings:
91 for allowed_flag in allowed_flags:
92 with self.assertRaises(ValueError):
93 obj_id_to_ss_object_id(disallowed_string, allowed_flag)
94 for disallowed_string in disallowed_strings:
95 for disallowed_flag in disallowed_flags:
96 with self.assertRaises(ValueError):
97 obj_id_to_ss_object_id(disallowed_string, disallowed_flag)
98 for disallowed_ssObjectID in disallowed_ssObjectIDs:
99 with self.assertRaises(ValueError):
100 ss_object_id_to_obj_id(disallowed_ssObjectID)
103class MemoryTestCase(lsst.utils.tests.MemoryTestCase):
104 pass
107def setup_module(module):
108 lsst.utils.tests.init()
111if __name__ == "__main__": 111 ↛ 112line 111 didn't jump to line 112 because the condition on line 111 was never true
112 lsst.utils.tests.init()
113 unittest.main()