dh2002.py 2.29 KB
Newer Older
Yannick Roehlly's avatar
Yannick Roehlly committed
1
# -*- coding: utf-8 -*-
2
3
4
# Copyright (C) 2012, 2013 Centre de données Astrophysiques de Marseille
# Licensed under the CeCILL-v2 licence - see Licence_CeCILL_V2-en.txt
# Author: Yannick Roehlly <yannick.roehlly@oamp.fr>
Yannick Roehlly's avatar
Yannick Roehlly committed
5

6
from collections import OrderedDict
Yannick Roehlly's avatar
Yannick Roehlly committed
7
from . import common
8
from ...data import Database
Yannick Roehlly's avatar
Yannick Roehlly committed
9
10
11
12


class Module(common.SEDCreationModule):
    """
13
14
    Module computing the infra-red re-emission corresponding to an amount of
    attenuation using the Dale and Helou (2002) templates.
Yannick Roehlly's avatar
Yannick Roehlly committed
15

16
    Given an amount of attenuation (e.g. resulting from the action of a dust
Yannick Roehlly's avatar
Yannick Roehlly committed
17
    attenuation module) this module normalises the Dale and Helou (2002)
18
19
20
21
    template corresponding to a given α to this amount of energy and add it
    to the SED.

    Information added to the SED: NAME_alpha.
Yannick Roehlly's avatar
Yannick Roehlly committed
22
23
24

    """

25
26
    parameter_list = OrderedDict([
        ('alpha', (
Yannick Roehlly's avatar
Yannick Roehlly committed
27
28
29
            'float',
            "Alpha slope.",
            None
30
        )),
31
32
33
34
35
36
        ('attenuation_value_keys', (
            'string',
            "Keys of the SED information dictionary where the module will "
            "look for the attenuation (in W) to re-emit. You can give several "
            "keys separated with a & (don't use commas), a re-emission "
            "contribution will be added for each key.",
37
            "attenuation"
38
39
        ))
    ])
Yannick Roehlly's avatar
Yannick Roehlly committed
40

41
    out_parameter_list = OrderedDict([('alpha', 'Alpha slope.')])
Yannick Roehlly's avatar
Yannick Roehlly committed
42

43
44
45
46
47
48
    def _init_code(self):
        """Get the template set out of the database"""
        database = Database()
        self.dh2002 = database.get_dh2002_infrared_templates()
        database.session.close_all()

49
    def process(self, sed):
Yannick Roehlly's avatar
Yannick Roehlly committed
50
51
        """Add the IR re-emission contributions

Yannick Roehlly's avatar
Yannick Roehlly committed
52
        Parameters
Yannick Roehlly's avatar
Yannick Roehlly committed
53
54
55
56
        ----------
        sed  : pcigale.sed.SED object

        """
57
        alpha = float(self.parameters["alpha"])
58
59
60
        attenuation_value_keys = [
            item.strip() for item in
            self.parameters["attenuation_value_keys"].split("&")]
Yannick Roehlly's avatar
Yannick Roehlly committed
61

62
        ir_template = self.dh2002.get_template(alpha)
Yannick Roehlly's avatar
Yannick Roehlly committed
63

64
65
        sed.add_module(self.name, self.parameters)
        sed.add_info("alpha" + self.postfix, alpha)
66

67
        for attenuation in attenuation_value_keys:
68
            sed.add_contribution(
69
                self.name + "_" + attenuation,
70
                self.dh2002.wavelength_grid,
Yannick Roehlly's avatar
Yannick Roehlly committed
71
                sed.info[attenuation] * ir_template
Yannick Roehlly's avatar
Yannick Roehlly committed
72
            )