Coverage for tests / test_associationUtils.py: 28%

42 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-01-09 01:51 -0800

1# This file is part of pipe_tasks. 

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/>. 

21 

22import hpgeom as hpg 

23import numpy as np 

24import unittest 

25 

26from lsst.pipe.tasks.associationUtils import query_disc, obj_id_to_ss_object_id, ss_object_id_to_obj_id 

27import lsst.utils.tests 

28 

29 

30class TestAssociationUtils(lsst.utils.tests.TestCase): 

31 

32 def test_queryDisc(self): 

33 """Test that doing a circle query of hpgeom using our wrapper works as 

34 expected. 

35 

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) 

57 

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', 'AAAAAAAA'] 

64 for allowed_string in allowed_strings: 

65 returned_string = ss_object_id_to_obj_id(obj_id_to_ss_object_id(allowed_string)) 

66 self.assertEqual(allowed_string, returned_string) 

67 

68 def test_invalid_conversions_between_obj_id_and_ss_object_id(self): 

69 """Convert between ssObjectIDs and MPC packed designations 

70 """ 

71 disallowed_strings = [''] + [ch for ch in 'ABCDEFGHIJKMNOPQRSTUVWXYZ0123456789 -'] \ 

72 + ['A' * i for i in range(2, 7)] + ['Z' * i for i in range(2, 7)] \ 

73 + ['Ā', '🔭', 'A' * 9, ' ' * 9, 'A' * 128] 

74 disallowed_ssObjectIDs = [-1, 1 << 64, 1 << 64 + 1, 2 << 65] 

75 for disallowed_ssObjectID in disallowed_ssObjectIDs: 

76 with self.assertRaises(ValueError): 

77 ss_object_id_to_obj_id(disallowed_ssObjectID) 

78 for disallowed_string in disallowed_strings: 

79 with self.assertRaises(ValueError): 

80 obj_id_to_ss_object_id(disallowed_string) 

81 

82 

83class MemoryTestCase(lsst.utils.tests.MemoryTestCase): 

84 pass 

85 

86 

87def setup_module(module): 

88 lsst.utils.tests.init() 

89 

90 

91if __name__ == "__main__": 91 ↛ 92line 91 didn't jump to line 92 because the condition on line 91 was never true

92 lsst.utils.tests.init() 

93 unittest.main()