Commit 27fb48f0 authored by Médéric Boquien's avatar Médéric Boquien

Rather than calling convolve() twice, call it just once with the separation...

Rather than calling convolve() twice, call it just once with the separation age as an argument et let it do the various different convolutions. While this is functionally equivalent, this allows to pass the full SFH to convolve(), which in turn is necessary to compute additional quantities. This patch is a preparatory work for the the implementation of mass-weighted ages.
parent 36ab34db
......@@ -66,7 +66,7 @@ class BC03(object):
self.info_table = info_table
self.spec_table = spec_table
def convolve(self, sfh):
def convolve(self, sfh, separation_age):
"""Convolve the SSP with a Star Formation History
Given an SFH, this method convolves the info table and the SSP
......@@ -76,6 +76,8 @@ class BC03(object):
----------
sfh: array of floats
Star Formation History in Msun/yr.
separation_age: float
Age separating the young from the old stellar populations in Myr.
Returns
-------
......@@ -88,18 +90,28 @@ class BC03(object):
* "n_ly": rate of H-ionizing photons (s-1)
"""
# The convolution is just a matter of reverting the SFH and computing
# the sum of the data from the SSP one to one product. This is done
# using the dot product. We take only the first three elements from the
# info_table as the others do not make sense when convolved with the
# SFH (break strength).
# We cut the SSP to the maximum age considered to simplify the
# computation. We take only the first three elements from the info_table
# as the others do not make sense when convolved with the SFH (break
# strength).
info_table = self.info_table[:3, :sfh.size]
spec_table = self.spec_table[:, :sfh.size]
# The 1e6 factor is because the SFH is in solar mass per year.
info = 1e6 * np.dot(info_table, sfh[::-1])
spec = 1e6 * np.dot(spec_table, sfh[::-1])
info = dict(zip(["m_star", "m_gas", "n_ly"], info))
return spec, info
# The convolution is just a matter of reverting the SFH and computing
# the sum of the data from the SSP one to one product. This is done
# using the dot product. The 1e6 factor is because the SFH is in solar
# mass per year.
info_young = 1e6 * np.dot(info_table[:, :separation_age],
sfh[-separation_age:][::-1])
spec_young = 1e6 * np.dot(spec_table[:, :separation_age],
sfh[-separation_age:][::-1])
info_old = 1e6 * np.dot(info_table[:, separation_age:],
sfh[:-separation_age][::-1])
spec_old = 1e6 * np.dot(spec_table[:, separation_age:],
sfh[:-separation_age][::-1])
info_young = dict(zip(["m_star", "m_gas", "n_ly"], info_young))
info_old = dict(zip(["m_star", "m_gas", "n_ly"], info_old))
return spec_young, spec_old, info_young, info_old
......@@ -62,7 +62,7 @@ class M2005(object):
self.info_table = info_table
self.spec_table = spec_table
def convolve(self, sfh):
def convolve(self, sfh, separation_age):
"""Convolve the SSP with a Star Formation History
Convolves the SSP and the associated info with the SFH.
......@@ -71,6 +71,8 @@ class M2005(object):
----------
sfh: array of floats
Star Formation History in Msun/yr.
separation_age: float
Age separating the young from the old stellar populations in Myr.
Returns
-------
......@@ -85,15 +87,24 @@ class M2005(object):
* info[5]: turn-off mass
"""
# As both the SFH and the SSP (limited to the age of the SFH) data now
# share the same time grid, the convolution is just a matter of
# reverting one and computing the sum of the one to one product; this
# is done using the dot product.
# We cut the SSP to the maximum age considered to simplify the
# computation.
info_table = self.info_table[:, :sfh.size]
spec_table = self.spec_table[:, :sfh.size]
# The 1e6 factor is because the SFH is in solar mass per year.
info = 1e6 * np.dot(info_table, sfh[::-1])
spec = 1e6 * np.dot(spec_table, sfh[::-1])
return info, spec
# As both the SFH and the SSP (limited to the age of the SFH) data now
# share the same time grid, the convolution is just a matter of
# reverting one and computing the sum of the one to one product; this
# is done using the dot product. The 1e6 factor is because the SFH is in
# solar mass per year.
info_young = 1e6 * np.dot(info_table[:, :separation_age],
sfh[-separation_age:][::-1])
spec_young = 1e6 * np.dot(spec_table[:, :separation_age],
sfh[-separation_age:][::-1])
info_old = 1e6 * np.dot(info_table[:, separation_age:],
sfh[:-separation_age][::-1])
spec_old = 1e6 * np.dot(spec_table[:, separation_age:],
sfh[:-separation_age][::-1])
return spec_young, spec_old, info_young, info_old
......@@ -74,16 +74,8 @@ class BC03(SedModule):
SED object.
"""
# First, we process the young population (age lower than the
# separation age.)
spec_young, info_young = self.ssp.convolve(
sed.sfh[-self.separation_age:])
# Then, we process the old population. If the SFH is shorter than the
# separation age then all the arrays will consist only of 0.
old_sfh = np.copy(sed.sfh)
old_sfh[-self.separation_age:] = 0.
spec_old, info_old = self.ssp.convolve(old_sfh)
spec_young, spec_old, info_young, info_old = self.ssp.convolve(sed.sfh,
self.separation_age)
# We compute the Lyman continuum luminosity as it is important to
# compute the energy absorbed by the dust before ionising gas.
......
......@@ -72,16 +72,8 @@ class M2005(SedModule):
SED object.
"""
# First, we process the young population (age lower than the
# separation age.)
info_young, spec_young = self.ssp.convolve(
sed.sfh[-self.separation_age:])
# Then, we process the old population. If the SFH is shorter than the
# separation age then all the arrays will consist only of 0.
old_sfh = np.copy(sed.sfh)
old_sfh[-self.separation_age:] = 0.
info_old, spec_old = self.ssp.convolve(old_sfh)
spec_young, spec_old, info_young, info_old = self.ssp.convolve(sed.sfh,
self.separation_age)
sed.add_module(self.name, self.parameters)
......@@ -89,24 +81,24 @@ class M2005(SedModule):
sed.add_info('stellar.metallicity', self.metallicity)
sed.add_info('stellar.old_young_separation_age', self.separation_age)
sed.add_info('stellar.mass_total_old', info_old[0], True)
sed.add_info('stellar.mass_alive_old', info_old[1], True)
sed.add_info('stellar.mass_white_dwarf_old', info_old[2], True)
sed.add_info('stellar.mass_neutron_old', info_old[3], True)
sed.add_info('stellar.mass_black_hole_old', info_old[4], True)
sed.add_info('stellar.mass_total_young', info_young[0], True)
sed.add_info('stellar.mass_alive_young', info_young[1], True)
sed.add_info('stellar.mass_white_dwarf_young', info_young[2], True)
sed.add_info('stellar.mass_neutron_young', info_young[3], True)
sed.add_info('stellar.mass_black_hole_young', info_young[4], True)
sed.add_info('stellar.mass_total', info_old[0] + info_young[0], True)
sed.add_info('stellar.mass_alive', info_old[1] + info_young[1], True)
sed.add_info('stellar.mass_white_dwarf', info_old[2] + info_young[2],
sed.add_info('stellar.mass_total_old', info_old[0], True)
sed.add_info('stellar.mass_alive_old', info_old[1], True)
sed.add_info('stellar.mass_white_dwarf_old', info_old[2], True)
sed.add_info('stellar.mass_neutron_old', info_old[3], True)
sed.add_info('stellar.mass_black_hole_old', info_old[4], True)
sed.add_info('stellar.mass_total', info_young[0] + info_old[0], True)
sed.add_info('stellar.mass_alive', info_young[1] + info_old[1], True)
sed.add_info('stellar.mass_white_dwarf', info_young[2] + info_old[2],
True)
sed.add_info('stellar.mass_neutron', info_old[3] + info_young[3], True)
sed.add_info('stellar.mass_black_hole', info_old[4] + info_young[4],
sed.add_info('stellar.mass_neutron', info_young[3] + info_old[3], True)
sed.add_info('stellar.mass_black_hole', info_young[4] + info_old[4],
True)
sed.add_contribution("stellar.old", self.ssp.wavelength_grid, spec_old)
......
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