m2005.py 5.17 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.

"""

14
from collections import OrderedDict
15

Yannick Roehlly's avatar
Yannick Roehlly committed
16
import numpy as np
17

18
from . import SedModule
19
from ..data import Database
Yannick Roehlly's avatar
Yannick Roehlly committed
20

21

22
class M2005(SedModule):
Yannick Roehlly's avatar
Yannick Roehlly committed
23
    """Maraston (2005) stellar emission module
Yannick Roehlly's avatar
Yannick Roehlly committed
24

Yannick Roehlly's avatar
Yannick Roehlly committed
25
26
27
    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
28

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

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

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

64
65
    def _init_code(self):
        """Read the SSP from the database."""
66
67
68
69
70
71
72
73
74
75
        self.imf = int(self.parameters["imf"])
        self.metallicity = float(self.parameters["metallicity"])
        self.separation_age = int(self.parameters["separation_age"])

        if self.imf == 0:
            with Database() as database:
                self.ssp = database.get_m2005('salp', self.metallicity)
        elif self.imf == 1:
            with Database() as database:
                self.ssp = database.get_m2005('krou', self.metallicity)
76
        else:
77
            raise Exception("IMF #{} unknown".format(self.imf))
78

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

Yannick Roehlly's avatar
Yannick Roehlly committed
82
        Parameters
Yannick Roehlly's avatar
Yannick Roehlly committed
83
        ----------
84
        sed: pcigale.sed.SED
Yannick Roehlly's avatar
Yannick Roehlly committed
85
86
87
            SED object.

        """
88
89
        # First, we process the young population (age lower than the
        # separation age.)
90
91
        young_masses, young_spectrum = self.ssp.convolve(
            sed.sfh[-self.separation_age:])
92
93
94

        # Then, we process the old population. If the SFH is shorter than the
        # separation age then all the arrays will consist only of 0.
95
96
        old_sfh = np.copy(sed.sfh)
        old_sfh[-self.separation_age:] = 0.
97
        old_masses, old_spectrum = self.ssp.convolve(old_sfh)
98

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

101
102
103
        sed.add_info('stellar.imf', self.imf)
        sed.add_info('stellar.metallicity', self.metallicity)
        sed.add_info('stellar.old_young_separation_age', self.separation_age)
104
105
106
107

        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)
108
        sed.add_info('stellar.mass_neutron_old', old_masses[3], True)
109
110
111
112
113
        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)
114
        sed.add_info('stellar.mass_neutron_young', young_masses[3], True)
115
116
117
        sed.add_info('stellar.mass_black_hole_young', young_masses[4], True)

        sed.add_info('stellar.mass_total',
118
                     old_masses[0] + young_masses[0], True)
119
        sed.add_info('stellar.mass_alive',
120
                     old_masses[1] + young_masses[1], True)
121
        sed.add_info('stellar.mass_white_dwarf',
122
                     old_masses[2] + young_masses[2], True)
123
        sed.add_info('stellar.mass_neutron',
124
                     old_masses[3] + young_masses[3], True)
125
        sed.add_info('stellar.mass_black_hole',
126
127
                     old_masses[4] + young_masses[4], True)

128
        sed.add_contribution("stellar.old",
Yannick Roehlly's avatar
Yannick Roehlly committed
129
                             self.ssp.wavelength_grid,
130
                             old_spectrum)
131
        sed.add_contribution("stellar.young",
Yannick Roehlly's avatar
Yannick Roehlly committed
132
                             self.ssp.wavelength_grid,
133
                             young_spectrum)
Yannick Roehlly's avatar
Yannick Roehlly committed
134

135
# SedModule to be returned by get_module
Yannick Roehlly's avatar
Yannick Roehlly committed
136
Module = M2005