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

import numpy as np 

from lsst.sims.photUtils import Bandpass 

 

 

__all__ = ["getImsimFluxNorm"] 

 

 

def getImsimFluxNorm(sed, magmatch): 

""" 

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

 

Parameters: 

----------- 

sed is the SED to be normalized 

 

magmatch is the desired magnitude in the imsim bandpass 

 

Output 

------ 

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

the desired magnitude. 

""" 

 

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

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

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

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

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

 

if not hasattr(getImsimFluxNorm, 'imsim_wavelen'): 

bp = Bandpass() 

bp.imsimBandpass() 

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

getImsimFluxNorm.imsim_wavelen = bp.wavelen[non_zero_dex] 

 

if sed.fnu is None: 

sed.flambdaTofnu() 

 

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

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

 

raise RuntimeError("Cannot normalize sed " 

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

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

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

 

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

dmag = magmatch - mag 

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