Coverage for tests/testEBV.py : 27%

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 unittest
2import numpy as np
4import lsst.utils.tests
5from lsst.utils import getPackageDir
6from lsst.sims.utils.CodeUtilities import sims_clean_up
7from lsst.sims.catUtils.dust import EBVbase
10def setup_module(module):
11 lsst.utils.tests.init()
14class EbvTestCase(unittest.TestCase):
16 @classmethod
17 def tearDownClass(cls):
18 sims_clean_up()
20 def test_cache(self):
21 """
22 Test that EBVbase() only loads each dust map once
23 """
24 sims_clean_up()
25 self.assertEqual(len(EBVbase._ebv_map_cache), 0)
27 ebv1 = EBVbase()
28 ebv1.load_ebvMapNorth()
29 ebv1.load_ebvMapSouth()
30 self.assertEqual(len(EBVbase._ebv_map_cache), 2)
32 ebv2 = EBVbase()
33 ebv2.load_ebvMapNorth()
34 ebv2.load_ebvMapSouth()
35 self.assertEqual(len(EBVbase._ebv_map_cache), 2)
37 rng = np.random.RandomState(881)
38 ra_list = rng.random_sample(10)*2.0*np.pi
39 dec_list = rng.random_sample(10)*np.pi - 0.5*np.pi
41 ebv1_vals = ebv1.calculateEbv(equatorialCoordinates=np.array([ra_list, dec_list]))
42 ebv2_vals = ebv2.calculateEbv(equatorialCoordinates=np.array([ra_list, dec_list]))
44 self.assertEqual(len(EBVbase._ebv_map_cache), 2)
46 np.testing.assert_array_equal(ebv1_vals, ebv2_vals)
48 def testEBV(self):
50 ebvObject = EBVbase()
51 ra = []
52 dec = []
53 gLat = []
54 gLon = []
55 for i in range(10):
56 ra.append(i*2.0*np.pi/10.0)
57 dec.append(i*np.pi/10.0)
59 gLat.append(-0.5*np.pi+i*np.pi/10.0)
60 gLon.append(i*2.0*np.pi/10.0)
62 equatorialCoordinates = np.array([ra, dec])
63 galacticCoordinates = np.array([gLon, gLat])
65 ebvOutput = ebvObject.calculateEbv(equatorialCoordinates=equatorialCoordinates)
66 self.assertEqual(len(ebvOutput), len(ra))
68 ebvOutput = ebvObject.calculateEbv(galacticCoordinates=galacticCoordinates)
69 self.assertEqual(len(ebvOutput), len(gLon))
70 self.assertGreater(len(ebvOutput), 0)
72 self.assertRaises(RuntimeError, ebvObject.calculateEbv, equatorialCoordinates=equatorialCoordinates,
73 galacticCoordinates=galacticCoordinates)
74 self.assertRaises(RuntimeError, ebvObject.calculateEbv,
75 equatorialCoordinates=None, galacticCoordinates=None)
76 self.assertRaises(RuntimeError, ebvObject.calculateEbv)
79class MemoryTestClass(lsst.utils.tests.MemoryTestCase):
80 pass
82if __name__ == "__main__": 82 ↛ 83line 82 didn't jump to line 83, because the condition on line 82 was never true
83 lsst.utils.tests.init()
84 unittest.main()