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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

import unittest 

import numpy as np 

 

import lsst.utils.tests 

from lsst.utils import getPackageDir 

from lsst.sims.utils.CodeUtilities import sims_clean_up 

from lsst.sims.catUtils.dust import EBVbase 

 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

class EbvTestCase(unittest.TestCase): 

 

@classmethod 

def tearDownClass(cls): 

sims_clean_up() 

 

def test_cache(self): 

""" 

Test that EBVbase() only loads each dust map once 

""" 

sims_clean_up() 

self.assertEqual(len(EBVbase._ebv_map_cache), 0) 

 

ebv1 = EBVbase() 

ebv1.load_ebvMapNorth() 

ebv1.load_ebvMapSouth() 

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

 

ebv2 = EBVbase() 

ebv2.load_ebvMapNorth() 

ebv2.load_ebvMapSouth() 

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

 

rng = np.random.RandomState(881) 

ra_list = rng.random_sample(10)*2.0*np.pi 

dec_list = rng.random_sample(10)*np.pi - 0.5*np.pi 

 

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

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

 

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

 

np.testing.assert_array_equal(ebv1_vals, ebv2_vals) 

 

def testEBV(self): 

 

ebvObject = EBVbase() 

ra = [] 

dec = [] 

gLat = [] 

gLon = [] 

for i in range(10): 

ra.append(i*2.0*np.pi/10.0) 

dec.append(i*np.pi/10.0) 

 

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

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

 

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

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

 

ebvOutput = ebvObject.calculateEbv(equatorialCoordinates=equatorialCoordinates) 

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

 

ebvOutput = ebvObject.calculateEbv(galacticCoordinates=galacticCoordinates) 

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

self.assertGreater(len(ebvOutput), 0) 

 

self.assertRaises(RuntimeError, ebvObject.calculateEbv, equatorialCoordinates=equatorialCoordinates, 

galacticCoordinates=galacticCoordinates) 

self.assertRaises(RuntimeError, ebvObject.calculateEbv, 

equatorialCoordinates=None, galacticCoordinates=None) 

self.assertRaises(RuntimeError, ebvObject.calculateEbv) 

 

 

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

pass 

 

82 ↛ 83line 82 didn't jump to line 83, because the condition on line 82 was never trueif __name__ == "__main__": 

lsst.utils.tests.init() 

unittest.main()