Commit 9d825558 authored by Médéric Boquien's avatar Médéric Boquien

For convenience the time grids start at 0. Howver the SSP grids start at 1....

For convenience the time grids start at 0. Howver the SSP grids start at 1. This  offset means that the oldest bin in an SFH is set to 0, for both the young and old components. Now rather than trying to interpolate the SFH time grid on the SSP time grid, we rely on the fact that the SFH time grid starts from 0, so it is easy to know which SSP to select (as many as the number of steps). Also adapt the sfh_buat08 module.
parent 30ce18c0
......@@ -69,14 +69,13 @@ class BC03(object):
spectrum along the whole SFR.
The time grid of the SFH is expected to be ordered and must not run
beyong 20 Gyr (the maximum time for Bruzual and Charlot 2003 SSP).
beyong 14 Gyr (the maximum time in the database).
Parameters
----------
sfh_time: array of floats
Time grid [Myr] of the star formation history. It must be
increasing and not run beyond 20 Gyr. The SFH will be regrided to
the SSP time.
Time grid [Myr] of the star formation history. It must start at 0
and not run beyond 14 Gyr, with a step of 1 Myr.
sfh_sfr: array of floats
Star Formation Rates in Msun/yr at each time of the SFH time grid.
......@@ -98,33 +97,20 @@ class BC03(object):
- "b_912": Amplitude of Lyman discontinuity
"""
# We work on a copy of SFH (as we change it)
sfh_time, sfh_sfr = np.copy((sfh_time, sfh_sfr))
# Index, in the SSP time grid, of the time nearest to the age of
# the SFH.
idx = np.abs(self.time_grid - np.max(sfh_time)).argmin()
# We regrid the SFH to the time grid of the SSP using a linear
# interpolation. If the SFH does no start at 0, the first SFR values
# will be set to 0.
sfh_sfr = np.interp(self.time_grid[:idx + 1],
sfh_time, sfh_sfr,
left=0., right=0.)
# Step between two item in the time grid in Myr
step = self.time_grid[1] - self.time_grid[0]
# 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.
color_table = self.color_table[:, :idx + 1]
lumin_table = self.lumin_table[:, :idx + 1]
# The 1.e6 * step is because the SFH is in solar mass per year.
color_info = 1.e6 * step * np.dot(color_table, sfh_sfr[::-1])
luminosity = 1.e6 * step * np.dot(lumin_table, sfh_sfr[::-1])
# We make sure the time grid starts from 0. Otherwise the selection of
# the SSP will be wrong.
if sfh_time[0] != 0:
raise Exception("Age grid must start from 0. Exiting.")
# 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_time[-1] + 1]
lumin_table = self.lumin_table[:, :sfh_time[-1] + 1]
# The 1.e6 factor is because the SFH is in solar mass per year.
color_info = 1.e6 * np.dot(color_table, sfh_sfr[::-1])
luminosity = 1.e6 * np.dot(lumin_table, sfh_sfr[::-1])
bc03_info = dict(zip(
["m_star", "m_gas", "n_ly", "b_4000", "b4_vn", "b4_sdss", "b_912"],
......
......@@ -83,10 +83,8 @@ class M2005(object):
Parameters
----------
sfh_time: array of floats
Time grid [Myr)] of the star formation history. It must be
increasing and not run beyond 13.7 Gyr. As the SFH will be
regrided to the SSP time grid, it is better to have a SFH age grid
compatible, i.e. with a precision limited to 1 Myr.
Time grid [Myr)] of the star formation history. It must start at 0
and not run beyond 13.7 Gyr, with a step of 1 Myr.
sfh_sfr: array of floats
Star Formation Rates in Msun/yr at each time of the SFH time grid.
......@@ -106,30 +104,20 @@ class M2005(object):
- spectra[1]: luminosity in W/nm
"""
# We work on a copy of SFH (as we change it)
sfh_time, sfh_sfr = np.copy((sfh_time, sfh_sfr))
# Step between two item in the time grid in Myr
step = self.time_grid[1] - self.time_grid[0]
# Number of step to go to the age of the SFH on the SSP age grid.
nb_steps = 1 + np.round((np.max(sfh_time) - self.time_grid[0]) / step)
# We regrid the SFH to the time grid of the SSP using a linear
# interpolation. If the SFH does no start at 0, the first SFR values
# will be set to 0.
sfh_sfr = np.interp(self.time_grid[:nb_steps],
sfh_time, sfh_sfr,
left=0., right=0.)
# We make sure the time grid starts from 0. Otherwise the selection of
# the SSP will be wrong.
if sfh_time[0] != 0:
raise Exception("Age grid must start from 0. Exiting.")
# 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[:, :nb_steps]
spec_table = self.spec_table[:, :nb_steps]
mass_table = self.mass_table[:, :sfh_time[-1] + 1]
spec_table = self.spec_table[:, :sfh_time[-1] + 1]
# The 1.e6 * step is because the SFH is in solar mass per year.
masses = 1.e6 * step * np.dot(mass_table, sfh_sfr[::-1])
spectra = 1.e6 * step * np.dot(spec_table, sfh_sfr[::-1])
# The 1.e6 factor is because the SFH is in solar mass per year.
masses = 1.e6 * np.dot(mass_table, sfh_sfr[::-1])
spectra = 1.e6 * np.dot(spec_table, sfh_sfr[::-1])
return masses, spectra
......@@ -63,7 +63,7 @@ class SfhBuat08(SedModule):
normalise = bool(self.parameters["normalise"])
# Time grid and age. If needed, the age is rounded to the inferior Myr
self.time_grid = np.arange(1, self.age + 1)
self.time_grid = np.arange(self.age)
# Values from Buat et al. (2008) table 2
paper_velocities = np.array([80., 150., 220., 290., 360.])
......
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