forked from acshu/transit-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transit
166 lines (144 loc) · 6.24 KB
/
transit
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/usr/bin/python
import sys
import os.path
import csv
from transitlib.transit import Transit
import matplotlib.pyplot as pyplot
semi_major_axis = 0.0171
star_radius = 0.0036
planet_radius = 0.00058
star_temperature = 4675
planet_temperature = 1300
inclination = 90
star_darkening_law = 'linear'
star_darkening_1 = 0.22
star_darkening_2 = 0.11
phase_start = 0
phase_end = 0.1
phase_step = 0.001
data = []
export_file = None
export_separator = "\t"
os.system('cls' if os.name == 'nt' else 'clear')
print ""
print "Transit"
# collect arguments
prev_argument = None
for argument in sys.argv[1:]:
if argument == "-h":
print ""
print "Help:"
print "\t-h Prints this help information"
print "\t-i Interactive mode for input parameters"
print "\t-p Plots the result"
print "\t-d params.dat Input parameters file"
print ""
print "\t semi_major_axis=0.0171"
print "\t star_radius=0.0036"
print "\t planet_radius=0.00058"
print "\t star_temperature=4675"
print "\t planet_temperature=1300"
print "\t inclination=90"
print "\t star_darkening_law=linear"
print "\t star_darkening_1=0.22"
print "\t star_darkening_2=0.11"
print "\t phase_start=0.0"
print "\t phase_end=0.2"
print "\t phase_step=0.001"
print ""
print "\t-e result.dat Result export file"
print "\t-s , Separator for export file (default: \\t)"
print ""
exit()
if prev_argument == "-d" and os.path.isfile(argument) :
file = open(argument)
data = [line.strip() for line in file]
file.close()
if prev_argument == "-e":
export_file = argument
if prev_argument == "-s":
argument = "\t" if argument == "\\t" else argument
argument = "\n" if argument == "\\n" else argument
export_separator = argument
prev_argument = argument
# read input file
for param in data :
name, value = param.split("=")
if name == "semi_major_axis" : semi_major_axis = value
if name == "star_radius" : star_radius = value
if name == "planet_radius" : planet_radius = value
if name == "star_temperature" : star_temperature = value
if name == "planet_temperature" : planet_temperature = value
if name == "inclination" : inclination = value
if name == "star_darkening_law" : star_darkening_law = value
if name == "star_darkening_1" : star_darkening_1 = value
if name == "star_darkening_2" : star_darkening_2 = value
if name == "phase_start" : phase_start = value
if name == "phase_end" : phase_end = value
if name == "phase_step" : phase_step = value
# ask user for input
if sys.argv.count("-i") > 0 :
semi_major_axis = raw_input("Semi-major axis [AU]: ") or semi_major_axis
star_radius = raw_input("Star radius [AU]: ") or star_radius
planet_radius = raw_input("Planet radius [AU]: ") or planet_radius
star_temperature = raw_input("Star temperature [K]: ") or star_temperature
planet_temperature = raw_input("Planet temperature [K]: ") or planet_temperature
inclination = raw_input("Inclination: ") or inclination
star_darkening_law = raw_input("Star darkening law: ") or star_darkening_law
star_darkening_1 = raw_input("Star darkening 1: ") or star_darkening_1
star_darkening_2 = raw_input("Star darkening 2: ") or star_darkening_2
phase_start = raw_input("Phase start: ") or phase_start
phase_end = raw_input("Phase end: ") or phase_end
phase_step = raw_input("Phase step: ") or phase_step
print ""
print "Params"
print "----------------------------------------"
print "Semi-major axis [AU]: " + str(semi_major_axis)
print "Star radius [AU]: " + str(star_radius)
print "Planet radius [AU]: " + str(planet_radius)
print "Star temperature [K] : " + str(star_temperature)
print "Planet temperature [K] : " + str(planet_temperature)
print "Inclination : " + str(inclination)
print "Star darkening law : " + str(star_darkening_law)
print "Star darkening 1 : " + str(star_darkening_1)
print "Star darkening 2 : " + str(star_darkening_2)
print "Phase start : " + str(phase_start)
print "Phase end : " + str(phase_end)
print "Phase step : " + str(phase_step)
print "----------------------------------------"
print ""
print "Progress"
def onProgress(progress):
repeat_fill = int(float(progress/(100/30)))
repeat_empty = int(float(100//(100/30))) - repeat_fill
sys.stdout.write("\r[" + ('-' * repeat_fill) + (' ' * repeat_empty) + "] " + str(progress) + "%")
def onComplete(phases, results):
print ""
print ""
print "Completed"
if not export_file is None :
print "Writing: " + export_file
with open(export_file, 'wb') as csvfile:
writer = csv.writer(csvfile, delimiter=export_separator)
for index in range(len(phases)):
writer.writerow([phases[index], results[index]])
if sys.argv.count("-p") > 0 :
pyplot.plot(phases, results)
pyplot.show()
transit = Transit()
transit.set_semi_major_axis(semi_major_axis)
transit.set_star_radius(star_radius)
transit.set_planet_radius(planet_radius)
transit.set_star_temperature(star_temperature)
transit.set_planet_temperature(planet_temperature)
transit.set_inclination(inclination)
transit.set_star_darkening_type(star_darkening_law)
transit.set_star_darkening_1(star_darkening_1)
transit.set_star_darkening_2(star_darkening_2)
transit.set_phase_start(phase_start)
transit.set_phase_end(phase_end)
transit.set_phase_step(phase_step)
transit.set_precision(1e-4)
transit.onProgress = onProgress
transit.onComplete = onComplete
transit.run()