forked from OpenExoplanetCatalogue/oec_plots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_mass_vs_semimajoraxis_eccentricity.python
41 lines (37 loc) · 1.49 KB
/
plot_mass_vs_semimajoraxis_eccentricity.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
#!/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_mass_vs_semimajoraxis_eccentricity.svg"
set xlabel "Semi-major axis [AU]"
set ylabel "Planet mass [MJupiter]"
set cblabel "Eccentricity"
set logscale xy
set xrange [0.001:80]
set yrange [0.008:25]
set label "Data taken from the Open Exoplanet Catalogue. Last updated on {0}." at screen 0.19,0.15 front font ",8"
plot "-" with point pt 7 lc palette notit
""".format(datetime.date.today().isoformat()).encode('utf-8'))
for filename in glob.glob("open_exoplanet_catalogue/systems/*.xml"):
system = ET.parse(open(filename, 'r'))
planets = system.findall(".//planet")
for planet in planets:
try:
mass = float(planet.findtext("./mass"))
semimajoraxis = float(planet.findtext("./semimajoraxis"))
try:
eccentricity = float(planet.findtext("./eccentricity"))
except:
eccentricity = 0.
gnuplot.stdin.write("{0:e}\t{1:e}\t{2:e}\n".format(
mass, semimajoraxis,
eccentricity).encode('utf-8'))
except:
# Mass or semimajoraxis 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.
pass
gnuplot.stdin.write("\ne\n".encode('utf-8'))
gnuplot.stdin.close()