loadfile.py 1.75 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
"""
Read spectrum from file module
==============================

This module reads a SED spectrum from a file.

"""

Yannick Roehlly's avatar
Yannick Roehlly committed
14
import atpy
15
from collections import OrderedDict
16
from . import CreationModule
Yannick Roehlly's avatar
Yannick Roehlly committed
17 18


Yannick Roehlly's avatar
Yannick Roehlly committed
19
class LoadSpecFile(CreationModule):
20
    """Module reading a spectrum from a file and adding it to the SED.
Yannick Roehlly's avatar
Yannick Roehlly committed
21 22 23

    Note that this module uses the atpy module, which is not automatically
    installed when one installs pcigale.
24

Yannick Roehlly's avatar
Yannick Roehlly committed
25 26
    """

27 28
    parameter_list = OrderedDict([
        ("filename", (
Yannick Roehlly's avatar
Yannick Roehlly committed
29 30 31 32 33
            'str',
            "Name of the file to load and to add to the SED table. This "
            "file must be loadable with atpy (that depends on other modules "
            "being installed).",
            None
34 35
        )),
        ("lambda_column", (
Yannick Roehlly's avatar
Yannick Roehlly committed
36 37 38
            'str',
            "Name of the column containing the wavelength in nm.",
            None
39 40
        )),
        ("l_lambda_column", (
Yannick Roehlly's avatar
Yannick Roehlly committed
41 42 43
            'str',
            "Name of the column containing the Lλ luminosity in W/nm.",
            None
44 45
        ))
    ])
Yannick Roehlly's avatar
Yannick Roehlly committed
46

47
    def process(self, sed):
Yannick Roehlly's avatar
Yannick Roehlly committed
48 49
        """Add the spectrum from the file to the SED object

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

        """
55
        filename = self.parameters['filename']
Yannick Roehlly's avatar
Yannick Roehlly committed
56
        table = atpy.Table(filename, verbose=False)
57

58
        sed.add_module(self.name, self.parameters)
59 60

        sed.add_contribution(
61
            filename,
62 63
            table[self.parameters['lambda_column']],
            table[self.parameters['l_lambda_column']]
Yannick Roehlly's avatar
Yannick Roehlly committed
64
        )
Yannick Roehlly's avatar
Yannick Roehlly committed
65 66 67

# CreationModule to be returned by get_module
Module = LoadSpecFile