Coverage for tests/test_associationUtils.py: 47%

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

28 statements  

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 healpy as hp 

23import numpy as np 

24import unittest 

25 

26from lsst.pipe.tasks.associationUtils import query_disc 

27import lsst.utils.tests 

28 

29 

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

31 

32 def test_queryDisc(self): 

33 """Test that doing a disc query of healpy 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 = hp.ang2pix(nside, testRa, testDec, lonlat=True) 

43 ra, dec = hp.pix2ang(nside, centerPixNumber, lonlat=True) 

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 

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

60 pass 

61 

62 

63def setup_module(module): 

64 lsst.utils.tests.init() 

65 

66 

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

68 lsst.utils.tests.init() 

69 unittest.main()