-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathinteractive.py
68 lines (56 loc) · 2.15 KB
/
interactive.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
""" Interactive widgets for running binaryBHexp
"""
import matplotlib
matplotlib.use("TkAgg")
from matplotlib.widgets import Slider, Button
import matplotlib.pyplot as P
import numpy as np
import binaryBHexp
def run_animation():
q = sl_q.val
chiAmag = sl_chiAmag.val
chiAth = sl_chiAth.val
chiAph = sl_chiAph.val
chiBmag = sl_chiBmag.val
chiBth = sl_chiBth.val
chiBph = sl_chiBph.val
chiA = [chiAmag*np.sin(chiAth)*np.cos(chiAph),
chiAmag*np.sin(chiAth)*np.sin(chiAph),
chiAmag*np.cos(chiAth)]
chiB = [chiBmag*np.sin(chiBth)*np.cos(chiBph),
chiBmag*np.sin(chiBth)*np.sin(chiBph),
chiBmag*np.cos(chiBth)]
ani = binaryBHexp.BBH_animation(fig, q, chiA, chiB, \
wave_time_series=True, auto_rotate_camera=False, \
rescale_fig_for_widgets=True)
return ani
fig = P.figure(figsize=(7,5.5))
axcolor = 'lightgoldenrodyellow'
# axes for sliders
ax_q = P.axes([0.75, 0.8, 0.15, 0.03], facecolor=axcolor)
ax_chiAmag = P.axes([0.75, 0.75, 0.15, 0.03], facecolor=axcolor)
ax_chiAth = P.axes([0.75, 0.70, 0.15, 0.03], facecolor=axcolor)
ax_chiAph = P.axes([0.75, 0.65, 0.15, 0.03], facecolor=axcolor)
ax_chiBmag = P.axes([0.75, 0.60, 0.15, 0.03], facecolor=axcolor)
ax_chiBth = P.axes([0.75, 0.55, 0.15, 0.03], facecolor=axcolor)
ax_chiBph = P.axes([0.75, 0.50, 0.15, 0.03], facecolor=axcolor)
# run button
ax_run = P.axes([0.75, 0.4, 0.1, 0.03])
button = Button(ax_run, 'Run', color=axcolor, hovercolor='0.975')
# define sliders
sl_q = Slider(ax_q, '$q$', 1, 2, valinit=1.34, valstep=0.01)
sl_chiAmag = Slider(ax_chiAmag, '$\chi_1$', 0, 0.8, valinit=0.8, valstep=0.01)
sl_chiAth = Slider(ax_chiAth, '$\\theta_1$', 0, 2*np.pi, valinit=1.1, \
valstep=0.01)
sl_chiAph = Slider(ax_chiAph, '$\phi_1$', -np.pi, np.pi, valinit=-0.4, \
valstep=0.01)
sl_chiBmag = Slider(ax_chiBmag, '$\chi_2$', 0, 0.8, valinit=0.8, valstep=0.01)
sl_chiBth = Slider(ax_chiBth, '$\\theta_2$', 0, 2*np.pi, valinit=1.1, \
valstep=0.01)
sl_chiBph = Slider(ax_chiBph, '$\phi_2$', -np.pi, np.pi, valinit=-0.4, \
valstep=0.01)
def run(event):
global ani
ani = run_animation()
button.on_clicked(run)
P.show()