forked from OpenExoplanetCatalogue/oec_plots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_binaryarchitecture.python
147 lines (127 loc) · 3.59 KB
/
plot_binaryarchitecture.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
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
#!/usr/bin/python
import xml.etree.ElementTree as ET
import subprocess, glob, os,math
# 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 800,3000
set output "plot_binaryarchitecture.svg"
set bmargin 1
set xtics in
set xtics nomirror
set tmargin 1
unset ytics
set yrange [-0.5:3]
""")
data = []
y= 0
class hostobject:
def __init__(self):
self.childs = []
self.planets = []
self.semimajoraxis = 0
self.tree = None
self.tag = None
self.mass = 0
self.name = None
self.objecttype = 0
def setup(self,xmlobject):
self.tree = xmlobject
self.tag = xmlobject.tag
_childs = xmlobject.findall("./star") + xmlobject.findall("./binary") + xmlobject.findall("./planet")
for child in _childs:
ho = hostobject()
ho.setup(child)
self.childs.append(ho)
self.mass += ho.mass
if xmlobject.tag == "binary":
try:
_semimajoraxis = float(xmlobject.findtext("./semimajoraxis"))
except:
period = float(xmlobject.findtext("./period"))
_semimajoraxis = math.pow(period/365.25,2./3.)
pass
childindex = 0
for child in self.childs:
if child.tag=="binary" or child.tag=="star":
if childindex == 0:
child.semimajoraxis = - _semimajoraxis*(1.-child.mass/self.mass)
else:
child.semimajoraxis = _semimajoraxis*(1.-child.mass/self.mass)
childindex += 1
if xmlobject.tag == "star":
try:
self.mass += float(xmlobject.findtext("./mass"))
except:
pass
if xmlobject.tag == "planet":
try:
self.semimajoraxis = float(xmlobject.findtext("./semimajoraxis"))
except:
pass
def findminx(self,offset,minx):
x = self.semimajoraxis + offset
for child in self.childs:
minx = child.findminx(x,minx)
if minx>x:
return x
else:
return minx
def printstars(self,offset):
global y
if self.tag=="star":
gnuplot.stdin.write("%f\t%e\n" %(y, self.semimajoraxis + offset))
y+=1
for child in self.childs:
child.printstars(self.semimajoraxis + offset)
y-=1
def printplanets(self,offset):
global y
if self.tag=="planet":
gnuplot.stdin.write("%f\t%e\n" %(y+0.009, self.semimajoraxis + offset))
y+=1
for child in self.childs:
child.printplanets(self.semimajoraxis + offset)
y-=1
def printlines(self,offset):
global y
x = self.semimajoraxis + offset
y+=1
for child in self.childs:
xchild = child.printlines(x)
gnuplot.stdin.write("%d\t%e\n" %(y-1, x))
gnuplot.stdin.write("%d\t%e\n" %(y-1, xchild))
gnuplot.stdin.write("%d\t%e\n" %(y, xchild))
gnuplot.stdin.write("\n")
y-=1
return self.semimajoraxis + offset
# parse
hostobjects = []
for filename in glob.glob("open_exoplanet_catalogue/systems/*.xml"):
system = ET.parse(open(filename, 'r'))
binaries = system.findall(".//binary")
if len(binaries)>0:
ho = hostobject()
ho.setup(system.find("./binary"))
ho.name = system.findtext("./name")
hostobjects.append(ho)
gnuplot.stdin.write("set multiplot layout %d,1\n"%(len(hostobjects)))
# print
for ho in hostobjects:
gnuplot.stdin.write("unset label\nset label \"%s\"\n" % ho.name)
gnuplot.stdin.write("""
plot \
"-" u 2:1 with lines lt 1 lc rgb "gray" notitle, \
"-" u 2:1 with point pt 7 ps 1. lt 1 lc rgb "yellow" notitle, \
"-" u 2:1 with point pt 7 ps 0.5 lt 4 lc rgb "black" notitle
""")
y = 0
ho.printlines(0.0)
gnuplot.stdin.write("\ne\n")
y = 0
ho.printstars(0.0)
gnuplot.stdin.write("\ne\n")
y = 0
ho.printplanets(0.0)
gnuplot.stdin.write("\ne\n")
gnuplot.stdin.close()