loadfile.py 1.58 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.

"""

14
from collections import OrderedDict
15

16
from ..utils import read_table
17
from . import SedModule
Yannick Roehlly's avatar
Yannick Roehlly committed
18 19


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

    """

25
    parameter_list = OrderedDict([
26
        ("filename", (
27
            'string()',
Yannick Roehlly's avatar
Yannick Roehlly committed
28
            "Name of the file to load and to add to the SED table. This "
Médéric Boquien's avatar
Médéric Boquien committed
29
            "file must be loadable with astropy",
Yannick Roehlly's avatar
Yannick Roehlly committed
30
            None
31 32
        )),
        ("lambda_column", (
33
            'string()',
Yannick Roehlly's avatar
Yannick Roehlly committed
34 35
            "Name of the column containing the wavelength in nm.",
            None
36 37
        )),
        ("l_lambda_column", (
38
            'string()',
Yannick Roehlly's avatar
Yannick Roehlly committed
39 40
            "Name of the column containing the Lλ luminosity in W/nm.",
            None
41 42
        ))
    ])
Yannick Roehlly's avatar
Yannick Roehlly committed
43

44
    def process(self, sed):
Yannick Roehlly's avatar
Yannick Roehlly committed
45 46
        """Add the spectrum from the file to the SED object

Yannick Roehlly's avatar
Yannick Roehlly committed
47
        Parameters
Yannick Roehlly's avatar
Yannick Roehlly committed
48
        ----------
49
        sed: pcigale.sed.SED object
Yannick Roehlly's avatar
Yannick Roehlly committed
50 51

        """
52
        filename = self.parameters['filename']
53
        table = read_table(filename)
54

55
        sed.add_module(self.name, self.parameters)
56 57

        sed.add_contribution(
58
            filename,
59 60
            table[self.parameters['lambda_column']],
            table[self.parameters['l_lambda_column']]
Yannick Roehlly's avatar
Yannick Roehlly committed
61
        )
Yannick Roehlly's avatar
Yannick Roehlly committed
62

63

64
# SedModule to be returned by get_module
Yannick Roehlly's avatar
Yannick Roehlly committed
65
Module = LoadSpecFile