m2005.py 5.23 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
92
        young_sfh = np.copy(sed.sfh)
        young_sfh[:-self.separation_age] = 0.
        young_masses, young_spectrum = self.ssp.convolve(sfh_time, young_sfh)
93
94
95

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

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

102
103
104
        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)
105
106
107
108

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

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

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

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