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

from builtins import range 

import numpy as np 

 

import os 

import unittest 

import lsst.utils 

import lsst.utils.tests 

from lsst.sims.utils import ObservationMetaData 

from lsst.sims.utils.CodeUtilities import sims_clean_up 

from lsst.sims.photUtils.Bandpass import Bandpass 

from lsst.sims.photUtils.Sed import Sed 

from lsst.sims.photUtils import BandpassDict 

 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

class photometryUnitTest(unittest.TestCase): 

 

@classmethod 

def tearDownClass(cls): 

sims_clean_up() 

 

def setUp(self): 

self.obs_metadata = ObservationMetaData(mjd=52000.7, bandpassName='i', 

boundType='circle', 

pointingRA=200.0, pointingDec=-30.0, 

boundLength=1.0, m5 = 25.0) 

 

def tearDown(self): 

del self.obs_metadata 

 

def testAlternateBandpassesStars(self): 

""" 

This will test our ability to do photometry using non-LSST bandpasses. 

 

It will first calculate the magnitudes using the getters in cartoonPhotometryStars. 

 

It will then load the alternate bandpass files 'by hand' and re-calculate the magnitudes 

and make sure that the magnitude values agree. This is guarding against the possibility 

that some default value did not change and the code actually ended up loading the 

LSST bandpasses. 

""" 

 

bandpassDir = os.path.join(lsst.utils.getPackageDir('sims_photUtils'), 'tests', 'cartoonSedTestData') 

 

cartoon_dict = BandpassDict.loadTotalBandpassesFromFiles(['u', 'g', 'r', 'i', 'z'], 

bandpassDir=bandpassDir, 

bandpassRoot='test_bandpass_') 

 

testBandPasses = {} 

keys = ['u', 'g', 'r', 'i', 'z'] 

 

bplist = [] 

 

for kk in keys: 

testBandPasses[kk] = Bandpass() 

testBandPasses[kk].readThroughput(os.path.join(bandpassDir, "test_bandpass_%s.dat" % kk)) 

bplist.append(testBandPasses[kk]) 

 

sedObj = Sed() 

phiArray, waveLenStep = sedObj.setupPhiArray(bplist) 

 

sedFileName = os.path.join(lsst.utils.getPackageDir('sims_photUtils'), 

'tests/cartoonSedTestData/starSed/') 

sedFileName = os.path.join(sedFileName, 'kurucz', 'km20_5750.fits_g40_5790.gz') 

ss = Sed() 

ss.readSED_flambda(sedFileName) 

 

controlBandpass = Bandpass() 

controlBandpass.imsimBandpass() 

ff = ss.calcFluxNorm(22.0, controlBandpass) 

ss.multiplyFluxNorm(ff) 

 

testMags = cartoon_dict.magListForSed(ss) 

 

ss.resampleSED(wavelen_match = bplist[0].wavelen) 

ss.flambdaTofnu() 

mags = -2.5*np.log10(np.sum(phiArray*ss.fnu, axis=1)*waveLenStep) - ss.zp 

self.assertEqual(len(mags), len(testMags)) 

self.assertGreater(len(mags), 0) 

for j in range(len(mags)): 

self.assertAlmostEqual(mags[j], testMags[j], 10) 

 

 

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

pass 

 

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

lsst.utils.tests.init() 

unittest.main()