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

1import numpy as np 

2from lsst.sims.photUtils import Bandpass 

3 

4 

5__all__ = ["getImsimFluxNorm"] 

6 

7 

8def getImsimFluxNorm(sed, magmatch): 

9 """ 

10 Calculate the flux normalization of an SED in the imsim bandpass. 

11 

12 Parameters: 

13 ----------- 

14 sed is the SED to be normalized 

15 

16 magmatch is the desired magnitude in the imsim bandpass 

17 

18 Output 

19 ------ 

20 The factor by which the flux of sed needs to be multiplied to achieve 

21 the desired magnitude. 

22 """ 

23 

24 # This method works based on the assumption that the imsim bandpass 

25 # is a delta function. If that ever ceases to be true, the unit test 

26 # testSedUtils.py, which checks that the results of this method are 

27 # identical to calling Sed.calcFluxNorm and passing in the imsim bandpass, 

28 # will fail and we will know to modify this method. 

29 

30 if not hasattr(getImsimFluxNorm, 'imsim_wavelen'): 

31 bp = Bandpass() 

32 bp.imsimBandpass() 

33 non_zero_dex = np.where(bp.sb > 0.0)[0][0] 

34 getImsimFluxNorm.imsim_wavelen = bp.wavelen[non_zero_dex] 

35 

36 if sed.fnu is None: 

37 sed.flambdaTofnu() 

38 

39 if (getImsimFluxNorm.imsim_wavelen < sed.wavelen.min() or 

40 getImsimFluxNorm.imsim_wavelen > sed.wavelen.max()): 

41 

42 raise RuntimeError("Cannot normalize sed " 

43 "at wavelength of %e nm\n" % getImsimFluxNorm.imsim_wavelen 

44 + "The SED does not cover that wavelength\n" 

45 + "(Covers %e < lambda %e)" % (sed.wavelen.min(), sed.wavelen.max())) 

46 

47 mag = -2.5*np.log10(np.interp(getImsimFluxNorm.imsim_wavelen, sed.wavelen, sed.fnu)) - sed.zp 

48 dmag = magmatch - mag 

49 return np.power(10, (-0.4*dmag))