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""" 

2Module to test that Approximate Bandpasses are in sync with the official LSST 

3Bandpasses from SYSENG 

4 

5Note: While the LSST bandpasses list throughput values corresponding to 

6wavelengths in the range of 300.0-1150.0 nm, the `approximate_baseline` 

7directory of throughputs is created by a script manually. It is thus possible 

8for this directory to fall out of sync with the SYSENG values in `baseline`. 

9This module is intended to test whether this is happening. 

10""" 

11from __future__ import with_statement 

12import os 

13import unittest 

14import numpy as np 

15import lsst.utils.tests 

16from lsst.utils import getPackageDir 

17from lsst.sims.photUtils import BandpassDict 

18 

19def setup_module(module): 

20 lsst.utils.tests.init() 

21 

22class ApproximateBandPassTest(unittest.TestCase): 

23 """ 

24 Tests for the approximate Bandpasses in the throughputs directory 

25 """ 

26 longMessage = True 

27 def setUp(self): 

28 """ 

29 setup before tests 

30 """ 

31 throughputsDir = getPackageDir('throughputs') 

32 self.approxBandPassDir = os.path.join(throughputsDir, 'approximate_baseline') 

33 self.refBandPassDir = os.path.join(throughputsDir, 'baseline') 

34 self.refBandPassDict = BandpassDict.loadTotalBandpassesFromFiles() 

35 self.approxBandPassDict = \ 

36 BandpassDict.loadTotalBandpassesFromFiles(bandpassDir=self.approxBandPassDir) 

37 self.errorMsg = "The failure of this test indicates that the" 

38 " approximate bandpasses in the lsst throughputs directory do not" 

39 "sync up with the baseline bandpasses is throughputs. This may require running" 

40 " the script : throughputs.approximate_baseline/approximateBandpasses.py" 

41 

42 def test_BandPassIntegrals(self): 

43 """ 

44 Test that the ratio of the quantity 

45 \int d\lambda T(\lambda) = band flux for a SED proportional to $\lambda$ 

46 for the approximate bandpasses to the SYSENG band passes is 1.0 to an 

47 absolute tolerance hard coded to be 1.0e-4 

48 

49 """ 

50 for bn in 'ugrizy': 

51 refBandPass = self.refBandPassDict[bn] 

52 approxBandPass = self.approxBandPassDict[bn] 

53 refStep = np.diff(refBandPass.wavelen) 

54 approxStep = np.diff(approxBandPass.wavelen) 

55 

56 # Currently we have uniform sampling, but the end points have 

57 # very slightly different steps. This accounts for 3 possible values 

58 # If there are more, then the steps are non-unifor 

59 msg = 'The step sizes in {} seem to be unequal'.format('Approximate Baseline') 

60 self.assertEqual(len(np.unique(approxStep)), 3, msg=msg) 

61 msg = 'The step sizes in {} seem to be unequal'.format('Baseline') 

62 self.assertEqual(len(np.unique(refStep)), 3, msg=msg) 

63 ratio = approxStep[1] * approxBandPass.sb.sum() / refStep[1]/ refBandPass.sb.sum() 

64 self.assertAlmostEqual(ratio, 1.0, delta=1.0e-4, msg=self.errorMsg) 

65 

66 def test_BandpassesIndiviaually(self): 

67 """ 

68 Test that individual transmission values at wavelengths kept in the 

69 approximate bandpasses match the individual transmission values in 

70 the reference bandpasses 

71 """ 

72 for bn in 'ugrizy': 

73 approxBandPass = self.approxBandPassDict[bn] 

74 refBandPass = self.refBandPass[bn] 

75 refwavelen = refBandPass.wavelen 

76 approxwavelen = approxBandPass.wavelen 

77 mask = np.zeros(len(refwavelen), dtype=bool) 

78 for i, wave in enumerate(refwavelen): 

79 if wave in approxwavelen: 

80 mask[i] = True 

81 # Assume that the wavelengths are in order 

82 msg = 'individual matches failed on band {}'.format(bn) 

83 self.assertAlmostEqual(refBandPass.sb[mask], approxBandPass.sb, 

84 1.0e-4, msg=msg) 

85 

86 def tearDown(self): 

87 pass 

88 

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

90 pass 

91 

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

93 lsst.utils.tests.init() 

94 unittest.main()