Coverage for python/lsst/sims/seeingModel/utils.py : 19%

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 os
2import warnings
5__all__ = ['get_effwavelens']
7DEFAULT_THROUGHPUTS_VERSION = '1.1'
8DEFAULT_FILTER_LIST = ['u', 'g', 'r', 'i', 'z', 'y']
9DEFAULT_WAVELENGTHS = [367.06988658, 482.68517118,
10 622.32403587, 754.59752265,
11 869.09018708, 971.02780848]
14def get_effwavelens(filter_list=('u', 'g', 'r', 'i', 'z', 'y')):
15 """Calculate the effective wavelengths for 'filter_list'.
17 Parameters
18 ----------
19 filter_list: list of str, opt
20 List of the filters for which to calculate effective wavelengths.
21 Default = ('u', 'g', 'r', 'i', 'z', 'y')
23 Returns
24 -------
25 List of floats
26 The effective wavelengths (in nm).
28 This function will attempt to calculate the effective wavelengths using
29 the throughputs curves in the throughput directory and sims_photUtils.
31 If sims_photUtils or throughputs is unavailable, it will just use the default values
32 provided with the utility.
33 """
34 try:
35 from lsst.sims.photUtils import Bandpass
36 import lsst.sims.photUtils.version as photUtils_version
37 no_photUtils = False
38 except ImportError:
39 no_photUtils = True
41 fdir = os.getenv('LSST_THROUGHPUTS_DEFAULT')
42 if no_photUtils or (fdir is None):
43 warnings.warn('Cannot calculate effective wavelengths; either sims_photUtils is '
44 'unavailable (setup sims_photUtils) or $LSST_THROUGHPUTS_DEFAULT '
45 'is undefined (setup throughputs package). '
46 'Without these, simply using default effective wavelengths from version %s.'
47 % (DEFAULT_THROUGHPUTS_VERSION), Warning)
48 photUtilsVersion = 'none'
49 throughputsVersion = DEFAULT_THROUGHPUTS_VERSION
50 effwavelens = []
51 for f in filter_list:
52 idx = filter_list.index(f)
53 effwavelens.append(DEFAULT_WAVELENGTHS[idx])
54 else:
55 # Read the throughputs curves from the throughputs package.
56 # Note that if sims_photUtils is setup, the throughputs package is as well.
57 photUtilsVersion = photUtils_version.__version__
58 effwavelens = []
59 for f in filter_list:
60 bp = Bandpass()
61 bp.readThroughput(os.path.join(fdir, 'total_' + f + '.dat'))
62 effwavelens.append(bp.calcEffWavelen()[1])
63 with open(os.path.join(fdir, 'version_info'), 'r') as version_info:
64 throughputsVersion = version_info.read().strip()
65 return photUtilsVersion, throughputsVersion, effwavelens