forked from OpenExoplanetCatalogue/oec_plots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_architecture.python
70 lines (60 loc) · 2.04 KB
/
plot_architecture.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
#!/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 size 600,2048
set output "plot_architecture.svg"
set xlabel "Semi-major axis [AU]"
set autoscale fix
set yrange [-1:*]
set xrange [0.003:10]
set format y ""
set ytics 1
set title "Architecture of multiplanetary systems"
set logscale x
set label "Data taken from the Open Exoplanet Catalogue. Last updated on """+datetime.date.today().isoformat()+"""." at screen 0.31,0.034 front font ",8"
plot \
"-" with labels right offset -1,0 font ",8" notit, \
"-" with point pt 7 ps variable notitle
""")
data = []
for filename in glob.glob("open_exoplanet_catalogue/systems/*.xml"):
system = ET.parse(open(filename, 'r'))
planets = system.findall(".//planet")
if len(planets)>1:
datasystem = []
for planet in planets:
try:
mass = float(planet.findtext("./mass"))
name = system.findtext("./name")
semimajoraxis = float(planet.findtext("./semimajoraxis"))
datasystem.append([semimajoraxis,mass,name])
except:
# Most likely cause for an exception: Mass or semi-major axis not specified for this planet.
# One could do a more complicated check here and see if the period and the mass of the host star is given and then calculate the semi-major axis
pass
if len(datasystem)>0:
datasystem.sort()
data.append(datasystem)
def compare(x, y):
if x>y: return 1
if x<y: return -1
return 0
sorteddata = sorted(data, cmp=compare)
# Labels
y=0
for system in sorteddata:
gnuplot.stdin.write("%e\t%e\t\"%s\"\n"%(system[0][0],y,system[0][2]))
y += 1
gnuplot.stdin.write("\ne\n")
#Systems
y=0
for system in sorteddata:
for planet in system:
pointsize = (math.log(planet[1])+7.)/8.
gnuplot.stdin.write("%e\t%e\t%e\n"%(planet[0], y, pointsize))
y += 1
gnuplot.stdin.write("\ne\n")
gnuplot.stdin.close()