__init__.py 2.87 KB
Newer Older
1 2 3 4
# -*- coding: utf-8 -*-
# Copyright (C) 2013 Centre de données Astrophysiques de Marseille
# Copyright (C) 2013-2014 Yannick Roehlly
# Copyright (C) 2013 Institute of Astronomy
5
# Copyright (C) 2014 Laboratoire d'Astrophysique de Marseille
6
# Licensed under the CeCILL-v2 licence - see Licence_CeCILL_V2-en.txt
7
# Author: Yannick Roehlly, Médéric Boquien & Denis Burgarella
8 9

import argparse
10
import sys
11
import multiprocessing as mp
12

13
from pcigale.session.configuration import Configuration
14 15 16 17
from .plot_types.chi2 import chi2 as chi2_action
from .plot_types.pdf import pdf as pdf_action
from .plot_types.sed import sed as sed_action
from .plot_types.mock import mock as mock_action
18

Médéric Boquien's avatar
Médéric Boquien committed
19 20
__version__ = "0.1-alpha"

21
# Wavelength limits (restframe) when plotting the best SED.
22
PLOT_L_MIN = 0.1
23
PLOT_L_MAX = 5e5
24 25 26 27


def main():

28 29 30 31 32 33
    if sys.version_info[:2] >= (3, 4):
        mp.set_start_method('spawn')
    else:
        print("Could not set the multiprocessing start method to spawn. If "
              "you encounter a deadlock, please upgrade to Python≥3.4.")

34 35 36 37 38 39 40
    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")

41
    pdf_parser = subparsers.add_parser('pdf', help=pdf_action.__doc__)
42 43
    pdf_parser.set_defaults(parser='pdf')

44
    chi2_parser = subparsers.add_parser('chi2', help=chi2_action.__doc__)
45 46
    chi2_parser.set_defaults(parser='chi2')

47
    sed_parser = subparsers.add_parser('sed', help=sed_action.__doc__)
48
    sed_parser.add_argument('--type', default='mJy')
49 50 51
    sed_parser.add_argument('--nologo', action='store_true')
    sed_parser.add_argument('--best-results-file', dest='best_results_file',
                            default='out/results.fits')
52 53
    sed_parser.set_defaults(parser='sed')

54 55 56 57 58 59 60
    mock_parser = subparsers.add_parser('mock', help=mock_action.__doc__)
    mock_parser.add_argument('--nologo', action='store_true')
    mock_parser.add_argument('--best-results-file', dest='best_results_file',
                            default='out/results.fits')
    mock_parser.add_argument('--mock-results-file', dest='mock_results_file',
                            default='out/results_mock.fits')
    mock_parser.set_defaults(parser='mock')
61

62 63 64 65 66 67 68
    args = parser.parse_args()

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

69 70 71 72
    if len(sys.argv) == 1:
        parser.print_usage()
    else:
        if args.parser == 'chi2':
73
            chi2_action(config)
74
        elif args.parser == 'pdf':
75
            pdf_action(config)
76
        elif args.parser == 'sed':
77
            sed_action(config, args.type, args.best_results_file, args.nologo)
78
        elif args.parser == 'mock':
79
            mock_action(config, args.best_results_file, args.mock_results_file, args.nologo)