-
Notifications
You must be signed in to change notification settings - Fork 3
/
magnitude_calculations.py
202 lines (151 loc) · 4.38 KB
/
magnitude_calculations.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#Duncan Campbell
#September 17, 2014
#Yale University
"""
Functions that compute quantities dealing with magnitudes.
"""
from __future__ import division
__all__=['apparent_to_absolute_magnitude','absolute_to_apparent_magnitude','luminosity_to_absolute_magnitude','absolute_magnitude_to_luminosity','absolute_magnitude_lim','get_sun_mag']
import numpy as np
def apparent_to_absolute_magnitude(m, d_L):
"""
calculate the absolute magnitude
Parameters
----------
m: array_like
apparent magnitude
d_L: array_like
luminosity distance to object in Mpc
Returns
-------
Mag: np.array of absolute magnitudes
"""
M = m - 5.0*(np.log10(d_L)+5.0)
return M
def absolute_to_apparent_magnitude(M, d_L):
"""
calculate the apparent magnitude given an absolute magnitude
Parameters
----------
M: array_like
absolute magnitude
d_L: array_like
luminosity distance to object in Mpc
Returns
-------
mag: np.array of apparent magnitudes
"""
m = M + 5.0*(np.log10(d_L)+5.0)
return m
def luminosity_to_absolute_magnitude(L, band, system='SDSS_Blanton_2003_z0.1'):
"""
calculate the absolute magnitude
Parameters
----------
L: array_like
luminosity
band: string
filter band
system: string, optional
filter systems: default is 'SDSS_Blanton_2003_z0.1'
1. Binney_and_Merrifield_1998
2. SDSS_Blanton_2003_z0.1
Returns
-------
Mag: np.array of absolute magnitudes
"""
Msun = get_sun_mag(band,system)
Lsun = 1.0
M = -2.5*np.log10(L/Lsun) + Msun
return M
def absolute_magnitude_to_luminosity(M, band, system='SDSS_Blanton_2003_z0.1'):
"""
calculate the Luminosity
Parameters
----------
M: array_like
absolute magnitude
band: string
filter band
system: string, optional
filter systems: default is 'SDSS_Blanton_2003_z0.1'
1. Binney_and_Merrifield_1998
2. SDSS_Blanton_2003_z0.1
Returns
-------
L: np.array of Luminosities in $log(L_{\odot})$
"""
Msun = get_sun_mag(band,system)
L = (M-Msun)/(-2.5) #in log(L/Lsun)
return L
def absolute_magnitude_lim(z, app_mag_lim, cosmo=None):
"""
give the absolute magnitude limit as a function of redshift for a flux-limited survey.
Parameters
----------
z: array_like
redshift
app_mag_lim: float
apparent magnitude limit
cosmo: cosmology object
Returns
-------
M,z: np.array, np.array
absolute magnitude in mag+5loh(h) units
"""
if cosmo==None:
from astropy.cosmology import FlatLambdaCDM
cosmo = FlatLambdaCDM(H0=70, Om0=0.3)
print('Warning, no cosmology specified, using default:',cosmo)
d_L = cosmo.luminosity_distance(z).value
M = apparent_to_absolute_magnitude(app_mag_lim, d_L)
return M-5.0*np.log10(cosmo.h)
def get_sun_mag(filter,system):
"""
get the solar value for a filter in a system.
Parameters
----------
filter: string
system: string
Returns
-------
Msun: float
"""
if system=='Binney_and_Merrifield_1998':
#see Binney and Merrifield 1998
if filter=='U':
return 5.61
elif filter=='B':
return 5.48
elif filter=='V':
return 4.83
elif filter=='R':
return 4.42
elif filter=='I':
return 4.08
elif filter=='J':
return 3.64
elif filter=='H':
return 3.32
elif filter=='K':
return 3.28
else:
raise ValueError('Filter does not exist in this system.')
if system=='SDSS_Blanton_2003_z0.1':
#see Blanton et al. 2003 equation 14
if filter=='u':
return 6.80
elif filter=='g':
return 5.45
elif filter=='r':
return 4.76
elif filter=='i':
return 4.58
elif filter=='z':
return 4.51
else:
raise ValueError('Filter does not exist in this system.')
else:
raise ValueError('Filter system not included in this package.')
def get_vmax(M,m,cosmo,w):
Vmax = (w/3.0)*(dmax/(1.0+z))**3.0