sfh_quenching_trunk.py 3.23 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 (trunk) module
===============================================
Yannick Roehlly's avatar
Yannick Roehlly committed
10
11
12
13
14
15
16

This module performs a quenching on the Star Formation History. Below a given
age, the Star Formation Rate in multiplied by 1 - quenching_factor and is set
constant.

"""

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 SfhQuenchTrunk(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([
Yannick Roehlly's avatar
Yannick Roehlly committed
32
        ("quenching_age", (
33
            "cigale_list(dtype=int, minvalue=0.)",
34
            "Look-back time when the quenching happens 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
53
54
    def _init_code(self):
        self.quenching_age = int(self.parameters["quenching_age"])
        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
67
    def process(self, sed):
        """
        Parameters
        ----------
        sed : pcigale.sed.SED object

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

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

Yannick Roehlly's avatar
Yannick Roehlly committed
74
75
76
77
78
        # 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.
79
        if self.quenching_age > 0 and self.quenching_factor > 0.:
80
            sfr[-self.quenching_age:] = sfr[-self.quenching_age] * (
81
                1. - self.quenching_factor)
Yannick Roehlly's avatar
Yannick Roehlly committed
82
83
84

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

90
            sed.sfh = sfr
91
            sed.add_info("sfh.integrated", sfr_integrated, True, force=True)
Yannick Roehlly's avatar
Yannick Roehlly committed
92
93
94

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

95
96
        sed.add_info("sfh.quenching_age", self.quenching_age)
        sed.add_info("sfh.quenching_factor", self.quenching_factor)
Yannick Roehlly's avatar
Yannick Roehlly committed
97

98

99
# SedModule to be returned by get_module
100
Module = SfhQuenchTrunk