sfh2exp.py 3.75 KB
Newer Older
1
# -*- coding: utf-8 -*-
2
3
4
# Copyright (C) 2013 Centre de données Astrophysiques de Marseille
# Licensed under the CeCILL-v2 licence - see Licence_CeCILL_V2-en.txt
# Author: Yannick Roehlly <yannick.roehlly@oamp.fr>
5
6

import numpy as np
7
from collections import OrderedDict
8
9
from . import common

Yannick Roehlly's avatar
Yannick Roehlly committed
10
# Time lapse used in the age grid in Myr. If should be consistent with the
11
# time lapse in the SSP modules.
Yannick Roehlly's avatar
Yannick Roehlly committed
12
AGE_LAPSE = 1
13
14
15
16
17
18
19
20
21
22
23


class Module(common.SEDCreationModule):
    """Create a double decreasing exponential Star Formation History

    This module create a star formation history (star formation rate vs galaxy
    age) composed of two exp(-t/τ). The SFH is added to the info dictionary of
    the SED as a tuple (age, SFR).

    """

24
25
    parameter_list = OrderedDict([
        ("tau_main", (
26
            "float",
Yannick Roehlly's avatar
Yannick Roehlly committed
27
            "e-folding time of the main stellar population model in Myr.",
28
            None
29
30
        )),
        ("tau_burst", (
31
            "float",
Yannick Roehlly's avatar
Yannick Roehlly committed
32
            "e-folding time of the late starburst population model in Myr.",
33
            None
34
35
        )),
        ("f_burst", (
36
37
38
            "float",
            "Mass fraction of the late burst population.",
            None
39
40
        )),
        ("age", (
41
            "integer",
Yannick Roehlly's avatar
Yannick Roehlly committed
42
            "Age of the oldest stars in the galaxy in Myr. The precision "
43
44
            "is 1 Myr.",
            None
45
46
        )),
        ("burst_age", (
47
            "integer",
Yannick Roehlly's avatar
Yannick Roehlly committed
48
            "Age of the late burst in Myr. Precision is 1 Myr.",
49
            None
50
51
        ))
    ])
52

53
54
55
56
57
58
59
60
61
    out_parameter_list = OrderedDict([
        ("tau_main", "e-folding time of the main stellar population model "
                     "in Myr."),
        ("tau_burst", "e-folding time of the late starburst population model "
                      "in Myr."),
        ("f_burst", "Produced mass fraction of the late burst population."),
        ("age", "Age of the oldest stars in the galaxy in Myr."),
        ("burst_age", "Age of the late burst in Myr.")
    ])
62

63
    def process(self, sed):
64
65
66
67
68
69
70
71
        """Add a double decreasing exponential Star Formation History.

        Parameters
        ----------
        sed : pcigale.sed.SED object

        """

72
73
74
75
76
        tau_main = float(self.parameters["tau_main"])
        tau_burst = float(self.parameters["tau_burst"])
        f_burst = float(self.parameters["f_burst"])
        age = int(self.parameters["age"])
        burst_age = int(self.parameters["burst_age"])
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99

        # 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)

        # Main exponential
        sfr = np.exp(-time_grid / tau_main)

        # Height of the late burst to have the desired produced mass fraction
        # (assuming that the main burst as a height of 1).
        burst_height = (
            f_burst * tau_main * (1 - np.exp(-age / tau_main))
            / (
                (1 - f_burst) * tau_burst * np.exp(-burst_age / tau_burst)
            ))

        # We add the age burst exponential for ages superior to age -
        # burst_age
        mask = (time_grid >= (age - burst_age))
        sfr[mask] = sfr[mask] + burst_height * np.exp(
            (-time_grid[mask] + age - burst_age) / tau_burst)

        # We normalise the SFH to have one solar mass produced.
Yannick Roehlly's avatar
Yannick Roehlly committed
100
        sfr = sfr / np.trapz(sfr * 1.e6, time_grid)
101

102
        sed.add_module(self.name, self.parameters)
103

104
        # Add the sfh and the output parameters to the SED.
Yannick Roehlly's avatar
Yannick Roehlly committed
105
        sed.sfh = (time_grid, sfr)
106
107
108
109
110
        sed.add_info("sfh_tau_main" + self.postfix, tau_main)
        sed.add_info("sfh_tau_burst" + self.postfix, tau_burst)
        sed.add_info("sfh_f_burst" + self.postfix, f_burst)
        sed.add_info("sfh_age" + self.postfix, age)
        sed.add_info("sfh_burst_age" + self.postfix, burst_age)