sfhperiodic.py 4.25 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 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 & Médéric Boquien

"""
Periodic SFH in the form of rectangles, and decaying or delayed exponentials
============================================================================

# 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".

"""

from collections import OrderedDict
18

19
import numpy as np
20

21
from . import SedModule
22
23


24
class SfhPeriodic(SedModule):
25
26
27
28
29
30
31
32
33
    """Several regularly-spaced short delayed-SFH SF events

    This module sets the SED star formation history (SFH) as a combination of
    several regularly-spaced short SF events.

    """

    parameter_list = OrderedDict([
        ("type_bursts", (
34
            "cigale_list(dtype=int, options=0. & 1. & 2.)",
35
36
37
38
39
            "Type of the individual star formation episodes. 0: exponential, "
            "1: delayed, 2: rectangle.",
            0
        )),
        ("delta_bursts", (
40
            "cigale_list(dtype=int, minvalue=0.)",
41
42
43
44
45
            "Elapsed time between the beginning of each burst in Myr. The "
            "precision is 1 Myr.",
            50
        )),
        ("tau_bursts", (
46
            "cigale_list()",
47
48
            "Duration (rectangle) or e-folding time of all short events in "
            "Myr. The precision is 1 Myr.",
49
            20.
50
51
        )),
        ("age", (
52
            "cigale_list(dtype=int, minvalue=0.)",
53
54
55
56
57
            "Age of the main stellar population in the galaxy in Myr. The "
            "precision is 1 Myr.",
            1000
        )),
        ("sfr_A", (
58
            "cigale_list(minvalue=0.)",
59
60
61
62
63
            "Multiplicative factor controlling the amplitude of SFR (valid "
            "for each event).",
            1.
        )),
        ("normalise", (
64
            "boolean()",
65
            "Normalise the SFH to produce one solar mass.",
66
            True
67
68
69
70
71
72
        )),
    ])

    def _init_code(self):
        self.type_bursts = int(self.parameters["type_bursts"])
        self.delta_bursts = int(self.parameters["delta_bursts"])
73
        self.tau_bursts = float(self.parameters["tau_bursts"])
74
75
        age = int(self.parameters["age"])
        sfr_A = float(self.parameters["sfr_A"])
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
82
        time_grid = np.arange(0, age)
        self.sfr = np.zeros_like(time_grid, dtype=np.float)
83
84

        if self.type_bursts == 0:
85
            burst = np.exp(-time_grid/self.tau_bursts)
86
        elif self.type_bursts == 1:
87
88
            burst = np.exp(-time_grid/self.tau_bursts) * \
                    time_grid/self.tau_bursts**2
89
        elif self.type_bursts == 2:
90
            burst = np.zeros_like(time_grid)
91
            burst[:int(self.tau_bursts)+1] = 1.
92
93
94
95
96
97
98
99
100
101
        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.
102
        self.sfr_integrated = np.sum(self.sfr) * 1e6
103
        if normalise:
104
105
            self.sfr /= self.sfr_integrated
            self.sfr_integrated = 1.
106
107
        else:
            self.sfr *= sfr_A
108
            self.sfr_integrated *= sfr_A
109
110
111
112
113
114
115
116
117
118
119
120
121

    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)

122
        sed.sfh = self.sfr
123
        sed.add_info("sfh.integrated", self.sfr_integrated, True)
124
125
126
127
        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)

128

129
# SedModule to be returned by get_module
130
Module = SfhPeriodic