__init__.py 2.83 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

6
7
__version__ = "0.1-alpha"

8
9
import argparse
from .session.configuration import Configuration
10
from .analysis_modules import get_module as get_analysis_module
11
12
13
14
15
16
17
18
19
20
21
22
23


def init(config):
    "Create a blank configuration file."
    config.create_blank_conf()
    print("The initial configuration file was created. Please complete it "
          "with the data file name and the pcigale modules to use.")


def genconf(config):
    "Generate the full configuration."
    config.generate_conf()
    print("The configuration file has been updated. Please complete the "
Yannick Roehlly's avatar
Yannick Roehlly committed
24
          "various module parameters and the data file columns to use in "
25
26
27
28
29
          "the analysis.")


def check(config):
    "Check the configuration."
30
    # TODO: Check if all the parameters that don't have default values are
31
    # given for each module.
Médéric Boquien's avatar
Médéric Boquien committed
32
33
    print("With this configuration, pcigale must compute {} "
          "SEDs.".format(len(config.creation_modules_conf_array)))
34
35
36
37


def run(config):
    "Run the analysis."
Yannick Roehlly's avatar
Yannick Roehlly committed
38
39
    data_file = config.configuration['data_file']
    column_list = config.configuration['column_list']
40
41
    creation_modules = config.configuration['creation_modules']
    creation_modules_params = config.creation_modules_conf_array
42
43
44
    analysis_module = get_analysis_module(config.configuration[
        'analysis_method'])
    analysis_module_params = config.configuration['analysis_method_params']
45
    cores = config.configuration['cores']
46

47
    analysis_module.process(data_file, column_list, creation_modules,
48
49
                            creation_modules_params, analysis_module_params,
                            cores)
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87


def main():

    parser = argparse.ArgumentParser()

    parser.add_argument('-c', '--conf-file', dest='config_file',
                        help="Alternative configuration file to use.")

    subparsers = parser.add_subparsers(help="List of commands")

    init_parser = subparsers.add_parser('init', help=init.__doc__)
    init_parser.set_defaults(parser='init')

    genconf_parser = subparsers.add_parser('genconf', help=genconf.__doc__)
    genconf_parser.set_defaults(parser='genconf')

    check_parser = subparsers.add_parser('check', help=check.__doc__)
    check_parser.set_defaults(parser='check')

    run_parser = subparsers.add_parser('run', help=run.__doc__)
    run_parser.set_defaults(parser='run')

    args = parser.parse_args()

    if args.config_file:
        config = Configuration(args.config_file)
    else:
        config = Configuration()

    if args.parser == 'init':
        init(config)
    elif args.parser == 'genconf':
        genconf(config)
    elif args.parser == 'check':
        check(config)
    elif args.parser == 'run':
        run(config)