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

Add an _init_code() to sfh2exp to avoid repeating twice the same operations....

Add an _init_code() to sfh2exp to avoid repeating twice the same operations. Even though that should not be a common occurrence, it is cleaner by separating the computation of the data and the actual processing of the SED object.
parent 586de99a
......@@ -66,56 +66,58 @@ class Sfh2Exp(CreationModule):
)),
])
def process(self, sed):
"""Add a double decreasing exponential Star Formation History.
Parameters
----------
sed: pcigale.sed.SED object
"""
tau_main = float(self.parameters["tau_main"])
tau_burst = float(self.parameters["tau_burst"])
f_burst = float(self.parameters["f_burst"])
def _init_code(self):
self.tau_main = float(self.parameters["tau_main"])
self.tau_burst = float(self.parameters["tau_burst"])
self.f_burst = float(self.parameters["f_burst"])
self.burst_age = int(self.parameters["burst_age"])
age = int(self.parameters["age"])
burst_age = int(self.parameters["burst_age"])
sfr_0 = int(self.parameters["sfr_0"])
normalise = (self.parameters["normalise"].lower() == "true")
# Time grid and age. If needed, the age is rounded to the inferior Myr
time_grid = np.arange(1, age + 1)
time_grid_burst = np.arange(1, burst_age + 1)
self.time_grid = np.arange(1, age + 1)
time_grid_burst = np.arange(1, self.burst_age + 1)
# SFR for each component
sfr = np.exp(-time_grid / tau_main)
sfr_burst = np.exp(-time_grid_burst / tau_burst)
self.sfr = np.exp(-self.time_grid / self.tau_main)
sfr_burst = np.exp(-time_grid_burst / self.tau_burst)
# Height of the late burst to have the desired produced mass fraction
sfr_burst *= f_burst / (1.-f_burst) * np.sum(sfr) / np.sum(sfr_burst)
sfr_burst *= self.f_burst / (1.-self.f_burst) * np.sum(self.sfr) / np.sum(sfr_burst)
# We add the age burst exponential for ages superior to age -
# burst_age
sfr[-time_grid_burst[-1]:] += sfr_burst
self.sfr[-time_grid_burst[-1]:] += sfr_burst
# Compute the galaxy mass and normalise the SFH to 1 solar mass
# produced if asked to.
galaxy_mass = np.sum(sfr) * 1e6
self.galaxy_mass = np.sum(self.sfr) * 1e6
if normalise:
sfr /= galaxy_mass
galaxy_mass = 1.
self.sfr /= self.galaxy_mass
self.galaxy_mass = 1.
else:
sfr *= sfr_0
galaxy_mass *= sfr_0
self.sfr *= sfr_0
self.galaxy_mass *= sfr_0
def process(self, sed):
"""Add a double decreasing exponential Star Formation History.
Parameters
----------
sed: pcigale.sed.SED object
"""
sed.add_module(self.name, self.parameters)
# Add the sfh and the output parameters to the SED.
sed.sfh = (time_grid, sfr)
sed.add_info("galaxy_mass", galaxy_mass, True)
sed.add_info("sfh.tau_main", tau_main)
sed.add_info("sfh.tau_burst", tau_burst)
sed.add_info("sfh.f_burst", f_burst)
sed.add_info("sfh.burst_age", burst_age)
sed.sfh = (self.time_grid, self.sfr)
sed.add_info("galaxy_mass", self.galaxy_mass, True)
sed.add_info("sfh.tau_main", self.tau_main)
sed.add_info("sfh.tau_burst", self.tau_burst)
sed.add_info("sfh.f_burst", self.f_burst)
sed.add_info("sfh.burst_age", self.burst_age)
# CreationModule to be returned by get_module
Module = Sfh2Exp
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