forked from jyshangguan/Fitter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gsf_mpi.py
70 lines (67 loc) · 2.25 KB
/
gsf_mpi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from __future__ import print_function
import os
import sys
import warnings
from optparse import OptionParser
from emcee.utils import MPIPool
from gsf_core import *
#Parse the commands#
#-------------------#
parser = OptionParser()
parser.add_option("-w", "--warning", dest="warning",
action="store_true", default=False,
help="Stop ignoring the warnings.")
parser.add_option("-o", "--overwrite", dest="overwrite",
action="store_true", default=False,
help="Overwrite the object information with the command-line inputs.")
parser.add_option("-r", "--refit", dest="refit", action="store_true", default=False,
help="Refit the SED though there is a result found.")
(options, args) = parser.parse_args()
if len(args) == 0:
raise AssertionError("The config file is not specified!")
else:
configName = args[0] #Get the input configure file information.
#Some times the warning may stop the code, so we ignore the warnings by default.
if options.warning:
pass
else:
warnings.simplefilter("ignore")
if options.refit:
refit = True
else:
refit = False
pool = MPIPool()
if not pool.is_master():
pool.wait()
sys.exit(0)
#-> The starter of this module
print("\n")
print("############################")
print("# Galaxy SED Fitter starts #")
print("############################")
print("\n")
#--> The object can be provided by the configure file or be overwrite with the
# command-line inputs
len_args = len(args)
if not options.overwrite:
if len_args > 1:
print("**Warning[UniFit]: there are more arguments may not be used...")
gsf_fitter(configName, mpi_pool=pool, refit=refit)
else:
if len_args < 4:
pool.close()
raise AssertionError("The object information is lacking!")
if len_args == 4:
targname = args[1]
redshift = eval(args[2])
distance = None
sedFile = args[3]
elif len_args == 5:
targname = args[1]
redshift = eval(args[2])
distance = eval(args[3]) #The distance should be in Mpc.
sedFile = args[4]
else:
print("**Warning[UniFit]: there are more arguments may not be used...")
gsf_fitter(configName, targname, redshift, distance, sedFile, pool, refit)
pool.close()