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

85

86

87

88

89

90

91

92

93

94

""" 

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

Bandpasses from SYSENG 

 

Note: While the LSST bandpasses list throughput values corresponding to 

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

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

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

This module is intended to test whether this is happening. 

""" 

from __future__ import with_statement 

import os 

import unittest 

import numpy as np 

import lsst.utils.tests 

from lsst.utils import getPackageDir 

from lsst.sims.photUtils import BandpassDict 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

class ApproximateBandPassTest(unittest.TestCase): 

""" 

Tests for the approximate Bandpasses in the throughputs directory 

""" 

longMessage = True 

def setUp(self): 

""" 

setup before tests 

""" 

throughputsDir = getPackageDir('throughputs') 

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

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

self.refBandPassDict = BandpassDict.loadTotalBandpassesFromFiles() 

self.approxBandPassDict = \ 

BandpassDict.loadTotalBandpassesFromFiles(bandpassDir=self.approxBandPassDir) 

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

" approximate bandpasses in the lsst throughputs directory do not" 

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

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

 

def test_BandPassIntegrals(self): 

""" 

Test that the ratio of the quantity 

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

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

absolute tolerance hard coded to be 1.0e-4 

 

""" 

for bn in 'ugrizy': 

refBandPass = self.refBandPassDict[bn] 

approxBandPass = self.approxBandPassDict[bn] 

refStep = np.diff(refBandPass.wavelen) 

approxStep = np.diff(approxBandPass.wavelen) 

 

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

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

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

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

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

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

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

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

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

 

def test_BandpassesIndiviaually(self): 

""" 

Test that individual transmission values at wavelengths kept in the 

approximate bandpasses match the individual transmission values in 

the reference bandpasses 

""" 

for bn in 'ugrizy': 

approxBandPass = self.approxBandPassDict[bn] 

refBandPass = self.refBandPass[bn] 

refwavelen = refBandPass.wavelen 

approxwavelen = approxBandPass.wavelen 

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

for i, wave in enumerate(refwavelen): 

if wave in approxwavelen: 

mask[i] = True 

# Assume that the wavelengths are in order 

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

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

1.0e-4, msg=msg) 

 

def tearDown(self): 

pass 

 

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

pass 

 

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

lsst.utils.tests.init() 

unittest.main()