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

made preliminary animator

parent 98be41b9
#!/usr/bin/env python
import numpy as np
from twirl.binary import Binary
from matplotlib import pyplot as plt
from matplotlib import animation
binary = Binary(
m1 = 10.,
m2 = 10.,
c1 = 'k',
c2 = 'k',
alpha = 45.,
beta = 20.,
gamma = 80.
)
x1 = []
y1 = []
x2 = []
y2 = []
for i in range(100):
binary.orbit()
pos1,pos2 = binary.project()
x1.append(pos1[1])
y1.append(pos1[2])
x2.append(pos2[1])
y2.append(pos2[2])
fig,ax = plt.subplots()
pt1, = ax.plot([],[],color='r',markersize=20)
def init():
pt1.set_data([],[])
return pt1,
def animate(i):
pt1.set_data([x1[i],x2[i]],[y1[i],y2[i]])
anim = animation.FuncAnimation(fig,animate,init_func=init,frames=100)
anim.save('/home/zoheyr.doctor/public_html/random/orbit.mp4',fps=30,extra_args=['-vcodec', 'libx264'])
......@@ -6,7 +6,7 @@ from distutils.core import setup
setup(
name='Twirl',
version='0.1',
url='https://git.ligo.org/zoheyr-doctor/cartoon-binary-animation',
url='https://git.ligo.org/zoheyr-doctor/twirl',
author = __author__,
author_email = 'zoheyr.doctor@ligo.org',
description = __description__,
......@@ -14,12 +14,10 @@ setup(
'bin/animate_binaries_from_file',
],
packages = [
'cartoon_binary_animation',
'twirl',
],
py_modules = [
'cartoon_binary_animation.waveform_utils',
'gp_rom.svd_utils',
'gp_rom.gp_utils',
'twirl.binary',
],
data_files = [],
requires = [])
......
......@@ -3,14 +3,14 @@ import numpy as np
class Binary:
def __init__(self,
r1=10.,
r2=10.,
m1=10.,
m2=10.,
c1='black',
c2='black',
inclination=50.,
azimuth=30.,
phase=0.,
frame_rate = 30.
alpha=50.,
beta=30.,
gamma=0.,
frame_rate = 30.,
omega = 2.
):
"""
......@@ -42,12 +42,15 @@ class Binary:
self.alpha = alpha
self.beta = beta
self.gamma = gamma
self.omega = omega
self.frame_rate = frame_rate
self.precession='off'
self._phase1 = self.gamma_rad
self._D = np.identity(3)
self._C = np.identity(3)
self._B = np.identity(3)
@property
def alpha_rad(self):
return self.alpha*np.pi/180.
......@@ -73,27 +76,27 @@ class Binary:
return self.phase1+np.pi
def orbit(self):
self.phase1 = self.phase1 + self.omega/self.frame_rate
self.phase1 = self.phase1 + 2.*np.pi*self.omega/self.frame_rate
@property
def Dmatrix(self):
self._D[0,0] = self._D[1,1] = np.cos(self.alpha*np.pi/180..)
self._D[1,0] = -np.sin(self.alpha*np.pi/180.)
self._D[0,1] = np.sin(self.alpha*np.pi/180.)
self._D[0,0] = self._D[1,1] = np.cos(self.alpha_rad)
self._D[1,0] = -np.sin(self.alpha_rad)
self._D[0,1] = np.sin(self.alpha_rad)
return self._D
@property
def Cmatrix(self):
self._C[1,1] = self._C[2,2] = np.cos(self.beta*np.pi/180.)
self._C[2,1] = -np.sin(self.beta*np.pi/180.)
self._C[1,2] = np.sin(self.beta*np.pi/180.)
self._C[1,1] = self._C[2,2] = np.cos(self.beta_rad)
self._C[2,1] = -np.sin(self.beta_rad)
self._C[1,2] = np.sin(self.beta_rad)
return self._C
@property
def Bmatrix(self):
self._B[0,0] = self._B[1,1] = np.cos(self.gamma*np.pi/180..)
self._B[1,0] = -np.sin(self.gamma*np.pi/180.)
self._B[0,1] = np.sin(self.gamma*np.pi/180.)
self._B[0,0] = self._B[1,1] = np.cos(self.gamma_rad)
self._B[1,0] = -np.sin(self.gamma_rad)
self._B[0,1] = np.sin(self.gamma_rad)
return self._B
@property
......@@ -105,6 +108,11 @@ class Binary:
"""
position of primary in XYZ coordinates of binary plane
"""
return np.array([np.cos(self.phase1),np.sin(self.phase1),0])
@property
def pos2(self):
return np.array([np.cos(self.phase2),np.sin(self.phase2),0])
def project(self):
return np.matmul(self.Amatrix,self.pos1),np.matmul(self.Amatrix,self.pos2)
class Single:
"""
A class to define single stars.
"""
def __init__(self,
r1,
r2,
chi=None,
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