-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunred_stars.py
executable file
·101 lines (90 loc) · 2.44 KB
/
unred_stars.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env python3
from importlib import import_module
from argparse import ArgumentParser, RawTextHelpFormatter
from textwrap import dedent
from unred.unred import *
argparser = ArgumentParser(
prog='unred_stars.py',
description=dedent('''\
>> Determine interstellar reddening of stars on the color-color plane <<
'''),
epilog='Copyright (c) 2019 Przemysław Bruś',
formatter_class=RawTextHelpFormatter
)
argparser.add_argument(
'stars_list',
help=dedent('''\
The name of a file which must contain columns with data:
id x_color y_color x_err_color y_err_color
------------------------------------------
int float float float float
''')
)
argparser.add_argument(
'unred_sequence',
help=dedent('''\
The name of a file which must contain columns with data:
x_color y_color
---------------
float float
The data must be sorted by INCREASING TEMPERATURE
''')
)
argparser.add_argument(
'line_slope',
help=dedent('''\
A reddening line slope defined as E(y_color)/E(x_color)
Example: E(U-B)/E(B-V) = 0.72
'''),
type=float
)
argparser.add_argument(
'extinction_ratio',
help=dedent('''\
A ratio of total to selective extinction
defined as A/E(x_color)
Example: Av/E(B-V) = 3.1
'''),
type=float
)
argparser.add_argument(
'--min',
help=dedent('''\
for each star print only the minimum value of extinction
'''),
action='store_true'
)
argparser.add_argument(
'--max',
help=dedent('''\
for each star print only the maximum value of extinction
'''),
action='store_true'
)
argparser.add_argument(
'-v',
'--version',
action='version',
version=dedent('''\
%(prog)s
* Version: ''' + import_module('unred').__version__ + '''
* Licensed under the MIT license:
* http://opensource.org/licenses/MIT
* ''' + argparser.epilog)
)
args = argparser.parse_args()
if args.min and args.max:
print(argparser.prog + ": choose only one option: --min or --max")
exit(1)
stars = args.stars_list
unred_sequence = args.unred_sequence
line_slope = args.line_slope
extinction_ratio = args.extinction_ratio
points = read_reddened_stars(stars)
model = read_unreddened_sequence(unred_sequence)
results = extinction(points, model, line_slope, extinction_ratio)
if args.min:
results = select_extinction(results)
elif args.max:
results = select_extinction(results, "max")
print_extinction(results)