Commit 0ec98253 authored by Médéric Boquien's avatar Médéric Boquien

Implement a priodic SFH module in replacement of the sfhcomb_constant and...

Implement a priodic SFH module in replacement of the sfhcomb_constant and sfhcomb_delayed modules. The new module handles rectangular, delayed, and exponential star-forming episodes.
parent 6d2cc094
# -*- coding: utf-8 -*-
# Copyright (C) 2013 Centre de données Astrophysiques de Marseille
# Licensed under the CeCILL-v2 licence - see Licence_CeCILL_V2-en.txt
# Author: Denis Burgarella
"""
SFH resembling a Dirac Comb formed by several regularly-spaced short constant SF events.
========================================================================================
This module implements a star formation history (SFH) formed by several
regularly-spaced short constant SF events.
"""
from collections import OrderedDict
import numpy as np
from . import CreationModule
# Time lapse used in the age grid in Myr. If should be consistent with the
# time lapse in the SSP modules.
AGE_LAPSE = 1
class SfhComb(CreationModule):
"""Several regularly-spaced short constant SF events
This module sets the SED star formation history (SFH) as a combination of
several regularly-spaced short constant SF events.
"""
parameter_list = OrderedDict([
("N_events", (
"integer",
"Number of individual star formation events. ",
5
)),
("t_duration", (
"integer",
"Length of each individual star formation event [Myr]. "
"Warning: if too long => continuous SFH",
20
)),
("age", (
"integer",
"Age of the main stellar population in the galaxy in Myr."
"The precision is 1 Myr.",
1000
)),
("age_last", (
"integer",
"Time since the end of the last SF event [Myr]. "
"Warning: Depending on the parameters, the last burst might not be finished. "
"The precision is 1 Myr.",
100
)),
("sfr_A", (
"float",
"Strength of each SF event in M_sun/yr (useful if not normalised)",
1.
)),
("normalise", (
"boolean",
"Normalise the SFH to produce one solar mass.",
"True"
)),
])
def process(self, sed):
"""Add a star formation history formed by several regularly-spaced short SF events.
** Parameters **
sed: pcigale.sed.SED object
"""
N_events = int(self.parameters["N_events"])
t_duration = int(self.parameters["t_duration"])
age = int(self.parameters["age"])
age_last = int(self.parameters["age_last"])
sfr_A = int(self.parameters["sfr_A"])
normalise = (self.parameters["normalise"].lower() == "true")
# Time grid and age. If needed, the age is rounded to the inferior Myr
time_grid = np.arange(AGE_LAPSE, age + AGE_LAPSE, AGE_LAPSE)
age = np.max(time_grid)
sfr = np.zeros(len(time_grid))
# Build the Dirac comb of events.
# Ages of the sequence of SF events in Myr,
# N_events over "age" with the last one starting at "age_last"
time_event = np.linspace(0., age-age_last, num = N_events)
for i_time in range(N_events):
sfr[time_event[i_time]:time_event[i_time]+t_duration] = sfr_A
# Compute the galaxy mass and normalise the SFH to 1 solar mass
# produced if asked to.
galaxy_mass = np.trapz(sfr, time_grid) * 1e6
if normalise:
sfr = sfr / galaxy_mass
galaxy_mass = 1.
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.N_events", N_events)
sed.add_info("sfh.t_duration", t_duration)
sed.add_info("sfh.age_last", age_last)
sed.add_info("sfh.age", age)
# CreationModule to be returned by get_module
Module = SfhComb
# -*- coding: utf-8 -*-
# Copyright (C) 2013 Centre de données Astrophysiques de Marseille
# Copyright (C) 2015 Centre de données Astrophysiques de Marseille
# Copyright (C) 2015 Institute of Astronomy
# Copyright (C) 2015 Universidad de Antofagasta
# Licensed under the CeCILL-v2 licence - see Licence_CeCILL_V2-en.txt
# Author: Denis Burgarella
# Author: Denis Burgarella & Médéric Boquien
"""
SFH resembling a Dirac Comb with regularly-spaced delayed-SFH events
=====================================================================
Periodic SFH in the form of rectangles, and decaying or delayed exponentials
============================================================================
This module implements a star formation history (SFH) formed by several
regularly-spaced short regularly-spaced delayed-SFH SF events.
# This module implements a periodic star formation history (SFH) formed by
regularly-spaced star formation events. Each even can either be rectangular, a
decaying exponential, or "delayed".
"""
......@@ -16,12 +18,8 @@ from collections import OrderedDict
import numpy as np
from . import CreationModule
# Time lapse used in the age grid in Myr. If should be consistent with the
# time lapse in the SSP modules.
AGE_LAPSE = 1
class SfhComb(CreationModule):
class SfhPeriodic(CreationModule):
"""Several regularly-spaced short delayed-SFH SF events
This module sets the SED star formation history (SFH) as a combination of
......@@ -30,32 +28,34 @@ class SfhComb(CreationModule):
"""
parameter_list = OrderedDict([
("N_events", (
("type_bursts", (
"integer",
"Number of individual star formation events. ",
5
"Type of the individual star formation episodes. 0: exponential, "
"1: delayed, 2: rectangle.",
0
)),
("tau_events", (
"float",
"e-folding time of all short events in Myr.",
20.
("delta_bursts", (
"integer",
"Elapsed time between the beginning of each burst in Myr. The "
"precision is 1 Myr.",
50
)),
("age", (
("tau_bursts", (
"integer",
"Age of the main stellar population in the galaxy in Myr."
"The precision is 1 Myr.",
1000
"Duration (rectangle) or e-folding time of all short events in "
"Myr. The precision is 1 Myr.",
20
)),
("age_last", (
("age", (
"integer",
"Time since the end of the last SF event [Myr]. "
"Warning: Depending on the parameters, the last burst might not be finished. "
"The precision is 1 Myr.",
100
"Age of the main stellar population in the galaxy in Myr. The "
"precision is 1 Myr.",
1000
)),
("sfr_A", (
"float",
"Multiplicative factor controlling the amplitude of SFR (valid for each event).",
"Multiplicative factor controlling the amplitude of SFR (valid "
"for each event).",
1.
)),
("normalise", (
......@@ -65,54 +65,60 @@ class SfhComb(CreationModule):
)),
])
def process(self, sed):
"""Add a star formation history formed by several
regularly-spaced delayed-SFH short SF events.
** Parameters **
sed: pcigale.sed.SED object
"""
N_events = int(self.parameters["N_events"])
tau_events = float(self.parameters["tau_events"])
def _init_code(self):
self.type_bursts = int(self.parameters["type_bursts"])
self.delta_bursts = int(self.parameters["delta_bursts"])
self.tau_bursts = int(self.parameters["tau_bursts"])
age = int(self.parameters["age"])
age_last = int(self.parameters["age_last"])
sfr_A = int(self.parameters["sfr_A"])
sfr_A = float(self.parameters["sfr_A"])
normalise = (self.parameters["normalise"].lower() == "true")
# Time grid and age. If needed, the age is rounded to the inferior Myr
time_grid = np.arange(AGE_LAPSE, age + AGE_LAPSE, AGE_LAPSE)
age = np.max(time_grid)
sfr = np.zeros(len(time_grid))
# Build the Dirac comb of events.
# Ages of the sequence of SF events in Myr,
# N_events over "age" with the last one starting at "age_last"
time_event = np.linspace(0., age-age_last, num = N_events)
# Add each delayed SFH
for i_time in range(N_events):
sfr[time_event[i_time]:] = \
sfr_A * (time_grid[time_event[i_time]:]-time_event[i_time]) / tau_events**2 * \
np.exp(-(time_grid[time_event[i_time]:]-time_event[i_time]) / tau_events)
self.time_grid = np.arange(0, age)
self.sfr = np.zeros_like(self.time_grid, dtype=np.float)
if self.type_bursts == 0:
burst = np.exp(-self.time_grid/self.tau_bursts)
elif self.type_bursts == 1:
burst = np.exp(-self.time_grid/self.tau_bursts) * \
self.time_grid/self.tau_bursts**2
elif self.type_bursts == 2:
burst = np.zeros_like(self.time_grid)
burst[:self.tau_bursts+1] = 1.
else:
raise Exception("Burst type {} unknown.".format(self.type_bursts))
for t_burst in np.arange(0, age, self.delta_bursts):
self.sfr += burst
burst = np.roll(burst, self.delta_bursts)
burst[:self.delta_bursts] = 0.
# Compute the galaxy mass and normalise the SFH to 1 solar mass
# produced if asked to.
galaxy_mass = np.trapz(sfr, time_grid) * 1e6
self.galaxy_mass = np.trapz(self.sfr, self.time_grid) * 1e6
if normalise:
sfr = sfr / galaxy_mass
galaxy_mass = 1.
self.sfr = self.sfr / self.galaxy_mass
self.galaxy_mass = 1.
else:
self.sfr *= sfr_A
self.galaxy_mass *= sfr_A
def process(self, sed):
"""Add a star formation history formed by several regularly-spaced SF
events.
** 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.N_events", N_events)
sed.add_info("sfh.tau_events", tau_events)
sed.add_info("sfh.age_last", age_last)
sed.add_info("sfh.age", age)
sed.sfh = (self.time_grid, self.sfr)
sed.add_info("galaxy_mass", self.galaxy_mass, True)
sed.add_info("sfh.type_bursts", self.type_bursts)
sed.add_info("sfh.delta_bursts", self.delta_bursts)
sed.add_info("sfh.tau_bursts", self.tau_bursts)
# CreationModule to be returned by get_module
Module = SfhComb
Module = SfhPeriodic
......@@ -128,7 +128,7 @@ class Configuration(object):
self.config['creation_modules'] = []
self.config.comments['creation_modules'] = [""] + wrap(
"Order of the modules use for SED creation. Available modules: "
"SFH: sfh2exp, sfhdelayed, sfhfromfile ; "
"SFH: sfh2exp, sfhdelayed, sfhfromfile, sfhperiodic ; "
"SSP: bc03, m2005 ; "
"Nebular: nebular ; "
"Attenuation: dustatt_calzleit, dustatt_powerlaw ; "
......
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