Coverage for tests/testHealUtils.py : 26%

Hot-keys 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
1import numpy as np
2import unittest
3import healpy as hp
4import lsst.sims.utils as utils
5import lsst.utils.tests
8def setup_module(module):
9 lsst.utils.tests.init()
12class TestHealUtils(unittest.TestCase):
14 def testRaDecsRad(self):
15 """
16 Test that the Ra Dec conversions round-trip
17 """
19 nside = 64
20 hpids = np.arange(hp.nside2npix(nside))
21 ra, dec = utils._hpid2RaDec(nside, hpids)
23 hpids_return = utils._raDec2Hpid(nside, ra, dec)
25 np.testing.assert_array_equal(hpids, hpids_return)
27 def testRaDecsDeg(self):
28 """
29 Test that the Ra Dec conversions round-trip
30 """
32 nside = 64
33 hpids = np.arange(hp.nside2npix(nside))
34 ra, dec = utils.hpid2RaDec(nside, hpids)
36 hpids_return = utils.raDec2Hpid(nside, ra, dec)
38 np.testing.assert_array_equal(hpids, hpids_return)
40 def testBinRad(self):
41 """
42 Test that healbin returns correct values and valid healpy maps.
43 """
45 ra = np.zeros(3)
46 dec = np.zeros(3)
47 values = ra * 0. + 1.
49 nside = 128
50 hpid = utils._raDec2Hpid(nside, ra[0], dec[0])
52 map1 = utils._healbin(ra, dec, values, nside=nside)
53 self.assertEqual(map1[hpid], 1.)
54 self.assertEqual(hp.maptype(map1), 0)
55 map2 = utils._healbin(ra, dec, values, nside=nside, reduceFunc=np.sum)
56 self.assertEqual(map2[hpid], 3.)
57 self.assertEqual(hp.maptype(map2), 0)
58 map3 = utils._healbin(ra, dec, values, nside=nside, reduceFunc=np.std)
59 self.assertEqual(map3[hpid], 0.)
60 self.assertEqual(hp.maptype(map3), 0)
62 def testBinDeg(self):
63 """
64 Test that healbin returns correct values and valid healpy maps.
65 """
67 ra = np.zeros(3)
68 dec = np.zeros(3)
69 values = ra * 0. + 1.
71 nside = 128
72 hpid = utils.raDec2Hpid(nside, ra[0], dec[0])
74 map1 = utils.healbin(ra, dec, values, nside=nside)
75 self.assertEqual(map1[hpid], 1.)
76 self.assertEqual(hp.maptype(map1), 0)
77 map2 = utils.healbin(ra, dec, values, nside=nside, reduceFunc=np.sum)
78 self.assertEqual(map2[hpid], 3.)
79 self.assertEqual(hp.maptype(map2), 0)
80 map3 = utils.healbin(ra, dec, values, nside=nside, reduceFunc=np.std)
81 self.assertEqual(map3[hpid], 0.)
82 self.assertEqual(hp.maptype(map3), 0)
85class MemoryTestClass(lsst.utils.tests.MemoryTestCase):
86 pass
88if __name__ == "__main__": 88 ↛ 89line 88 didn't jump to line 89, because the condition on line 88 was never true
89 lsst.utils.tests.init()
90 unittest.main()