sfhdelayed.py 2.72 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# Copyright (C) 2013 Centre de données Astrophysiques de Marseille
# Copyright (C) 2014 Laboratoire d'Astrophysique de Marseille
# Copyright (C) 2014 University of Cambridge
# Licensed under the CeCILL-v2 licence - see Licence_CeCILL_V2-en.txt
# Author: Yannick Roehlly, Véronique Buat & Médéric Boquien

"""
Delayed tau model for star formation history
============================================

This module implements a star formation history (SFH) described as a delayed
rise of the SFR up to a maximum, followed by an exponential decrease.

"""

16
from collections import OrderedDict
17

18
import numpy as np
19

20 21
from . import CreationModule

22

23 24 25 26 27 28 29 30
class SFHDelayed(CreationModule):
    """Delayed tau model for Star Formation History

    This module sets the SED star formation history (SFH) proportional to time,
    with a declining exponential parametrised with a time-scale (tau_main).

    """

31
    parameter_list = OrderedDict([
32 33 34
        ("tau_main", (
            "float",
            "e-folding time of the main stellar population model in Myr.",
35
            2000.
36 37 38 39 40
        )),
        ("age", (
            "integer",
            "Age of the oldest stars in the galaxy in Myr. The precision "
            "is 1 Myr.",
41
            5000.
Denis's avatar
Denis committed
42
        )),
Médéric Boquien's avatar
Médéric Boquien committed
43
        ("sfr_A", (
44 45 46 47 48 49 50
            "float",
            "Multiplicative factor controlling the amplitude of SFR.",
            1.
        )),
        ("normalise", (
            "boolean",
            "Normalise the SFH to produce one solar mass.",
Denis's avatar
Denis committed
51
            "True"
52
        ))
Médéric Boquien's avatar
Médéric Boquien committed
53
    ])
54

55 56
    def _init_code(self):
        self.tau_main = float(self.parameters["tau_main"])
57
        age = int(self.parameters["age"])
58 59
        sfr_A = int(self.parameters["sfr_A"])
        normalise = (self.parameters["normalise"].lower() == "true")
60

61 62 63 64
        # Time grid and SFR
        self.time_grid = np.arange(age)
        self.sfr = self.time_grid * np.exp(-self.time_grid / self.tau_main) / \
                   self.tau_main**2
65

66 67
        # Compute the galaxy mass and normalise the SFH to 1 solar mass
        # produced if asked to.
68
        self.sfr_integrated = np.sum(self.sfr) * 1e6
69
        if normalise:
70 71
            self.sfr /= self.sfr_integrated
            self.sfr_integrated = 1.
72
        else:
73 74 75 76 77 78 79 80 81 82
            self.sfr *= sfr_A
            self.sfr_integrated *= sfr_A

    def process(self, sed):
        """
        Parameters
        ----------
        sed : pcigale.sed.SED object

        """
83 84 85 86

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

        # Add the sfh and the output parameters to the SED.
87 88 89
        sed.sfh = (self.time_grid, self.sfr)
        sed.add_info("sfh.integrated", self.sfr_integrated, True)
        sed.add_info("sfh.tau_main", self.tau_main)
90 91 92

# CreationModule to be returned by get_module
Module = SFHDelayed