m2005.py 7.77 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
    def _init_code(self):
        """Read the SSP from the database."""
        imf = self.parameters["imf"]
        metallicity = float(self.parameters["metallicity"])
107
        with Database() as database:
108
            self.ssp = database.get_m2005(imf, metallicity)
109

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

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

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

        # 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
127

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

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

142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
        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.mass_total_old', old_masses[0], True)
        sed.add_info('stellar.mass_alive_old', old_masses[1], True)
        sed.add_info('stellar.mass_white_dwarf_old', old_masses[2], True)
        sed.add_info('stellar.mass_neutrino_old', old_masses[3], True)
        sed.add_info('stellar.mass_black_hole_old', old_masses[4], True)
        sed.add_info('stellar.mass_turn_off_old', old_masses[5], True)

        sed.add_info('stellar.mass_total_young', young_masses[0], True)
        sed.add_info('stellar.mass_alive_young', young_masses[1], True)
        sed.add_info('stellar.mass_white_dwarf_young', young_masses[2], True)
        sed.add_info('stellar.mass_neutrino_young', young_masses[3], True)
        sed.add_info('stellar.mass_black_hole_young', young_masses[4], True)
        sed.add_info('stellar.mass_turn_off_young', young_masses[5], True)

        sed.add_info('stellar.mass_total',
161
                     old_masses[0] + young_masses[0], True)
162
        sed.add_info('stellar.mass_alive',
163
                     old_masses[1] + young_masses[1], True)
164
        sed.add_info('stellar.mass_white_dwarf',
165
                     old_masses[2] + young_masses[2], True)
166
        sed.add_info('stellar.mass_neutrino',
167
                     old_masses[3] + young_masses[3], True)
168
        sed.add_info('stellar.mass_black_hole',
169
                     old_masses[4] + young_masses[4], True)
170
        sed.add_info('stellar.mass_turn_off',
171
172
                     old_masses[5] + young_masses[5], True)

173
174
        sed.add_info("galaxy_mass", 1., True)

175
        sed.add_contribution("ssp_old",
176
177
                             ssp.wavelength_grid,
                             old_spectrum)
178
        sed.add_contribution("ssp_young",
179
180
                             ssp.wavelength_grid,
                             young_spectrum)
Yannick Roehlly's avatar
Yannick Roehlly committed
181
182
183

# CreationModule to be returned by get_module
Module = M2005