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

1from builtins import range 

2import numpy as np 

3 

4import os 

5import unittest 

6import lsst.utils 

7import lsst.utils.tests 

8from lsst.sims.utils import ObservationMetaData 

9from lsst.sims.utils.CodeUtilities import sims_clean_up 

10from lsst.sims.photUtils.Bandpass import Bandpass 

11from lsst.sims.photUtils.Sed import Sed 

12from lsst.sims.photUtils import BandpassDict 

13 

14 

15def setup_module(module): 

16 lsst.utils.tests.init() 

17 

18 

19class photometryUnitTest(unittest.TestCase): 

20 

21 @classmethod 

22 def tearDownClass(cls): 

23 sims_clean_up() 

24 

25 def setUp(self): 

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

27 boundType='circle', 

28 pointingRA=200.0, pointingDec=-30.0, 

29 boundLength=1.0, m5 = 25.0) 

30 

31 def tearDown(self): 

32 del self.obs_metadata 

33 

34 def testAlternateBandpassesStars(self): 

35 """ 

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

37 

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

39 

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

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

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

43 LSST bandpasses. 

44 """ 

45 

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

47 

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

49 bandpassDir=bandpassDir, 

50 bandpassRoot='test_bandpass_') 

51 

52 testBandPasses = {} 

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

54 

55 bplist = [] 

56 

57 for kk in keys: 

58 testBandPasses[kk] = Bandpass() 

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

60 bplist.append(testBandPasses[kk]) 

61 

62 sedObj = Sed() 

63 phiArray, waveLenStep = sedObj.setupPhiArray(bplist) 

64 

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

66 'tests/cartoonSedTestData/starSed/') 

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

68 ss = Sed() 

69 ss.readSED_flambda(sedFileName) 

70 

71 controlBandpass = Bandpass() 

72 controlBandpass.imsimBandpass() 

73 ff = ss.calcFluxNorm(22.0, controlBandpass) 

74 ss.multiplyFluxNorm(ff) 

75 

76 testMags = cartoon_dict.magListForSed(ss) 

77 

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

79 ss.flambdaTofnu() 

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

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

82 self.assertGreater(len(mags), 0) 

83 for j in range(len(mags)): 

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

85 

86 

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

88 pass 

89 

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

91 lsst.utils.tests.init() 

92 unittest.main()