m2005.py 8.41 KB
Newer Older
Yannick Roehlly's avatar
Yannick Roehlly committed
1
# -*- coding: utf-8 -*-
2
3
# Copyright (C) 2012, 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
Yannick Roehlly's avatar
Yannick Roehlly committed
5

Yannick Roehlly's avatar
Yannick Roehlly committed
6
7
8
9
10
11
12
13
"""
Maraston (2005) stellar emission module
=======================================

This module implements the Maraston (2005) Single Stellar Populations.

"""

Yannick Roehlly's avatar
Yannick Roehlly committed
14
import numpy as np
15
from collections import OrderedDict
16
from . import CreationModule
17
from ..data import Database
Yannick Roehlly's avatar
Yannick Roehlly committed
18

19

Yannick Roehlly's avatar
Yannick Roehlly committed
20
class M2005(CreationModule):
Yannick Roehlly's avatar
Yannick Roehlly committed
21
    """Maraston (2005) stellar emission module
Yannick Roehlly's avatar
Yannick Roehlly committed
22

Yannick Roehlly's avatar
Yannick Roehlly committed
23
24
25
    This SED creation module convolves the SED star formation history with
    a Maraston (2005) single stellar population to add a stellar component to
    the SED.
Yannick Roehlly's avatar
Yannick Roehlly committed
26

27
28
29
30
    Information added to the SED:
        - imf, metallicity, galaxy_age
        - mass_total, mass_alive, mass_white_dwarf,mass_neutrino,
          mass_black_hole, mass_turn_off : stellar masses in solar mass.
31
        - age: age of the oldest stars in the galaxy.
Yannick Roehlly's avatar
Yannick Roehlly committed
32
        - old_young_separation_age: age (in Myr) separating the young and the
33
34
35
36
37
38
39
40
              old star populations (if 0, there is only one population)
        - mass_total_old, mass_alive_old, mass_white_dwarf_old,
          mass_neutrino_old, mass_black_hole_old, mass_turn_off_old: old
              star population masses.
        - mass_total_young, mass_alive_young, mass_white_dwarf_young,
          mass_neutrino_young, mass_black_hole_young, mass_turn_off_young:
              young star population masses.

Yannick Roehlly's avatar
Yannick Roehlly committed
41
42
    """

43
44
    parameter_list = OrderedDict([
        ('imf', (
Yannick Roehlly's avatar
Yannick Roehlly committed
45
            'string',
46
            "Initial mass function, salp (Salpeter) or krou (Krupa)",
Yannick Roehlly's avatar
Yannick Roehlly committed
47
            None
48
49
        )),
        ('metallicity', (
Yannick Roehlly's avatar
Yannick Roehlly committed
50
            'float',
51
            "Metallicity Z.",
Yannick Roehlly's avatar
Yannick Roehlly committed
52
            None
53
54
        )),
        ('separation_age', (
55
            'integer',
Yannick Roehlly's avatar
Yannick Roehlly committed
56
57
58
59
            "Age [Myr] of the separation between the young and the old star "
            "populations. The default value in 10^7 years (10 Myr). Set to "
            "0 not to differentiate ages (only an old population).",
            10
60
61
        ))
    ])
Yannick Roehlly's avatar
Yannick Roehlly committed
62

63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
    out_parameter_list = OrderedDict([
        ('sfr', 'Instantaneous Star Formation Rate in solar mass per year, '
                'at the age of the galaxy.'),
        ('average_sfr', 'Average SFR in the last 100 Myr (default) of the '
                        'galaxy history.'),
        ('mass_total', 'Total stellar mass of the galaxy in solar mass.'),
        ('mass_alive', 'Mass of alive stars in solar mass.'),
        ('mass_white_dwarf', 'Mass of white dwarf stars in solar mass.'),
        ('mass_neutrino', 'Mass of neutrino stars in solar mass.'),
        ('mass_black_hole', 'Mass of black holes in solar mass.'),
        ('mass_turn_off', 'Mass in the turn-off in solar mass.'),
        ('old_young_separation_age', 'Age (in Myr) separating the old and '
                                     'the young star populations (0 if there '
                                     'is only one population).'),
        ('mass_total_old', 'Total stellar mass of the old population in solar '
                           'mass.'),
        ('mass_alive_old', 'Mass of alive stars in solar mass (old '
                           'population).'),
        ('mass_white_dwarf_old', 'Mass of white dwarf stars in solar mass '
                                 '(old population).'),
        ('mass_neutrino_old', 'Mass of neutrino stars in solar mass '
                              '(old population).'),
        ('mass_black_hole_old', 'Mass of black holes in solar mass '
                                '(old population).'),
        ('mass_turn_off_old', 'Mass in the turn-off in solar mass '
                              '(old population).'),
        ('mass_total_young', 'Total stellar mass of the young population '
                             'in solar mass.'),
        ('mass_alive_young', 'Mass of alive stars in solar mass '
                             '(young population).'),
        ('mass_white_dwarf_young', 'Mass of white dwarf stars in solar mass '
                                   '(young population).'),
        ('mass_neutrino_young', 'Mass of neutrino stars in solar mass '
                                '(young population).'),
        ('mass_black_hole_young', 'Mass of black holes in solar mass '
                                  '(young population).'),
        ('mass_turn_off_young', 'Mass in the turn-off in solar mass '
                                '(young population).')
    ])
Yannick Roehlly's avatar
Yannick Roehlly committed
102

103
104
105
106
107
108
109
110
    def _init_code(self):
        """Read the SSP from the database."""
        imf = self.parameters["imf"]
        metallicity = float(self.parameters["metallicity"])
        database = Database()
        self.ssp = database.get_ssp_m2005(imf, metallicity)
        database.session.close_all()

111
    def process(self, sed):
Yannick Roehlly's avatar
Yannick Roehlly committed
112
113
        """Add the convolution of a Maraston 2005 SSP to the SED

Yannick Roehlly's avatar
Yannick Roehlly committed
114
        Parameters
Yannick Roehlly's avatar
Yannick Roehlly committed
115
116
117
118
119
120
        ----------
        sed  : pcigale.sed.SED
            SED object.

        """

121
        imf = self.parameters["imf"]
122
123
        metallicity = float(self.parameters["metallicity"])
        separation_age = int(self.parameters["separation_age"])
Yannick Roehlly's avatar
Yannick Roehlly committed
124
        sfh_time, sfh_sfr = sed.sfh
125
        ssp = self.ssp
126
127
128

        # Age of the galaxy at each time of the SFH
        sfh_age = np.max(sfh_time) - sfh_time
Yannick Roehlly's avatar
Yannick Roehlly committed
129

130
131
132
        # First, we process the young population (age lower than the
        # separation age.)
        young_sfh = np.copy(sfh_sfr)
133
        young_sfh[sfh_age > separation_age] = 0
134
135
136
137
138
        young_masses, young_spectrum = 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)
139
        old_sfh[sfh_age <= separation_age] = 0
140
        old_masses, old_spectrum = ssp.convolve(sfh_time, old_sfh)
141

142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
        sed.add_module(self.name, self.parameters)

        sed.add_info('ssp_imf' + self.postfix, imf)
        sed.add_info('ssp_metallicity' + self.postfix, metallicity)
        sed.add_info('ssp_old_young_separation_age' + self.postfix,
                     separation_age)

        sed.add_info('ssp_mass_total_old' + self.postfix, old_masses[0], True)
        sed.add_info('ssp_mass_alive_old' + self.postfix, old_masses[1], True)
        sed.add_info('ssp_mass_white_dwarf_old' + self.postfix, old_masses[2],
                     True)
        sed.add_info('ssp_mass_neutrino_old' + self.postfix, old_masses[3],
                     True)
        sed.add_info('ssp_mass_black_hole_old' + self.postfix, old_masses[4],
                     True)
        sed.add_info('ssp_mass_turn_off_old' + self.postfix, old_masses[5],
                     True)

        sed.add_info('ssp_mass_total_young' + self.postfix, young_masses[0],
                     True)
        sed.add_info('ssp_mass_alive_young' + self.postfix, young_masses[1],
                     True)
        sed.add_info('ssp_mass_white_dwarf_young' + self.postfix,
                     young_masses[2], True)
        sed.add_info('ssp_mass_neutrino_young' + self.postfix, young_masses[3],
                     True)
        sed.add_info('ssp_mass_black_hole_young' + self.postfix,
                     young_masses[4], True)
        sed.add_info('ssp_mass_turn_off_young' + self.postfix, young_masses[5],
                     True)

        sed.add_info('ssp_mass_total' + self.postfix,
                     old_masses[0] + young_masses[0], True)
        sed.add_info('ssp_mass_alive' + self.postfix,
                     old_masses[1] + young_masses[1], True)
        sed.add_info('ssp_mass_white_dwarf' + self.postfix,
                     old_masses[2] + young_masses[2], True)
        sed.add_info('ssp_mass_neutrino' + self.postfix,
                     old_masses[3] + young_masses[3], True)
        sed.add_info('ssp_mass_black_hole' + self.postfix,
                     old_masses[4] + young_masses[4], True)
        sed.add_info('ssp_mass_turn_off' + self.postfix,
                     old_masses[5] + young_masses[5], True)

186
187
188
189
        # We take off anything below the Lyman break in the spectra
        old_spectrum[ssp.wavelength_grid < 91.2] = 0.
        young_spectrum[ssp.wavelength_grid < 91.2] = 0.

190
        sed.add_contribution("ssp_old" + self.postfix,
191
192
                             ssp.wavelength_grid,
                             old_spectrum)
193
        sed.add_contribution("ssp_young" + self.postfix,
194
195
                             ssp.wavelength_grid,
                             young_spectrum)
Yannick Roehlly's avatar
Yannick Roehlly committed
196
197
198

# CreationModule to be returned by get_module
Module = M2005