forked from OpenExoplanetCatalogue/oec_plots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_periodratio.python
112 lines (96 loc) · 2.76 KB
/
plot_periodratio.python
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
#!/usr/bin/python
import xml.etree.ElementTree as ET
import subprocess, glob, os, math, datetime
# Open pipe gnuplot. You may want to change the terminal from svg to pdf for publication quality plots.
gnuplot = subprocess.Popen(['gnuplot',"-persist"], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
gnuplot.stdin.write("""
set terminal svg
set output "plot_periodratio.svg"
set ylabel "Number of pairs"
set title "Period ratios in multiplanetary systems"
set xrange [1.2:4]
set lmargin 8
set yrange [0:]
set style fill solid 1.0
set label "Data taken from the Open Exoplanet Catalogue. Last updated on """+datetime.date.today().isoformat()+"""." at screen 0.31,0.15 front font ",8"
binwidth = 0.1
bin(x,width)=width*floor(x/width) + binwidth/2.0
set boxwidth binwidth
set multiplot
""")
minratio = 1.2
maxratio = 4.0
# RV planets
data = []
gnuplot.stdin.write("""
set size 1,0.5
set origin 0,0.5
unset xtics
unset xlabel
set yrange [0:8]
set bmargin 0
plot \
"-" using (bin($1,binwidth)):2 smooth freq with boxes t "Radial velocity systems"
""")
for filename in glob.glob("open_exoplanet_catalogue/systems/*.xml"):
system = ET.parse(open(filename, 'r'))
planets = system.findall(".//planet")
if len(planets)>1:
for planet1 in planets:
try:
discoverymethod = planet1.findtext("./discoverymethod")
period1 = float(planet1.findtext("./period"))
if discoverymethod=="RV":
for planet2 in planets:
period2 = float(planet2.findtext("./period"))
ratio = period1/period2
if ratio>minratio and ratio<maxratio:
data.append([ratio])
except:
pass
def compare(x, y):
if x[0]>y[0]: return 1
if x[0]<y[0]: return -1
return 0
sorteddata = sorted(data, cmp=compare)
for ratio in sorteddata:
gnuplot.stdin.write("%e\t%e\n"%(ratio[0],1.))
gnuplot.stdin.write("\ne\n")
gnuplot.stdin.write("""
unset title
set size 1,0.5
set origin 0,0.
set tmargin 0
set xtics
set bmargin
set yrange [0:95]
set xlabel "Period ratio"
set ytics 10
plot \
"-" using (bin($1,binwidth)):2 smooth freq with boxes ls 2 t "Kepler objects of interest (KOI)"
""")
# Kepler planets
data = []
for filename in glob.glob("open_exoplanet_catalogue/systems_kepler/*.xml"):
system = ET.parse(open(filename, 'r'))
planets = system.findall(".//planet")
if len(planets)>1:
for planet1 in planets:
try:
period1 = float(planet1.findtext("./period"))
for planet2 in planets:
period2 = float(planet2.findtext("./period"))
ratio = period1/period2
if ratio>minratio and ratio<maxratio:
data.append([ratio])
except:
pass
def compare(x, y):
if x[0]>y[0]: return 1
if x[0]<y[0]: return -1
return 0
sorteddata = sorted(data, cmp=compare)
for ratio in sorteddata:
gnuplot.stdin.write("%e\t%e\n"%(ratio[0],1.))
gnuplot.stdin.write("\ne\n")
gnuplot.stdin.close()