bc03.py 4.8 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
"""
Bruzual and Charlot (2003) stellar emission module
==================================================

This module implements the Bruzual and Charlot (2003) Single Stellar
Populations.

"""

15
from collections import OrderedDict
16

17
import numpy as np
18

19
from . import CreationModule
20
from ..data import Database
21

22

Yannick Roehlly's avatar
Yannick Roehlly committed
23
class BC03(CreationModule):
Yannick Roehlly's avatar
Yannick Roehlly committed
24
25
26
27
28
    """Bruzual and Charlot (2003) stellar emission module

    This SED creation module convolves the SED star formation history with a
    Bruzual and Charlot (2003) single stellar population to add a stellar
    component to the SED.
29
30
    """

31
    parameter_list = OrderedDict([
32
        ("imf", (
33
            "int",
34
            "Initial mass function: 0 (Salpeter) or 1 (Chabrier).",
35
            0
36
37
        )),
        ("metallicity", (
38
            "float",
39
40
            "Metalicity. Possible values are: 0.0001, 0.0004, 0.004, 0.008, "
            "0.02, 0.05.",
41
            0.02
42
43
44
        )),
        ("separation_age", (
            "int",
Yannick Roehlly's avatar
Yannick Roehlly committed
45
46
            "Age [Myr] of the separation between the young and the old star "
            "populations. The default value in 10^7 years (10 Myr). Set "
47
            "to 0 not to differentiate ages (only an old population).",
Yannick Roehlly's avatar
Yannick Roehlly committed
48
            10
49
50
        ))
    ])
51

52
53
    def _init_code(self):
        """Read the SSP from the database."""
54
55
56
57
        if self.parameters["imf"] == 0:
            imf = 'salp'
        elif self.parameters["imf"] == 1:
            imf = 'chab'
58
        metallicity = float(self.parameters["metallicity"])
59
        with Database() as database:
60
            self.ssp = database.get_bc03(imf, metallicity)
61

62
    def process(self, sed):
63
64
65
66
        """Add the convolution of a Bruzual and Charlot SSP to the SED

        Parameters
        ----------
67
        sed: pcigale.sed.SED
68
69
70
71
            SED object.

        """
        imf = self.parameters["imf"]
72
73
        metallicity = float(self.parameters["metallicity"])
        separation_age = int(self.parameters["separation_age"])
Yannick Roehlly's avatar
Yannick Roehlly committed
74
        sfh_time, sfh_sfr = sed.sfh
75
        ssp = self.ssp
76
77
78
79
80
81
82

        # Age of the galaxy at each time of the SFH
        sfh_age = np.max(sfh_time) - sfh_time

        # First, we process the young population (age lower than the
        # separation age.)
        young_sfh = np.copy(sfh_sfr)
83
        young_sfh[sfh_age > separation_age] = 0
84
85
86
87
88
        young_wave, young_lumin, young_info = ssp.convolve(sfh_time, young_sfh)

        # Then, we process the old population. If the SFH is shorter than the
        # separation age then all the arrays will consist only of 0.
        old_sfh = np.copy(sfh_sfr)
89
        old_sfh[sfh_age <= separation_age] = 0
90
91
        old_wave, old_lumin, old_info = ssp.convolve(sfh_time, old_sfh)

92
93
94
95
96
97
        # We compute the Lyman continuum luminosity as it is important to
        # compute the energy absorbed by the dust before ionising gas.
        w = np.where(young_wave <= 91.1)
        lum_ly_young = np.trapz(young_lumin[w], young_wave[w])
        lum_ly_old = np.trapz(old_lumin[w], old_wave[w])

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

100
101
102
103
104
105
        sed.add_info("stellar.imf", imf)
        sed.add_info("stellar.metallicity", metallicity)
        sed.add_info("stellar.old_young_separation_age", separation_age)

        sed.add_info("stellar.m_star_young", young_info["m_star"], True)
        sed.add_info("stellar.m_gas_young", young_info["m_gas"], True)
106
        sed.add_info("stellar.n_ly_young", young_info["n_ly"], True)
107
        sed.add_info("stellar.lum_ly_young", lum_ly_young, True)
108
109
110
111
112
113
114
        sed.add_info("stellar.b_400_young", young_info["b_4000"])
        sed.add_info("stellar.b4_vn_young", young_info["b4_vn"])
        sed.add_info("stellar.b4_sdss_young", young_info["b4_sdss"])
        sed.add_info("stellar.b_912_young", young_info["b_912"])

        sed.add_info("stellar.m_star_old", old_info["m_star"], True)
        sed.add_info("stellar.m_gas_old", old_info["m_gas"], True)
115
        sed.add_info("stellar.n_ly_old", old_info["n_ly"], True)
116
        sed.add_info("stellar.lum_ly_old", lum_ly_old, True)
117
118
119
120
121
        sed.add_info("stellar.b_400_old", old_info["b_4000"])
        sed.add_info("stellar.b4_vn_old", old_info["b4_vn"])
        sed.add_info("stellar.b4_sdss_old", old_info["b4_sdss"])
        sed.add_info("stellar.b_912_old", old_info["b_912"])

122
123
124
125
126
127
128
        sed.add_info("stellar.m_star",
                     young_info["m_star"] + old_info["m_star"],
                     True)
        sed.add_info("stellar.m_gas",
                     young_info["m_gas"] + old_info["m_gas"],
                     True)

129
130
        sed.add_contribution("stellar.old", old_wave, old_lumin)
        sed.add_contribution("stellar.young", young_wave, young_lumin)
Yannick Roehlly's avatar
Yannick Roehlly committed
131
132
133

# CreationModule to be returned by get_module
Module = BC03