sfh2exp.py 4.01 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 SedModule
20

21

22
class Sfh2Exp(SedModule):
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
            "cigale_list()",
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
            "cigale_list()",
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
            "cigale_list(minvalue=0., maxvalue=0.9999)",
43
            "Mass fraction of the late burst population.",
44
            0.01
45
46
        )),
        ("age", (
47
            "cigale_list(dtype=int, minvalue=0.)",
48
49
            "Age of the main stellar population in the galaxy in Myr. The "
            "precision is 1 Myr.",
50
            5000
51
52
        )),
        ("burst_age", (
53
            "cigale_list(dtype=int, minvalue=1.)",
54
            "Age of the late burst in Myr. The 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
            "cigale_list(minvalue=0.)",
59
            "Value of SFR at t = 0 in M_sun/yr.",
60
61
62
            1.
        )),
        ("normalise", (
63
            "boolean()",
64
            "Normalise the SFH to produce one solar mass.",
65
            True
66
        )),
67
    ])
68

69
70
71
72
73
    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"])
74
        age = int(self.parameters["age"])
75
        sfr_0 = float(self.parameters["sfr_0"])
76
77
78
79
        if type(self.parameters["normalise"]) is str:
            normalise = self.parameters["normalise"].lower() == 'true'
        else:
            normalise = bool(self.parameters["normalise"])
80
81

        # Time grid and age. If needed, the age is rounded to the inferior Myr
82
        time_grid = np.arange(age)
83
        time_grid_burst = np.arange(self.burst_age)
84

85
        # SFR for each component
86
        self.sfr = np.exp(-time_grid / self.tau_main)
87
        sfr_burst = np.exp(-time_grid_burst / self.tau_burst)
88
89

        # Height of the late burst to have the desired produced mass fraction
90
91
        sfr_burst *= (self.f_burst / (1.-self.f_burst) * np.sum(self.sfr) /
                      np.sum(sfr_burst))
92
93
94

        # We add the age burst exponential for ages superior to age -
        # burst_age
95
        self.sfr[-(time_grid_burst[-1]+1):] += sfr_burst
96

97
98
        # Compute the galaxy mass and normalise the SFH to 1 solar mass
        # produced if asked to.
99
        self.sfr_integrated = np.sum(self.sfr) * 1e6
100
        if normalise:
101
102
            self.sfr /= self.sfr_integrated
            self.sfr_integrated = 1.
103
        else:
104
            self.sfr *= sfr_0
105
            self.sfr_integrated *= sfr_0
106
107
108
109
110
111
112
113
114

    def process(self, sed):
        """Add a double decreasing exponential Star Formation History.

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

        """
115

116
        sed.add_module(self.name, self.parameters)
117

118
        # Add the sfh and the output parameters to the SED.
119
        sed.sfh = self.sfr
120
        sed.add_info("sfh.integrated", self.sfr_integrated, True)
121
122
123
124
        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)
Yannick Roehlly's avatar
Yannick Roehlly committed
125

126

127
# SedModule to be returned by get_module
Yannick Roehlly's avatar
Yannick Roehlly committed
128
Module = Sfh2Exp