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

fixed orbital frequencies, made videos loopable through rounding of orbital...

fixed orbital frequencies, made videos loopable through rounding of orbital frequencies to multiples of the slowest rotating binary, added option for dark background
parent 159928a7
......@@ -16,23 +16,38 @@ def make_parser():
help='json file with median values',
)
parser.add_argument(
"--round",
help="round orbital frequencies so that the movie can seamlessly loop",
action="store_true"
)
parser.add_argument(
"--dark",
help="use dark background",
action="store_true")
return parser
def main():
import json
import sys
import sys
# parse arguments
parser = make_parser()
args = parser.parse_args()
with open(args.file,'r') as json_file:
data = json.load(json_file)
# get number of events and hence number of axes needed
events = list(data.keys())
n_events = len(events)
n_side = int(np.ceil(np.sqrt(n_events)))
n_side2 = int(np.ceil(n_events/float(n_side)))
# make axes
if args.dark:
plt.style.use('dark_background')
fig,ax = plt.subplots(n_side,n_side2,figsize=(10,10))
ax = ax.flatten()
for axi in ax: axi.set_axis_off()
......@@ -41,16 +56,29 @@ def main():
fps = 30. # frames per second
length = 10. # seconds
pos_dict = {}
binary_dict = {}
# determine orbital frequencies
if args.round:
omegas = np.array([1./(data[event]['mass_1_source']['med']
+ data[event]['mass_2_source']['med']
) for event in events
])
omegas = np.round(omegas/np.amin(omegas),0)
omegas = {event : omegas[i]/length for i,event in enumerate(events)}
else:
omegas = {event : 20./(data[event]['mass_1_source']['med']
+ data[event]['mass_2_source']['med']
) for event in events
}
pos_dict = {} # dictionary for all compact object positions
binary_dict = {} # dictionary for all Binary objects
# loop over all events
for event in events:
print('evolving ',event)
event_pos_dict = {}
event_pos_dict = {} # dictionary for positions of this event
m1 = data[event]['mass_1_source']['med']
m2 = data[event]['mass_2_source']['med']
omega = 30.*((m1/((m1+m2)**3.))**(1./2))
# create a Binary instance for the event
binary = Binary(
m1 = m1,
......@@ -60,13 +88,14 @@ def main():
alpha = 45.,
beta = 20.,
gamma = 80.,
omega = omega,
omega = omegas[event],
frame_rate = fps
)
print('omega',binary.omega)
# evolve the binary over one orbit
n_frames = int(length*fps)
# populate positions for event
event_pos_dict = {
var: np.empty(n_frames)
for var in ['x1','y1','z1','x2','y2','z2']
......@@ -86,12 +115,28 @@ def main():
pos_dict[event] = event_pos_dict
binary_dict[event] = binary
artist_dict = {}
artist_dict = {} # dictionary for matplotlib artists
def init():
for ei,event in enumerate(events):
artist_dict['%s_m1'%event] = ax[ei].add_artist(Circle((pos_dict[event]['x1'][0],pos_dict[event]['y1'][0]),radius=binary_dict[event].m1/200,edgecolor='white',facecolor='black'))
artist_dict['%s_m2'%event] = ax[ei].add_artist(Circle((pos_dict[event]['x2'][0],pos_dict[event]['y2'][0]),radius=binary_dict[event].m2/200,edgecolor='white',facecolor='black'))
for ei,event in enumerate(events):
# create artists for both stars
artist_dict['%s_m1'%event] = ax[ei].add_artist(
Circle((pos_dict[event]['x1'][0],pos_dict[event]['y1'][0]),
radius=binary_dict[event].m1/200,
edgecolor='white',
facecolor='black'
)
)
artist_dict['%s_m2'%event] = ax[ei].add_artist(
Circle((pos_dict[event]['x2'][0],pos_dict[event]['y2'][0]),
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(pos_dict[event]['z1'][0]>pos_dict[event]['z2'][0])
zorder_2 = ~zorder_1
artist_dict['%s_m1'%event].set_zorder(zorder_1)
......@@ -104,8 +149,12 @@ def main():
def animate(i):
for ei,event in enumerate(events):
# update positions of stars
artist_dict['%s_m1'%event].set_center((pos_dict[event]['x1'][i],pos_dict[event]['y1'][i]))
artist_dict['%s_m2'%event].set_center((pos_dict[event]['x2'][i],pos_dict[event]['y2'][i]))
# make sure star that is closer is shown on top of the other
if pos_dict[event]['z1'][i]>pos_dict[event]['z2'][i]:
zorder_1 = 2
zorder_2 = 1
......
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