-
Notifications
You must be signed in to change notification settings - Fork 10
/
plot_binarysep_vs_planetsep.python
61 lines (57 loc) · 2.03 KB
/
plot_binarysep_vs_planetsep.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
#!/usr/bin/python
import xml.etree.ElementTree as ET
import subprocess, glob, os, 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_binarysep_vs_planetsep.svg"
set xlabel "Binary separation [AU]"
set ylabel "Planet semi-major axis [AU]"
set logscale xy
set xrange [:20000]
set yrange [0.01:10]
set key at screen 0.4,0.27
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"
plot \
"-" with point pt 7 lc 2 t "S-type orbits", \
"-" with point pt 7 lc 1 t "P-type orbits", \
x w line lt 1 lc rgb "gray" notit
""")
for filename in glob.glob("open_exoplanet_catalogue/systems/*.xml"):
system = ET.parse(open(filename, 'r'))
planets = system.findall(".//binary/star/planet")
binaries = system.findall(".//binary")
if len(planets)>0:
for planet in planets:
planethost = None
for binary in binaries:
for star in binary:
for _planet in star:
if _planet == planet:
planethost = binary
try:
binarysep = float(planethost.findtext("./semimajoraxis"))
semimajoraxis = float(planet.findtext("./semimajoraxis"))
gnuplot.stdin.write("%e\t%e\n"%(binarysep, semimajoraxis))
except:
pass
gnuplot.stdin.write("\ne\n")
for filename in glob.glob("open_exoplanet_catalogue/systems/*.xml"):
system = ET.parse(open(filename, 'r'))
planets = system.findall(".//binary/planet")
binaries = system.findall(".//binary")
if len(planets)>0:
for planet in planets:
planethost = None
for binary in binaries:
if planet in binary:
planethost = binary
try:
binarysep = float(planethost.findtext("./semimajoraxis"))
semimajoraxis = float(planet.findtext("./semimajoraxis"))
gnuplot.stdin.write("%e\t%e\n"%(binarysep, semimajoraxis))
except:
pass
gnuplot.stdin.write("\ne\n")
gnuplot.stdin.close()