Skip to content
Snippets Groups Projects

Add artists

Merged Zoheyr Doctor requested to merge add_artists into master
26 files
+ 221
161
Compare changes
  • Side-by-side
  • Inline
Files
26
@@ -2,6 +2,7 @@
import numpy as np
from twirl.binary import Binary
from twirl.artists import BinaryBlackHole
from matplotlib import pyplot as plt
from matplotlib import animation
from matplotlib.patches import Circle
@@ -84,9 +85,9 @@ def main():
}
pos_dict = {} # dictionary for all compact object positions
binary_dict = {} # dictionary for all Binary objects
bbh_dict = {} # dictionary for all BinaryBlackHole objects
# loop over all events
for event in events:
for ei,event in enumerate(events):
print('evolving ',event)
event_pos_dict = {} # dictionary for positions of this event
@@ -108,37 +109,20 @@ def main():
binary.evolve(n_frames)
binary_dict[event] = binary
# make BBH artist
bbh = BinaryBlackHole(
binary = binary,
ax = ax[ei],
name=event,
BH_scale = 1./200
)
bbh_dict[event] = bbh
artist_dict = {} # dictionary for matplotlib artists
def init():
for ei,event in enumerate(events):
# create artists for both stars
z1,x1,y1 = binary_dict[event].pos1_projected[0,:]
z2,x2,y2 = binary_dict[event].pos2_projected[0,:]
artist_dict['%s_m1'%event] = ax[ei].add_artist(
Circle((x1,y1),
radius=binary_dict[event].m1/200,
edgecolor='white',
facecolor='black'
)
)
artist_dict['%s_m2'%event] = ax[ei].add_artist(
Circle((x2,y2),
radius=binary_dict[event].m2/200,
edgecolor='white',
facecolor='black'
)
)
# make sure star that is closer is shown on top of the other
zorder_1 = int(z1>z2)
zorder_2 = ~zorder_1
artist_dict['%s_m1'%event].set_zorder(zorder_1)
artist_dict['%s_m2'%event].set_zorder(zorder_2)
print(bbh_dict.keys())
artist_dict.update(bbh_dict[event].setup_artists())
# configure plot axes, title
ax[ei].set_xlim([-1,1])
@@ -147,29 +131,13 @@ def main():
if not args.no_names:
print('putting names on events')
ax[ei].set_title(event)
print(artist_dict)
return artist_dict
def animate(i):
for ei,event in enumerate(events):
# update positions of stars
z1,x1,y1 = binary_dict[event].pos1_projected[i,:]
z2,x2,y2 = binary_dict[event].pos2_projected[i,:]
artist_dict['%s_m1'%event].set_center((x1,y1))
artist_dict['%s_m2'%event].set_center((x2,y2))
# make sure star that is closer is shown on top of the other
if z1>z2:
zorder_1 = 2
zorder_2 = 1
else:
zorder_1 = 1
zorder_2 = 2
artist_dict['%s_m1'%event].set_zorder(zorder_1)
artist_dict['%s_m2'%event].set_zorder(zorder_2)
return artist_dict
artist_dict.update(bbh_dict[event].get_artists(i))
return artist_dict
anim = animation.FuncAnimation(fig,animate,init_func=init,frames=n_frames)
#anim.save('orbit.gif',fps=fps,writer='imagemagick',extra_args=['-vcodec', 'libx264'])
Loading