Hide keyboard shortcuts

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 

3 

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 

8 

9 

10def setup_module(module): 

11 lsst.utils.tests.init() 

12 

13 

14class EbvTestCase(unittest.TestCase): 

15 

16 @classmethod 

17 def tearDownClass(cls): 

18 sims_clean_up() 

19 

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) 

26 

27 ebv1 = EBVbase() 

28 ebv1.load_ebvMapNorth() 

29 ebv1.load_ebvMapSouth() 

30 self.assertEqual(len(EBVbase._ebv_map_cache), 2) 

31 

32 ebv2 = EBVbase() 

33 ebv2.load_ebvMapNorth() 

34 ebv2.load_ebvMapSouth() 

35 self.assertEqual(len(EBVbase._ebv_map_cache), 2) 

36 

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 

40 

41 ebv1_vals = ebv1.calculateEbv(equatorialCoordinates=np.array([ra_list, dec_list])) 

42 ebv2_vals = ebv2.calculateEbv(equatorialCoordinates=np.array([ra_list, dec_list])) 

43 

44 self.assertEqual(len(EBVbase._ebv_map_cache), 2) 

45 

46 np.testing.assert_array_equal(ebv1_vals, ebv2_vals) 

47 

48 def testEBV(self): 

49 

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) 

58 

59 gLat.append(-0.5*np.pi+i*np.pi/10.0) 

60 gLon.append(i*2.0*np.pi/10.0) 

61 

62 equatorialCoordinates = np.array([ra, dec]) 

63 galacticCoordinates = np.array([gLon, gLat]) 

64 

65 ebvOutput = ebvObject.calculateEbv(equatorialCoordinates=equatorialCoordinates) 

66 self.assertEqual(len(ebvOutput), len(ra)) 

67 

68 ebvOutput = ebvObject.calculateEbv(galacticCoordinates=galacticCoordinates) 

69 self.assertEqual(len(ebvOutput), len(gLon)) 

70 self.assertGreater(len(ebvOutput), 0) 

71 

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) 

77 

78 

79class MemoryTestClass(lsst.utils.tests.MemoryTestCase): 

80 pass 

81 

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()