m2005.py 7.34 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
    Information added to the SED:
        - imf, metallicity, galaxy_age
29
        - mass_total, mass_alive, mass_white_dwarf,mass_neutron,
30
          mass_black_hole: 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
              old star populations (if 0, there is only one population)
        - mass_total_old, mass_alive_old, mass_white_dwarf_old,
35
          mass_neutron_old, mass_black_hole_old, : old star population masses.
36
        - mass_total_young, mass_alive_young, mass_white_dwarf_young,
37
38
          mass_neutron_young, mass_black_hole_young: young star population
              masses.
39

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

42
43
    parameter_list = OrderedDict([
        ('imf', (
44
            'int',
45
            "Initial mass function: 0 (Salpeter) or 1 (Kroupa)",
46
            0
47
48
        )),
        ('metallicity', (
Yannick Roehlly's avatar
Yannick Roehlly committed
49
            'float',
50
            "Metallicity. Possible values are: 0.001, 0.01, 0.02, 0.04.",
51
            0.02
52
53
        )),
        ('separation_age', (
54
            'int',
Yannick Roehlly's avatar
Yannick Roehlly committed
55
56
57
58
            "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
59
60
        ))
    ])
Yannick Roehlly's avatar
Yannick Roehlly committed
61

62
63
64
    out_parameter_list = OrderedDict([
        ('sfr', 'Instantaneous Star Formation Rate in solar mass per year, '
                'at the age of the galaxy.'),
65
66
67
        ('sfr10Myrs', 'Average SFR in the last 10 Myr (default) of the '
                        'galaxy history.'),
        ('sfr100Myrs', 'Average SFR in the last 100 Myr (default) of the '
68
69
70
71
                        '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.'),
72
        ('mass_neutron', 'Mass of neutron stars in solar mass.'),
73
74
75
76
77
78
79
80
81
82
        ('mass_black_hole', 'Mass of black holes 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).'),
83
        ('mass_neutron_old', 'Mass of neutron stars in solar mass '
84
85
86
87
88
89
90
91
92
                              '(old population).'),
        ('mass_black_hole_old', 'Mass of black holes 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).'),
93
        ('mass_neutron_young', 'Mass of neutron stars in solar mass '
94
95
                                '(young population).'),
        ('mass_black_hole_young', 'Mass of black holes in solar mass '
96
                                  '(young population).')
97
    ])
Yannick Roehlly's avatar
Yannick Roehlly committed
98

99
100
    def _init_code(self):
        """Read the SSP from the database."""
101
102
103
        if self.parameters["imf"] == 0:
            imf = 'salp'
        elif self.parameters["imf"] == 1:
104
            imf = 'krou'
105
        metallicity = float(self.parameters["metallicity"])
106
        with Database() as database:
107
            self.ssp = database.get_m2005(imf, metallicity)
108

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

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

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

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

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

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

141
142
143
144
145
146
147
        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)
148
        sed.add_info('stellar.mass_neutron_old', old_masses[3], True)
149
150
151
152
153
        sed.add_info('stellar.mass_black_hole_old', old_masses[4], 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)
154
        sed.add_info('stellar.mass_neutron_young', young_masses[3], True)
155
156
157
        sed.add_info('stellar.mass_black_hole_young', young_masses[4], True)

        sed.add_info('stellar.mass_total',
158
                     old_masses[0] + young_masses[0], True)
159
        sed.add_info('stellar.mass_alive',
160
                     old_masses[1] + young_masses[1], True)
161
        sed.add_info('stellar.mass_white_dwarf',
162
                     old_masses[2] + young_masses[2], True)
163
        sed.add_info('stellar.mass_neutron',
164
                     old_masses[3] + young_masses[3], True)
165
        sed.add_info('stellar.mass_black_hole',
166
167
                     old_masses[4] + young_masses[4], True)

168
        sed.add_contribution("stellar.old",
169
170
                             ssp.wavelength_grid,
                             old_spectrum)
171
        sed.add_contribution("stellar.young",
172
173
                             ssp.wavelength_grid,
                             young_spectrum)
Yannick Roehlly's avatar
Yannick Roehlly committed
174
175
176

# CreationModule to be returned by get_module
Module = M2005