sfh2exp.py 3.6 KB
Newer Older
1
# -*- coding: utf-8 -*-
2
3
# Copyright (C) 2013 Centre de données Astrophysiques de Marseille
# Licensed under the CeCILL-v2 licence - see Licence_CeCILL_V2-en.txt
Yannick Roehlly's avatar
Yannick Roehlly committed
4
# Author: Yannick Roehlly
5

Yannick Roehlly's avatar
Yannick Roehlly committed
6
7
8
9
10
11
12
13
14
"""
Double decreasing exponential star formation history module
===========================================================

This module implements a star formation history (SFH) composed of two
decreasing exponentials.

"""

15
from collections import OrderedDict
16

17
import numpy as np
18

19
from . import CreationModule
20

21

Yannick Roehlly's avatar
Yannick Roehlly committed
22
class Sfh2Exp(CreationModule):
Yannick Roehlly's avatar
Yannick Roehlly committed
23
    """Double decreasing exponential Star Formation History
24

Yannick Roehlly's avatar
Yannick Roehlly committed
25
26
    This module sets the SED star formation history (SFH) as a combination of
    two exp(-t/τ) exponentials.
27
28
29

    """

30
    parameter_list = OrderedDict([
31
        ("tau_main", (
32
            "float",
Yannick Roehlly's avatar
Yannick Roehlly committed
33
            "e-folding time of the main stellar population model in Myr.",
34
            6000.
35
36
        )),
        ("tau_burst", (
37
            "float",
Yannick Roehlly's avatar
Yannick Roehlly committed
38
            "e-folding time of the late starburst population model in Myr.",
39
            50.
40
41
        )),
        ("f_burst", (
42
43
            "float",
            "Mass fraction of the late burst population.",
44
            0.01
45
46
        )),
        ("age", (
47
            "integer",
48
49
50
            "Age of the main stellar population in the galaxy in Myr."
            "The precision is 1 Myr.",
            5000.
51
52
        )),
        ("burst_age", (
53
            "integer",
Yannick Roehlly's avatar
Yannick Roehlly committed
54
            "Age of the late burst in Myr. Precision is 1 Myr.",
55
            20.
Denis's avatar
Denis committed
56
        )),
Médéric Boquien's avatar
Médéric Boquien committed
57
        ("sfr_0", (
58
            "float",
59
            "Value of SFR at t = 0 in M_sun/yr.",
60
61
62
63
64
            1.
        )),
        ("normalise", (
            "boolean",
            "Normalise the SFH to produce one solar mass.",
Denis's avatar
Denis committed
65
            "True"
66
        )),
67
    ])
68

69
    def process(self, sed):
70
71
72
73
        """Add a double decreasing exponential Star Formation History.

        Parameters
        ----------
74
        sed: pcigale.sed.SED object
75
76

        """
77
78
79
80
81
        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"])
82
83
        sfr_0 = int(self.parameters["sfr_0"])
        normalise = (self.parameters["normalise"].lower() == "true")
84
85

        # Time grid and age. If needed, the age is rounded to the inferior Myr
86
87
        time_grid = np.arange(1, age + 1)
        time_grid_burst = np.arange(1, burst_age + 1)
88

89
        # SFR for each component
90
        sfr = np.exp(-time_grid / tau_main)
91
        sfr_burst = np.exp(-time_grid_burst / tau_burst)
92
93

        # Height of the late burst to have the desired produced mass fraction
94
        sfr_burst *= f_burst / (1.-f_burst) * np.sum(sfr) / np.sum(sfr_burst)
95
96
97

        # We add the age burst exponential for ages superior to age -
        # burst_age
98
        sfr[-time_grid_burst[-1]:] += sfr_burst
99

100
101
        # Compute the galaxy mass and normalise the SFH to 1 solar mass
        # produced if asked to.
102
        galaxy_mass = np.sum(sfr) * 1e6
103
        if normalise:
104
            sfr /= galaxy_mass
105
            galaxy_mass = 1.
106
107
108
        else:
            sfr *= sfr_0
            galaxy_mass *= sfr_0
109

110
        sed.add_module(self.name, self.parameters)
111

112
        # Add the sfh and the output parameters to the SED.
Yannick Roehlly's avatar
Yannick Roehlly committed
113
        sed.sfh = (time_grid, sfr)
114
        sed.add_info("galaxy_mass", galaxy_mass, True)
115
116
117
118
        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)
Yannick Roehlly's avatar
Yannick Roehlly committed
119
120
121

# CreationModule to be returned by get_module
Module = Sfh2Exp