Commit 31964b73 authored by Zoheyr Doctor's avatar Zoheyr Doctor 🔭
Browse files

Merge branch 'fix_z_order' into 'master'

Fix issue where one star was always shown in front of the other

See merge request !3
parents bae90753 fb421f01
......@@ -6,6 +6,7 @@ from twirl.artists import BinaryBlackHole
from matplotlib import pyplot as plt
from matplotlib import animation
from matplotlib.patches import Circle
import json
def make_parser():
from argparse import ArgumentParser
......@@ -152,7 +153,6 @@ def main():
artist_dict = {} # dictionary for matplotlib artists
def init():
for ei,event in enumerate(events):
print(bbh_dict.keys())
artist_dict.update(bbh_dict[event].setup_artists())
# configure plot axes, title
......@@ -162,7 +162,6 @@ 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):
......
#!/usr/bin/env python
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
def make_parser():
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument(
"--outfile",
type=str,
help='output file name',
default='single_binary.mp4'
)
parser.add_argument(
"--m1",
type=float,
help='mass of first object',
default=30.
)
parser.add_argument(
"--m2",
type=float,
help='mass of secondary object',
default = 30.,
)
parser.add_argument(
"--name",
type=str,
help='name to put at the top',
)
return parser
def main():
import json
import sys
parser = make_parser()
args = parser.parse_args()
plt.style.use('dark_background')
fig,ax = plt.subplots(figsize=(5,5))
ax.set_axis_off()
fps = 30.
length = 5.
omega = 30./(args.m1 + args.m2)
# create a Binary instance for the event
binary = Binary(
m1 = args.m1,
m2 = args.m2,
alpha = 45.,
beta = 20.,
gamma = 80.,
omega = omega,
frame_rate = fps
)
# evolve the binary over one orbit
n_frames = int(length*fps)
binary.evolve(n_frames)
# make BBH artist
bbh = BinaryBlackHole(
binary = binary,
ax = ax,
name='orbit',
BH_scale = 1./200
)
artist_dict = {}
def init():
artist_dict.update(bbh.setup_artists())
# configure plot axes, title
ax.set_xlim([-1,1])
ax.set_ylim([-1,1])
if args.name is not None:
print('putting names on events')
ax.set_title(args.name)
return artist_dict
def animate(i):
artist_dict.update(bbh.get_artists(i))
return artist_dict
print(f'saving to {args.outfile}')
anim = animation.FuncAnimation(fig,animate,init_func=init,frames=n_frames)
anim.save(args.outfile,fps=fps,extra_args=['-vcodec', 'libx264'])
if __name__=='__main__':
main()
......@@ -14,6 +14,7 @@ setup(
'bin/animate_binaries_from_file',
'bin/make_event_gifs',
'bin/inspiral_ringdown',
'bin/binary_orbit',
],
packages = [
'twirl',
......
......@@ -56,8 +56,10 @@ class BinaryBlackHole:
)
)
# make sure star that is closer is shown on top of the other
zorder_1 = int(z1>z2)
zorder_2 = ~zorder_1
if z1 > z2:
zorder_1, zorder_2 = 2, 1
else:
zorder_1, zorder_2 = 1, 2
self.artists['{}_m1'.format(self.name)].set_zorder(zorder_1)
self.artists['{}_m2'.format(self.name)].set_zorder(zorder_2)
......@@ -70,8 +72,10 @@ class BinaryBlackHole:
self.artists['{}_m2'.format(self.name)].set_center((x2,y2))
# make sure star that is closer is shown on top of the other
zorder_1 = int(z1>z2)
zorder_2 = ~zorder_1
if z1 > z2:
zorder_1, zorder_2 = 2, 1
else:
zorder_1, zorder_2 = 1, 2
self.artists['{}_m1'.format(self.name)].set_zorder(zorder_1)
self.artists['{}_m2'.format(self.name)].set_zorder(zorder_2)
......
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