Commit d3d63e60 authored by Zoheyr Doctor's avatar Zoheyr Doctor 🔭
Browse files

regenerated gifs using artists

parent 40017947
......@@ -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'])
......
#!/usr/bin/env python
import numpy as np
from twirl.binary import InspiralingBinary
from matplotlib import pyplot as plt
from matplotlib import animation
from matplotlib.patches import Circle
import sys
plt.style.use('dark_background')
fig,ax = plt.subplots()
fps = 30.
omega0 = 20.
m1 = 30.,
m2 = 30.,
binary = InspiralingBinary(
m1 = 30.,
m2 = 30.,
alpha = 45.,
beta = 20.,
gamma = 80.,
omega0 = omega0
)
print('tc:',binary.tc)
print('omegamax',binary.omegamax)
binary.inspiral()
print('t:',binary.t)
pos1 = binary.pos1_projected
pos2 = binary.pos2_projected
print('pos shape:',pos1.shape)
x1s = pos1[:,1]
y1s = pos1[:,2]
x2s = pos2[:,1]
y2s = pos2[:,2]
artist_dict = {}
def init():
artist_dict['m1'] = ax.add_artist(
Circle((x1s[0],y1s[0]),
radius=100.,
edgecolor='white',
facecolor='black'
)
)
artist_dict['m2'] = ax.add_artist(
Circle((x2s[0],y2s[0]),
radius=100.,
edgecolor='white',
facecolor='black'
)
)
ax.set_xlim([-2000,2000])
ax.set_ylim([-2000,2000])
return artist_dict
def animate(i):
artist_dict['m1'].set_center((x1s[i],y1s[i]))
artist_dict['m2'].set_center((x2s[i],y2s[i]))
return artist_dict
anim = animation.FuncAnimation(fig,animate,init_func=init,frames = len(x1s))
anim.save('inspiral.mp4',fps=fps,extra_args=['-vcodec', 'libx264'])
......@@ -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
......@@ -73,7 +74,7 @@ def main():
) for event in events
}
binary_dict = {} # dictionary for all Binary objects
binary_dict = {} # dictionary for all BBH artist objects
# loop over all events
for event in events:
print('evolving ',event)
......@@ -95,42 +96,24 @@ def main():
n_frames = int(length*fps)
binary.evolve(n_frames)
# write out evolution to dictionary
binary_dict[event] = binary
for ei,event in enumerate(events):
fig,ax = plt.subplots()
ax.set_axis_off()
artist_dict = {} # dictionary for matplotlib artists
bbh = BinaryBlackHole(
binary = binary_dict[event],
ax = ax,
name=event,
BH_scale = 1./200
)
def init():
z1,x1,y1 = binary_dict[event].pos1_projected[0,:]
z2,x2,y2 = binary_dict[event].pos2_projected[0,:]
# create artists for both stars
artist_dict['%s_m1'%event] = ax.add_artist(
Circle((x1,y1),
radius=binary_dict[event].m1/200,
edgecolor='white',
facecolor='black'
)
)
artist_dict['%s_m2'%event] = ax.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)
artist_dict.update(bbh.setup_artists())
ax.set_xlim([-1,1])
ax.set_ylim([-1,1])
ax.set_title(event)
......@@ -138,23 +121,7 @@ def main():
return artist_dict
def animate(i):
# 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)
artist_dict.update(bbh.get_artists(i))
return artist_dict
anim = animation.FuncAnimation(fig,animate,init_func=init,frames=n_frames)
......
#!/usr/bin/env python
import numpy as np
from twirl.artists import BlackHoleRingdown
from matplotlib import pyplot as plt
from matplotlib import animation
from matplotlib.patches import Circle
import sys
plt.style.use('dark_background')
fig,ax = plt.subplots()
ringdown = BlackHoleRingdown(
M=1.,
amplitude0 = 1.,
omega=0.03,
tau=15,
ax=ax,
name='BH',
)
def init():
ax.set_xlim([-10,10])
ax.set_ylim([-10,10])
return ringdown.setup_artists()
def animate(i):
return ringdown.get_artists(i)
fps = 30
anim = animation.FuncAnimation(fig,animate,init_func=init,frames = 60)
anim.save('ringdown.mp4',fps=fps,extra_args=['-vcodec', 'libx264'])
......@@ -13,8 +13,6 @@ setup(
scripts = [
'bin/animate_binaries_from_file',
'bin/make_event_gifs',
'bin/inspiral_test',
'bin/ringdown_test',
'bin/inspiral_ringdown',
],
packages = [
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment