-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextinction.py
214 lines (172 loc) · 6.77 KB
/
extinction.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
202
203
204
205
206
207
208
209
210
211
212
213
214
# -*- coding: utf-8 -*-
"""
Created on Fri Aug 26 09:29:52 2022
@author: hmfausey
The extinction module includes equations for the SMC, LMC, and Milky Way
extinction models based on work from Pei(1998).
Yichuan C. Pei, "Interstellar Dust from the Milky Way to the Magellenic
Clouds", The Astrophysical Journal, Volume 395, August 1992, Page 130,
http://doi.org/10.1086/171637
"""
##############################################################################
####################################IMPORTS###################################
##############################################################################
import numpy as np
##############################################################################
###################################FUNCTIONS##################################
##############################################################################
def xsi(params, lam_emit):
##Function that creates base function for extinction profiles.
# Inputs:
# params -- 2D array, holds all relevant parameters for the desired
# extinction model
# lam_emit -- wavelengths when emitted at the source/in the host galaxy
# Returns:
# xsi -- array, extinction profile at each corresponding wavelength for
# the current extinction model and input parameters.
xsi = np.zeros(len(lam_emit)) # initialize array
for i in range(len(xsi)):
# Pei extinction curves rely on a sum over 6 terms each with a different
# set of parameters
for j in range(6):
# get parameters for current sum term
ai = params[j, 0]
lami = params[j, 1]
bi = params[j, 2]
ni = params[j, 3]
# add current xsi term for current wavelength
xsi[i] += (ai) / (
(lam_emit[i] / lami) ** (ni) + (lami / lam_emit[i]) ** (ni) + bi
)
return xsi
def A_lambda(xsi_vals, E_bv, R_v):
##Function determines A_lambda using xsi function
# Inputs:
# xsi -- array, list of xsi values determined by input wavelengths and
# extinction law
# E_bv -- scalar, E_b-v value
# R_v -- scalar, R_v value according to the desired extinction model
# Returns:
# A_lam -- array, A_lambda values at corresponding input xsi values
A_lam = xsi_vals * E_bv * (1 + R_v)
return A_lam
def smc(lam_emit):
##Function applies SMC host galaxy extinction model to emitted spectrum
# Inputs:
# lam_emit -- wavelengths when emitted at the source/in the host galaxy
# Returns:
# xsi -- array, extinction profile at each corresponding wavelength for
# the current extinction model and input parameters.
# R_v -- float, specific R_v = A_v/E_b-v value for the SMC extinction
# model
params = np.array(
[
[185, 0.042, 90, 2.0],
[27, 0.08, 5.50, 4.0],
[0.005, 0.22, -1.95, 2.0],
[0.010, 9.7, -1.95, 2.0],
[0.012, 18, -1.8, 2.0],
[0.030, 25, 0.00, 2.0],
]
)
R_v = 2.93 ##For SMC
xsi_array = xsi(params, lam_emit)
return xsi_array, R_v
def lmc(lam_emit):
##Function applies LMC host galaxy extinction model to emitted spectrum
# Inputs:
# lam_emit -- array, wavelengths when emitted at the source/in the host
# galaxy
# Returns:
# xsi -- array, extinction profile at each corresponding wavelength for
# the current extinction model and input parameters.
# R_v -- float, specific R_v = A_v/E_b-v value for the LMC extinction
# model
params = np.array(
[
[175, 0.046, 90, 2.0],
[19, 0.08, 5.50, 4.5],
[0.023, 0.22, -1.95, 2.0],
[0.005, 9.7, -1.95, 2.0],
[0.006, 18, -1.80, 2.0],
[0.020, 25, 0.00, 2.0],
]
)
R_v = 3.16 # For LMC
xsi_array = xsi(params, lam_emit)
return xsi_array, R_v
def milkyway(lam_emit):
##Function applies Milky Way host galaxy extinction model to emitted
# spectrum
# Inputs:
# lam_emit -- wavelengths when emitted at the source/in the host galaxy
# Returns:
# xsi -- array, extinction profile at each corresponding wavelength for
# the current extinction model and input parameters.
# R_v -- float, specific R_v = A_v/E_b-v value for the Milky Way
# extinction model
params = np.array(
[
[165, 0.047, 90, 2.0],
[14, 0.08, 4.0, 6.5],
[0.045, 0.22, -1.95, 2.0],
[0.002, 9.7, -1.95, 2.0],
[0.002, 18, -1.80, 2.0],
[0.012, 25, 0.00, 2.0],
]
)
R_v = 3.08 # For Milky Way
xsi_array = xsi(params, lam_emit)
return xsi_array, R_v
def transmission(lam_emit, E_bv, extinction_law):
##Function calculates the transmission for an array of wavelengths and an
# extinction law.
# Inputs:
# lam_emit -- array, wavelengths when emitted at the source/in the host
# galaxy
# E_bv -- scalar, E_{B-V} value
# extinction_law -- string, indicates desired extinction law:
# smc -- Small Magellenic Cloud
# lmc -- Large Magellenic Cloud
# mw -- Milky Way
# Default is smc as this extinction law is most prevalent for GRBs
# Returns:
# transmission -- transmission coefficient
# get xsi array and R_v values based on extinction law
if extinction_law == "smc":
xsi_array, R_v = smc(lam_emit)
elif extinction_law == "lmc":
xsi_array, R_v = lmc(lam_emit)
elif extinction_law == "mw":
xsi_array, R_v = milkyway(lam_emit)
else:
raise Exception(
"Invalid extinction law. Choices are 'smc', 'lmc', or 'mw' and must be a string"
)
# Get A_lambda array
a_lam = A_lambda(xsi_array, E_bv, R_v)
# Calculate transmission based on A_lambda values
transmission = 10 ** (-0.4 * a_lam)
return transmission
def get_extincted_curve(lam_emit, flux, E_bv, extinction_law):
##Function returns extincted curve based on E_bv value and desired
# extinction law
# Inputs:
# lam_emit -- array, wavelengths when emitted at the source/in the host
# galaxy
# flux -- array, flux at each coresponding emitted wavelengths when
# emitted at the source
# E_bv -- scalar, E_{B-V} value
# extinction_law -- string, indicates desired extinction law:
# smc -- Small Magellenic Cloud
# lmc -- Large Magellenic Cloud
# mw -- Milky Way
# Default is smc as this extinction law is most prevalent for GRBs
# Returns:
# lam_emit -- array, wavelengths when emitted at the source/in the host
# galaxy
# flux_new -- array, extincted flux at each corresponding emitted
# wavelength based on the input extinction law
transmission_coeff = transmission(lam_emit, E_bv, extinction_law)
flux_new = transmission_coeff * flux
return lam_emit, flux_new