sfh_quenching_smooth.py 3.39 KB
Newer Older
Yannick Roehlly's avatar
Yannick Roehlly committed
1
2
# -*- coding: utf-8 -*-

3
# Copyright (C) 2015-2016 Laboratoire d'Astrophysique de Marseille
Yannick Roehlly's avatar
Yannick Roehlly committed
4
5
6
7
# Licensed under the CeCILL-v2 licence - see Licence_CeCILL_V2-en.txt
# Author: Yannick Roehlly

"""
8
9
Star Formation History quenching (smooth) module
================================================
Yannick Roehlly's avatar
Yannick Roehlly committed
10

11
12
13
This module performs a smooth quenching on the Star Formation History. Below a
given age, the Star Formation Rate becomes linear to be multiplied by
1- quenching_factor at the end of the history.
Yannick Roehlly's avatar
Yannick Roehlly committed
14
15
16

"""

17
from collections import OrderedDict
18

Yannick Roehlly's avatar
Yannick Roehlly committed
19
import numpy as np
20

21
from . import SedModule
Yannick Roehlly's avatar
Yannick Roehlly committed
22

23

24
class SfhQuenchSmooth(SedModule):
Yannick Roehlly's avatar
Yannick Roehlly committed
25
26
27
28
29
30
    """Star Formation History Quenching

    This module implements a quenching of the Star Formation History.

    """

31
    parameter_list = OrderedDict([
32
        ("quenching_time", (
33
            "cigale_list(dtype=int, minvalue=0.)",
34
            "Look-back time when the quenching starts in Myr.",
Yannick Roehlly's avatar
Yannick Roehlly committed
35
36
37
            0
        )),
        ("quenching_factor", (
38
            "cigale_list(minvalue=0., maxvalue=1.)",
Yannick Roehlly's avatar
Yannick Roehlly committed
39
40
41
42
            "Quenching factor applied to the SFH. After the quenching time, "
            "the SFR is multiplied by 1 - quenching factor and made constant. "
            "The factor must be between 0 (no quenching) and 1 (no more star "
            "formation).",
43
            0.
Yannick Roehlly's avatar
Yannick Roehlly committed
44
45
        )),
        ("normalise", (
46
            "boolean()",
Yannick Roehlly's avatar
Yannick Roehlly committed
47
            "Normalise the SFH to produce one solar mass.",
48
            True
Yannick Roehlly's avatar
Yannick Roehlly committed
49
50
51
        ))
    ])

52
    def _init_code(self):
53
        self.quenching_age = int(self.parameters["quenching_time"])
54
        self.quenching_factor = float(self.parameters["quenching_factor"])
55
56
57
58
        if type(self.parameters["normalise"]) is str:
            normalise = self.parameters["normalise"].lower() == 'true'
        else:
            normalise = bool(self.parameters["normalise"])
59

Yannick Roehlly's avatar
Yannick Roehlly committed
60
61
62
63
64
65
66
    def process(self, sed):
        """
        Parameters
        ----------
        sed : pcigale.sed.SED object

        """
67

Yannick Roehlly's avatar
Yannick Roehlly committed
68
        # Read the star formation history of the SED
69
        sfr = sed.sfh
Yannick Roehlly's avatar
Yannick Roehlly committed
70

71
        if self.quenching_age > sfr.size:
72
73
74
            raise Exception("[sfh_quenching] The quenching age is greater "
                            "than the galaxy age. Please fix your parameters.")

Yannick Roehlly's avatar
Yannick Roehlly committed
75
76
77
78
79
        # We assume the time in the star formation history is evenly spaced to
        # compute the reverse index (i.e. from the end of the array) of the SFH
        # step corresponding to the quenching age.
        # We make the computation only if the quenching age and the quenching
        # factor are not 0.
80
        if self.quenching_age > 0 and self.quenching_factor > 0.:
81
82
83
84
            sfr0 = sfr[-self.quenching_age]
            sfr1 = sfr[-self.quenching_age] * (1. - self.quenching_factor)
            sfr[-self.quenching_age:] = sfr0 + (sfr1 - sfr0) * np.linspace(
                0, 1, self.quenching_age)
Yannick Roehlly's avatar
Yannick Roehlly committed
85
86
87

            # Compute the galaxy mass and normalise the SFH to 1 solar mass
            # produced if asked to.
88
            sfr_integrated = np.sum(sfr) * 1e6
89
            if self.normalise:
90
91
                sfr /= sfr_integrated
                sfr_integrated = 1.
Yannick Roehlly's avatar
Yannick Roehlly committed
92

93
            sed.sfh = sfr
94
            sed.add_info("sfh.integrated", sfr_integrated, True, force=True)
Yannick Roehlly's avatar
Yannick Roehlly committed
95
96
97

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

98
        sed.add_info("sfh.quenching_time", self.quenching_age)
99
        sed.add_info("sfh.quenching_factor", self.quenching_factor)
Yannick Roehlly's avatar
Yannick Roehlly committed
100

101

102
# SedModule to be returned by get_module
103
Module = SfhQuenchSmooth