Coverage for python/lsst/sims/utils/stellarMags.py : 10%

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 __future__ import print_function
2from builtins import zip
3from builtins import range
4import numpy as np
6__all__ = ['stellarMags']
9def calcWDColors():
10 """
11 Calculate a few example WD colors. Values to go in stellarMags(). Here in case
12 values need to be regenerated (different stars, bandpasses change, etc.)
13 """
15 try:
16 from lsst.utils import getPackageDir
17 import os
18 from lsst.sims.photUtils import Bandpass, Sed
19 except:
20 'Need to setup sims_photUtils to generate WD magnitudes.'
22 names = ['HeWD_25200_80', 'WD_11000_85', 'WD_3000_85']
23 fns = ['bergeron_He_24000_80.dat_25200.gz',
24 'bergeron_10500_85.dat_11000.gz', 'bergeron_2750_85.dat_3000.gz']
25 wdDir = os.path.join(getPackageDir('sims_sed_library'), 'starSED/wDs/')
26 files = [os.path.join(wdDir, filename) for filename in fns]
28 # Read in the LSST bandpasses
29 bpNames = ['u', 'g', 'r', 'i', 'z', 'y']
30 bps = []
31 throughPath = os.path.join(getPackageDir('throughputs'), 'baseline')
32 for key in bpNames:
33 bp = np.loadtxt(os.path.join(throughPath, 'filter_' + key + '.dat'),
34 dtype=list(zip(['wave', 'trans'], [float] * 2)))
35 tempB = Bandpass()
36 tempB.setBandpass(bp['wave'], bp['trans'])
37 bps.append(tempB)
39 # Read in the SEDs and compute mags
40 mags = []
41 for filename in files:
42 star = Sed()
43 star.readSED_flambda(filename)
44 singleMags = [star.calcMag(band) for band in bps]
45 mags.append([singleMags[i - 1] - singleMags[i] for i in range(1, 6)])
47 for maglist, fn, name in zip(mags, fns, names):
48 format = (name, fn) + tuple(maglist)
49 print("['%s', '%s', %f, %f, %f, %f, %f]" % format)
52def stellarMags(stellarType, rmag=19.):
53 """
54 Calculates the expected magnitudes in LSST filters for a
55 typical star of the given spectral type.
57 Based on mapping of Kuruz models to spectral types here:
58 http://www.stsci.edu/hst/observatory/crds/k93models.html
61 Parameters
62 ----------
63 stellarType : str
64 Spectral type of a star (O,B,A,F,G,K,M), or for white dwarf colors,
65 one of 'HeWD_25200_80, 'WD_11000_85', 'WD_3000_85'
66 rmag : float
67 The expected r-band magnitude of the star.
69 Returns
70 -------
71 dict of floats
72 The expected magnitudes in LSST filters.
73 """
75 # If this is the first time running the function, set up the data array
76 if not hasattr(stellarMags, 'data'):
77 names = ['stellarType', 'Model Name',
78 'u-g', 'g-r', 'r-i', 'i-z', 'z-y']
79 types = [('U', 20), ('U', 35), float, float, float, float, float]
80 data = np.core.records.fromrecords([
81 ['O', 'kp00_50000[g50]', -0.4835688497, -0.5201721327,
82 -0.3991733698, -0.3106800468, -0.2072290744],
83 ['B', 'kp00_30000[g40]', -0.3457202828, -0.4834762052,
84 -0.3812792176, -0.2906072887, -0.1927230035],
85 ['A', 'kp00_9500[g40]', 0.8823182684, -0.237288029,
86 -0.2280783991, -0.1587960264, -0.03043824335],
87 ['F', 'kp00_7250[g45]', 0.9140316091, 0.1254277486,
88 -0.03419150003, -0.0802010739, -0.03802756413],
89 ['G', 'kp00_6000[g45]', 1.198219095, 0.3915608688,
90 0.09129426676, 0.002604263747, -0.004659443668],
91 ['K', 'kp00_5250[g45]', 1.716635024, 0.6081567546,
92 0.1796910856, 0.06492278686, 0.0425155827],
93 ['M', 'kp00_3750[g45]', 2.747842719, 1.287599638,
94 0.5375622482, 0.4313486709, 0.219308065],
95 ['HeWD_25200_80', 'bergeron_He_24000_80.dat_25200.gz',
96 -0.218959, -0.388374, -0.326946, -0.253573, -0.239460],
97 ['WD_11000_85', 'bergeron_10500_85.dat_11000.gz',
98 0.286146, -0.109115, -0.178500, -0.185833, -0.186913],
99 ['WD_3000_85', 'bergeron_2750_85.dat_3000.gz',
100 3.170620, 1.400062, 0.167195, 0.127024, -0.378069]],
101 dtype=list(zip(names, types)))
102 # Switch to a dict for faster look-up
103 stellarMags.data = {}
104 for row in data:
105 stellarMags.data['%s' % row['stellarType']] = row
107 results = {}
108 # good = np.where(stellarMags.data['stellarType'] == stellarType)
109 if stellarType not in stellarMags.data:
110 message = 'Received stellarType %s' % stellarType
111 message += ' but expected one of %s' % ', '.join(stellarMags.data.keys())
112 raise ValueError(message)
114 results['r'] = rmag
115 results['i'] = rmag - stellarMags.data[stellarType]['r-i']
116 results['z'] = results['i'] - stellarMags.data[stellarType]['i-z']
117 results['y'] = results['z'] - stellarMags.data[stellarType]['z-y']
118 results['g'] = stellarMags.data[stellarType]['g-r'] + results['r']
119 results['u'] = stellarMags.data[stellarType]['u-g'] + results['g']
120 return results