Commit 6fab230a authored by Médéric Boquien's avatar Médéric Boquien

Homogenise the bc03 and m2005 data modules so they use the same variable names...

Homogenise the bc03 and m2005 data modules so they use the same variable names as far as possible. Comments have also been corrected and made consistent.
parent fe504475
......@@ -10,13 +10,18 @@ class BC03(object):
"""Single Stellar Population as defined in Bruzual and Charlot (2003)
This class holds the data associated with a single stellar population
(SSP) as defined in Bruzual and Charlot (2003). Compare to the pristine
SSP, the wavelength are given in nm (rather than Å), the time is given in
(SSP) as defined in Bruzual and Charlot (2003). Compared to the pristine
Bruzual and Charlot SSP:
* The time grid ranges from 1 Myr to 14 Gyr with 1 Myr steps.
* The SSP are all interpolated on this new grid.
* The wavelength grid is refined beyond 10 μm to avoid artefacts.
* The wavelength is given in nm rather than Å.
* The spectra are given in W/nm rather than Lsun.
"""
def __init__(self, imf, metallicity, time_grid, wavelength_grid,
color_table, lumin_table):
info_table, spec_table):
"""Create a new single stellar population as defined in Bruzual and
Charlot (2003).
......@@ -27,27 +32,27 @@ class BC03(object):
'chab' for Chabrier (2003).
metallicity: float
The metallicity. Possible values are 0.0001, 0.0004, 0.004, 0.008,
0.02 (solar metallicity) and 0.05.
0.02, and 0.05.
time_grid: array of floats
The time [Myr] grid used in the colors_table and the lumin_table.
The time grid in Myr used in the info_table and the spec_table.
wavelength_grid: array of floats
The wavelength [nm] grid used in the lumin_table.
color_table: 2 axis array of floats
The wavelength grid in nm used in spec_table.
info_table: 2 axis array of floats
Array containing information from some of the *.?color tables from
Bruzual and Charlot (2003) at each time of the time_grid.
* color_table[0]: Total mass in stars in solar mass
* color_table[1]: Mass returned to the ISM by evolved stars
in solar mass
* color_table[2]: rate of H-ionizing photons (s-1)
* color_table[3]: Amplitude of 4000 Å break (Bruzual 2003)
* color_table[4]: Amplitude of 4000 Å narrow break (Balogh
* info_table[0]: Total mass in stars in solar mass
* info_table[1]: Mass returned to the ISM by evolved stars in
solar mass
* info_table[2]: rate of H-ionizing photons (s-1)
* info_table[3]: Amplitude of 4000 Å break (Bruzual 2003)
* info_table[4]: Amplitude of 4000 Å narrow break (Balogh
et al. 1999)
* color_table[5]: Amplitude of 4000 Å break (Stoughton
* info_table[5]: Amplitude of 4000 Å break (Stoughton
et al. 2002)
* color_table[6]: Amplitude of Lyman discontinuity
lumin_table: 2 axis array of floats
Luminosity density in W/nm. The first axis is the wavelength and
the second the time (index bases on the wavelength and time grids).
* cinfo_table[6]: Amplitude of Lyman discontinuity
spec_table: 2D array of floats
Spectrum of the SSP in W/nm (first axis) every 1 Myr (second axis).
"""
if imf in ['salp', 'chab']:
......@@ -58,13 +63,13 @@ class BC03(object):
self.metallicity = metallicity
self.time_grid = time_grid
self.wavelength_grid = wavelength_grid
self.color_table = color_table
self.lumin_table = lumin_table
self.info_table = info_table
self.spec_table = spec_table
def convolve(self, sfh):
"""Convolve the SSP with a Star Formation History
Given an SFH, this method convolves the color table and the SSP
Given an SFH, this method convolves the info table and the SSP
luminosity spectrum.
Parameters
......@@ -74,35 +79,32 @@ class BC03(object):
Returns
-------
wavelength: array of floats
Wavelength grid [nm] for the spectrum
luminosity: array of floats
Luminosity density [W/nm] at each wavelength.
bc03_info: dictionary
spec: array of floats
Spectrum in [W/nm].
info: dictionary
Dictionary containing various information from the *.?color tables:
- "m_star": Total mass in stars in solar mass
- "m_gas": Mass returned to the ISM by evolved stars
in solar mass
- "n_ly": rate of H-ionizing photons (s-1)
- "b_4000": Amplitude of 4000 Å break (Bruzual 2003)
- "b4_vn": Amplitude of 4000 Å narrow break (Balogh et al. 1999)
- "b4_sdss": Amplitude of 4000 Å break (Stoughton et al. 2002)
- "b_912": Amplitude of Lyman discontinuity
* "m_star": Total mass in stars in Msun
* "m_gas": Mass returned to the ISM by evolved stars in Msun
* "n_ly": rate of H-ionizing photons (s-1)
* "b_4000": Amplitude of 4000 Å break (Bruzual 2003)
* "b4_vn": Amplitude of 4000 Å narrow break (Balogh et al. 1999)
* "b4_sdss": Amplitude of 4000 Å break (Stoughton et al. 2002)
* "b_912": Amplitude of Lyman break
"""
# 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.
color_table = self.color_table[:, :sfh.size]
lumin_table = self.lumin_table[:, :sfh.size]
info_table = self.info_table[:, :sfh.size]
spec_table = self.spec_table[:, :sfh.size]
# The 1.e6 factor is because the SFH is in solar mass per year.
color_info = 1.e6 * np.dot(color_table, sfh[::-1])
luminosity = 1.e6 * np.dot(lumin_table, sfh[::-1])
# 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])
bc03_info = dict(zip(
info = dict(zip(
["m_star", "m_gas", "n_ly", "b_4000", "b4_vn", "b4_sdss", "b_912"],
color_info
info
))
return self.wavelength_grid, luminosity, bc03_info
return self.wavelength_grid, spec, info
......@@ -10,24 +10,19 @@ class M2005(object):
"""Single Stellar Population as defined in Maraston (2005)
This class holds the data associated with a single stellar population
(SSP) as defined in Maraston (2005). Compare to the pristine Maraston's
(SSP) as defined in Maraston (2005). Compared to the pristine Maraston's
SSP:
- The time grid used ranges from 1 My to 13.7 Gyr with 1 My step. This
excludes the metallicities -2.25 and 0.67 for which the pristine age
grid starts at 1 Gyr.
- The stellar masses and the luminosities ( luminosity vs age for a given
wavelength) were all interpolated to this new grid.
- The wavelength are given in nm rather than in Å.
- The luminosities are given in W rather than erg/s.
* The time grid ranges from 1 Myr to 13.7 Gyr with 1 Myr steps. This
excludes the metallicities -2.25 and 0.67 for which the age grid starts
at 1 Gyr.
* The SSP are all interpolated on this new grid.
* The wavelength is given in nm rather than Å.
* The spectra are given in W/nm rather than erg/s.
"""
def __init__(self, imf, metallicity, time_grid, wavelength_grid,
mass_table, spec_table):
info_table, spec_table):
"""Create a new single stellar population as defined in Maraston 2005.
Parameters
......@@ -36,45 +31,41 @@ class M2005(object):
Initial mass function (IMF): either 'salp' for single Salpeter
(1955) or 'krou' for Kroupa (2001).
metallicity: float
The metallicity. Possible values are 0.001, 0.01, 0.02 (solar
metallicity) and 0.04.
The metallicity. Possible values are 0.001, 0.01, 0.02, and 0.04.
time_grid: array of floats
The time [Myr] grid used in the mass_table and the spec_table.
The time grid in Myr used in the info_table and the spec_table.
wavelength_grid: array of floats
The wavelength [nm] grid used in the spec_table.
mass_table: (6, n) array of floats
The wavelength grid in nm used in spec_table.
info_table: (6, n) array of floats
The 2D table giving the various masses at a given age. The
first axis is the king of mass, the second is the age based on the
time_grid.
* mass_table[0]: total mass
* mass_table[1]: alive stellar mass
* mass_table[2]: white dwarf stars mass
* mass_table[3]: neutron stars mass
* mass_table[4]: black holes mass
* mass_table[5]: turn-off mass
spec_table: (2, n) array of floats
The 2D table giving the luminosity density [W/nm] at various time.
The first axis is the age, base on the time_grid, the second is the
wavelength, base on the wavelength_grid.
* info_table[0]: total mass
* info_table[1]: alive stellar mass
* info_table[2]: white dwarf stars mass
* info_table[3]: neutron stars mass
* info_table[4]: black holes mass
* info_table[5]: turn-off mass
spec_table: 2D array of floats
Spectrum of the SSP in W/nm (first axis) every 1 Myr (second axis).
"""
if imf in ['salp', 'krou']:
self.imf = imf
else:
raise ValueError('IMF must be either salp for Salpeter or '
'krou for Krupa.')
raise ValueError("IMF must be either salp for Salpeter or krou for "
"Kroupa.")
self.metallicity = metallicity
self.time_grid = time_grid
self.wavelength_grid = wavelength_grid
self.mass_table = mass_table
self.info_table = info_table
self.spec_table = spec_table
def convolve(self, sfh):
"""Convolve the SSP with a Star Formation History
Given an SFH, this method convolves the masses and the spectra of the
SSPs.
Convolves the SSP and the associated info with the SFH.
Parameters
----------
......@@ -83,29 +74,26 @@ class M2005(object):
Returns
-------
masses, spectra: array of floats, array of floats
masses is an array of floats or and array of arrays of floats (the
second axe is then the age):
- masses[0]: total stellar mass
- masses[1]: alive stellar mass
- masses[2]: white dwarf stars mass
- masses[3]: neutron stars mass
- masses[4]: black holes mass
- masses[5]: turn-off mass
spectra holds:
- spectra[0]: wavelengths in nm
- spectra[1]: luminosity in W/nm
spec: array of floats
Spectrum in [W/nm].
info: array of floats containing:
* info[0]: total stellar mass
* info[1]: alive stellar mass
* info[2]: white dwarf stars mass
* info[3]: neutron stars mass
* info[4]: black holes mass
* 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.
mass_table = self.mass_table[:, :sfh.size]
info_table = self.info_table[:, :sfh.size]
spec_table = self.spec_table[:, :sfh.size]
# The 1.e6 factor is because the SFH is in solar mass per year.
masses = 1.e6 * np.dot(mass_table, sfh[::-1])
spectra = 1.e6 * np.dot(spec_table, sfh[::-1])
# 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 masses, spectra
return info, spec
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