Commit 7786b431 authored by Zoheyr Doctor's avatar Zoheyr Doctor 🔭
Browse files

added artists for black holes and ringdowns

parent e143369d
#!/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'])
......@@ -14,12 +14,14 @@ setup(
'bin/animate_binaries_from_file',
'bin/make_event_gifs',
'bin/inspiral_test',
'bin/ringdown_test',
],
packages = [
'twirl',
],
py_modules = [
'twirl.binary',
'twirl.artists',
],
data_files = [],
requires = [])
......
import numpy as np
import twirl.binary
from matplotlib import pyplot as plt
from matplotlib.patches import Ellipse,Circle
class BinaryBlackHoleArtist:
"""
A class to define the matplotlib artists
for a binary black hole.
"""
def __init__(self,
binary,
ax,
name,
BH_scale = 1,
):
"""
Parameters
----------
binary: Binary
An evolved Binary object
ax: axis object
The matplotlib axis to plot the artists on
name: str
unique name of the binary for identification
BH_scale: float
scale of BH on image WRT BH mass in solar masses
Returns
-------
None
"""
self.binary = binary
self.ax = ax
self.name = name
self.BH_scale = BH_scale
self.edgecolor='white',
self.facecolor='black',
self.artists = {}
def setup_artists(self):
z1,x1,y1 = self.binary.pos1_projected[0,:]
z2,x2,y2 = self.binary.pos2_projected[0,:]
self.artists['{}_m1'.format(self.name)] = self.ax.add_artist(
Circle((x1,y1), radius=self.BH_scale*self.binary.m1,
edgecolor=self.edgecolor,
facecolor=self.facecolor
)
)
self.artists['{}_m2'.format(self.name)] = self.ax.add_artist(
Circle((x2,y2), radius=self.BH_scale*self.binary.m2,
edgecolor=self.edgecolor,
facecolor=self.facecolor
)
)
# make sure star that is closer is shown on top of the other
zorder_1 = int(z1>z2)
zorder_2 = ~zorder_1
self.artists['{}_m1'.format(self.name)].set_zorder(zorder_1)
self.artists['{}_m2'.format(self.name)].set_zorder(zorder_2)
return self.artists
def get_artists(self,i):
z1,x1,y1 = self.binary.pos1_projected[i,:]
z2,x2,y2 = self.binary.pos2_projected[i,:]
self.artists['{}_m1'.format(self.name)].set_center((x1,y1))
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
self.artists['{}_m1'.format(self.name)].set_zorder(zorder_1)
self.artists['{}_m2'.format(self.name)].set_zorder(zorder_2)
return self.artists
class BlackHoleRingdown:
def __init__(self,
M,
amplitude0,
omega,
tau,
ax,
name,
BH_scale = 1
):
self.M = M
self.tau = tau
self._amplitude0 = amplitude0
self.omega = omega
self.ax = ax
self.name = name
self.artists = {}
self.BH_scale = BH_scale
def amplitude(self,i):
return self._amplitude0 * np.exp(-i/self.tau) * np.cos(2.*2.*np.pi*i/self.tau)
def get_height_width(self,i):
return 1 + self.amplitude(i), 1 - self.amplitude(i)
def setup_artists(self):
height,width = self.get_height_width(0)
self.artists['{}_ringdown'.format(self.name)] = self.ax.add_artist(
Ellipse((0,0),
self.BH_scale*self.M*height,self.BH_scale*self.M*width,
edgecolor='white',facecolor='black'
)
)
return self.artists
def get_artists(self,i):
height,width = self.get_height_width(i)
self.artists['{}_ringdown'.format(self.name)].height = self.BH_scale*self.M*height
self.artists['{}_ringdown'.format(self.name)].width = self.BH_scale*self.M*width
return self.artists
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