Commit 2c699c7b authored by Médéric Boquien's avatar Médéric Boquien
Browse files

Ensure that the Lyman continuum emission is properly absorbed by the gas in...

Ensure that the Lyman continuum emission is properly absorbed by the gas in the nebular module. This means that without that module, the Lyman continuum is left untouched. As this may be an issue for people used to running without the nebular module (assuming that the flux in individual bands in small), add an option to only absorb the Lyman continuum while discarding any nebular emission.
parent 250575ef
......@@ -259,7 +259,9 @@ class CalzLeit(CreationModule):
powerlaw_slope)
attenuation_total = 0.
for contrib in list(sed.contribution_names):
contribs = [contrib for contrib in sed.contribution_names if
'absorption' not in contrib]
for contrib in contribs:
age = contrib.split('.')[-1].split('_')[-1]
luminosity = sed.get_lumin_contribution(contrib)
attenuated_luminosity = (luminosity * 10 **
......
......@@ -185,7 +185,9 @@ class PowerLawAtt(CreationModule):
uv_bump_width, uv_bump_amplitude)
attenuation_total = 0.
for contrib in list(sed.contribution_names):
contribs = [contrib for contrib in sed.contribution_names if
'absorption' not in contrib]
for contrib in contribs:
age = contrib.split('.')[-1].split('_')[-1]
luminosity = sed.get_lumin_contribution(contrib)
attenuated_luminosity = (luminosity * 10 **
......
......@@ -16,8 +16,8 @@ class NebularEmission(CreationModule):
"""
Module computing the nebular emission from the ultraviolet to the
near-infrared. It includes both the nebular lines and the nubular
continuum. It takes into account the escape fraction and the absorption by
dust.
continuum (optional). It takes into account the escape fraction and the
absorption by dust.
Given the number of Lyman continuum photons, we compute the Hβ line
luminosity. We then compute the other lines using the
......@@ -47,6 +47,11 @@ class NebularEmission(CreationModule):
'float',
"Line width in km/s",
300.
)),
('emission', (
'boolean',
"Include nebular emission.",
True
))
])
......@@ -55,67 +60,69 @@ class NebularEmission(CreationModule):
them to see the line profile. Compute scaling coefficients.
"""
fesc = self.parameters['f_esc']
fdust = self.parameters['f_dust']
self.fesc = self.parameters['f_esc']
self.fdust = self.parameters['f_dust']
self.emission = (self.parameters["emission"].lower() == "true")
if fesc < 0. or fesc > 1:
if self.fesc < 0. or self.fesc > 1:
raise Exception("Escape fraction must be between 0 and 1")
if fdust < 0 or fdust > 1:
if self.fdust < 0 or self.fdust > 1:
raise Exception("Fraction of lyman photons absorbed by dust must "
"be between 0 and 1")
if fesc + fdust > 1:
if self.fesc + self.fdust > 1:
raise Exception("Escape fraction+f_dust>1")
with Database() as db:
self.lines_template = {m:
db.
get_nebular_lines(m,
self.parameters['logU'])
for m in db.get_nebular_lines_parameters()
['metallicity']
}
self.cont_template = {m:
db.
get_nebular_continuum(m,
if self.emission:
with Database() as db:
self.lines_template = {m: db.get_nebular_lines(m,
self.parameters['logU'])
for m in db.get_nebular_continuum_parameters()
['metallicity']
}
lines_width = self.parameters['lines_width'] * 1e3
for lines in self.lines_template.values():
new_wave = np.array([])
for line_wave in lines.wave:
width = line_wave * lines_width / cst.c
new_wave = np.concatenate((new_wave,
np.linspace(line_wave - 3. * width,
line_wave + 3. * width,
9)))
new_wave.sort()
new_flux = np.zeros_like(new_wave)
for line_flux, line_wave in zip(lines.ratio, lines.wave):
width = line_wave * lines_width / cst.c
new_flux += (line_flux * np.exp(- 4. * np.log(2.) *
(new_wave - line_wave) ** 2. / (width * width)) /
(width * np.sqrt(np.pi / np.log(2.)) / 2.))
lines.wave = new_wave
lines.ratio = new_flux
# We compute the conversion coefficient to determine the fluxes using
# the formula of Inoue 2011: LHβ=Q(H)*γHβ(10000K)/αβ(10000K)
gamma_Hbeta = 1.23e-38 # Inoue 2011, W m³
alpha_B = 2.58e-19 # Ferland 1980, m³ s¯¹
# To take into acount the escape fraction and the fraction of Lyman
# continuum photons absorbed by dust we correct by a factor
# k=(1-fesc-fdust)/(1+(α1/αβ)*(fesc+fdust))
alpha_1 = 1.54e-19 # αA-αB, Ferland 1980, m³ s¯¹
k = (1. - fesc - fdust) / (1. + alpha_1 / alpha_B * (fesc + fdust))
self.conv_line = gamma_Hbeta / alpha_B * k
self.conv_cont = k
for m in db.get_nebular_lines_parameters()
['metallicity']
}
self.cont_template = {m: db.get_nebular_continuum(m,
self.parameters['logU'])
for m in db.get_nebular_continuum_parameters()
['metallicity']
}
lines_width = self.parameters['lines_width'] * 1e3
for lines in self.lines_template.values():
new_wave = np.array([])
for line_wave in lines.wave:
width = line_wave * lines_width / cst.c
new_wave = np.concatenate((new_wave,
np.linspace(line_wave - 3. * width,
line_wave + 3. * width,
9)))
new_wave.sort()
new_flux = np.zeros_like(new_wave)
for line_flux, line_wave in zip(lines.ratio, lines.wave):
width = line_wave * lines_width / cst.c
new_flux += (line_flux * np.exp(- 4. * np.log(2.) *
(new_wave - line_wave) ** 2. / (width * width)) /
(width * np.sqrt(np.pi / np.log(2.)) / 2.))
lines.wave = new_wave
lines.ratio = new_flux
# We compute the conversion coefficient to determine the fluxes using
# the formula of Inoue 2011: LHβ=Q(H)*γHβ(10000K)/αβ(10000K)
gamma_Hbeta = 1.23e-38 # Inoue 2011, W m³
alpha_B = 2.58e-19 # Ferland 1980, m³ s¯¹
# To take into acount the escape fraction and the fraction of Lyman
# continuum photons absorbed by dust we correct by a factor
# k=(1-fesc-fdust)/(1+(α1/αβ)*(fesc+fdust))
alpha_1 = 1.54e-19 # αA-αB, Ferland 1980, m³ s¯¹
k = (1. - self.fesc - self.fdust) / (1. + alpha_1 / alpha_B * (
self.fesc + self.fdust))
self.conv_line = gamma_Hbeta / alpha_B * k
self.conv_cont = k
self.idx_Ly_break = None
self.absorbed_old = None
self.absorbed_young = None
def process(self, sed):
"""Add the nebular emission lines
......@@ -126,29 +133,48 @@ class NebularEmission(CreationModule):
parameters: dictionary containing the parameters
"""
NLy_old = sed.info['stellar.n_ly_old']
NLy_young = sed.info['stellar.n_ly_young']
lines = self.lines_template[sed.info['stellar.metallicity']]
cont = self.cont_template[sed.info['stellar.metallicity']]
if self.idx_Ly_break is None:
self.idx_Ly_break = np.searchsorted(sed.wavelength_grid, 91.2)
self.absorbed_old = np.zeros(sed.wavelength_grid.size)
self.absorbed_young = np.zeros(sed.wavelength_grid.size)
self.absorbed_young = np.zeros(sed.wavelength_grid.size)
self.absorbed_old[:self.idx_Ly_break] -= (
sed.get_lumin_contribution('stellar.old')[:self.idx_Ly_break] *
(1. - self.fesc))
self.absorbed_young[:self.idx_Ly_break] -= (
sed.get_lumin_contribution('stellar.young')[:self.idx_Ly_break] *
(1. - self.fesc))
sed.add_module(self.name, self.parameters)
sed.add_info('nebular.logU', self.parameters['logU'])
sed.add_info('nebular.f_esc', self.parameters['f_esc'])
sed.add_info('nebular.f_dust', self.parameters['f_dust'])
sed.add_info('nebular.lines_width', self.parameters['lines_width'])
sed.add_info('nebular.f_esc', self.fesc)
sed.add_info('nebular.f_dust', self.fdust)
sed.add_info('dust.luminosity', (sed.info['stellar.lum_ly_young'] +
sed.info['stellar.lum_ly_old']) *
self.parameters['f_dust'], True)
sed.add_contribution('nebular.lines_old', lines.wave,
lines.ratio * NLy_old * self.conv_line)
sed.add_contribution('nebular.lines_young', lines.wave,
lines.ratio * NLy_young * self.conv_line)
sed.add_contribution('nebular.continuum_old', cont.wave,
cont.lumin * NLy_old * self.conv_cont)
sed.add_contribution('nebular.continuum_young', cont.wave,
cont.lumin * NLy_young * self.conv_cont)
sed.info['stellar.lum_ly_old']) * self.fdust, True)
sed.add_contribution('nebular.absorption_old', sed.wavelength_grid,
self.absorbed_old)
sed.add_contribution('nebular.absorption_young', sed.wavelength_grid,
self.absorbed_young)
if self.emission:
NLy_old = sed.info['stellar.n_ly_old']
NLy_young = sed.info['stellar.n_ly_young']
lines = self.lines_template[sed.info['stellar.metallicity']]
cont = self.cont_template[sed.info['stellar.metallicity']]
sed.add_info('nebular.lines_width', self.parameters['lines_width'])
sed.add_info('nebular.logU', self.parameters['logU'])
sed.add_contribution('nebular.lines_old', lines.wave,
lines.ratio * NLy_old * self.conv_line)
sed.add_contribution('nebular.lines_young', lines.wave,
lines.ratio * NLy_young * self.conv_line)
sed.add_contribution('nebular.continuum_old', cont.wave,
cont.lumin * NLy_old * self.conv_cont)
sed.add_contribution('nebular.continuum_young', cont.wave,
cont.lumin * NLy_young * self.conv_cont)
# CreationModule to be returned by get_module
Module = NebularEmission
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment