<jupyter_start><jupyter_text>Animations All the work done below serves to animate the postions of the bodies in my system for each case I consider.  All the actual animations can be viewed in the visualization notebooks for each case.<jupyter_code>%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
from moviepy.video.io.bindings import mplfig_to_npimage
import moviepy.editor as mpy<jupyter_output><empty_output><jupyter_text>Base Question<jupyter_code>f = open('base_question_data.npz','r')
r = np.load('base_question_data.npz')
sol_base = r['arr_0']
ic_base = r['arr_1']
f.close()<jupyter_output><empty_output><jupyter_text>Creating animation with main galaxy as the center:<jupyter_code>duration = 10.0

fig_mpl, ax = plt.subplots(1,figsize=(10,10), facecolor='white')

x = np.zeros(122)
y = np.zeros(122)
for i in range(0,int(len(ic_base)/4)):
    x[i] = sol_base[0][4*i]
    y[i] = sol_base[0][4*i+1]
    

plt.sca(ax)

plt.ylim(-50,50)
plt.xlim(-50,50)

scat = ax.scatter(x, y);

def make_frame_mpl(t):
    newx = np.zeros(122)
    newy = np.zeros(122)
    for i in range(0,121):
        newx[i] = sol_base[10*t][4*i]
        newy[i] = sol_base[10*t][4*i+1]
    scat.set_offsets(np.transpose(np.vstack([newx, newy])))
    return mplfig_to_npimage(fig_mpl)

animation_base = mpy.VideoClip(make_frame_mpl, duration=duration)<jupyter_output><empty_output><jupyter_text>Writing animation to disk:<jupyter_code>animation_base.write_videofile("base_animation.mp4", fps=24)<jupyter_output>[MoviePy] >>>> Building video base_animation.mp4
[MoviePy] Writing video base_animation.mp4
[MoviePy] Done.
[MoviePy] >>>> Video ready: base_animation.mp4<jupyter_text>Creating animation centered around center of mass:<jupyter_code>duration = 10.0

fig_mpl, ax = plt.subplots(1,figsize=(10,10), facecolor='white')

x_com = np.zeros(122)
y_com = np.zeros(122)
S = 1e11
M = 1e11
for i in range(0,int(len(ic_base)/4)):
    cm_x_base = (S*sol_base[0][0])/(M+S)
    cm_y_base = (S*sol_base[0][1])/(M+S)
    x_com[i] = sol_base[0][4*i]-cm_x
    y_com[i] = sol_base[0][4*i+1]-cm_y
    x_com[121] = 0-cm_x_base
    y_com[121] = 0-cm_y_base

plt.sca(ax)

plt.ylim(-100,100)
plt.xlim(-100,100)

scat = ax.scatter(x_com, y_com);

def make_frame_mpl_com(t):
    cm_x_base = (S*sol_base[10*t][0])/(M+S)
    cm_y_base = (S*sol_base[10*t][1])/(M+S)
    newx_com = np.zeros(122)
    newy_com = np.zeros(122)
    for i in range(0,121):
        newx_com[i] = sol_base[10*t][4*i]-cm_x_base
        newy_com[i] = sol_base[10*t][4*i+1]-cm_y_base
        newx_com[121] = 0-cm_x_base
        newy_com[121] = 0-cm_y_base
    scat.set_offsets(np.transpose(np.vstack([newx_com, newy_com])))
    return mplfig_to_npimage(fig_mpl)

animation_base_com = mpy.VideoClip(make_frame_mpl_com, duration=duration)
animation_base_com.write_videofile("base_animation_com.mp4", fps=24)<jupyter_output>[MoviePy] >>>> Building video base_animation_com.mp4
[MoviePy] Writing video base_animation_com.mp4
[MoviePy] Done.
[MoviePy] >>>> Video ready: base_animation_com.mp4<jupyter_text>Additional Question 1<jupyter_code>f = open('additional_1_data.npz','r')
r = np.load('additional_1_data.npz')
sol_add1 = r['arr_0']
ic_add1 = r['arr_1']
f.close()<jupyter_output><empty_output><jupyter_text>Creating animation centered at main galaxy:<jupyter_code>duration = 10.0

fig_mpl, ax = plt.subplots(1,figsize=(10,10), facecolor='white')

x_1 = np.zeros(122)
y_1 = np.zeros(122)
for i in range(0,int(len(ic_add1)/4)):
    x_1[i] = sol_add1[0][4*i]
    y_1[i] = sol_add1[0][4*i+1]
    

plt.sca(ax)

plt.ylim(-50,50)
plt.xlim(-50,50)

scat = ax.scatter(x_1, y_1);

def make_frame_mpl_1(t):
    newx_1 = np.zeros(122)
    newy_1 = np.zeros(122)
    for i in range(0,121):
        newx_1[i] = sol_add1[10*t][4*i]
        newy_1[i] = sol_add1[10*t][4*i+1]
    scat.set_offsets(np.transpose(np.vstack([newx_1, newy_1])))
    return mplfig_to_npimage(fig_mpl)

animation_add1 = mpy.VideoClip(make_frame_mpl_1, duration=duration)
animation_add1.write_videofile("additional_1_animation.mp4", fps=24)<jupyter_output>[MoviePy] >>>> Building video additional_1_animation.mp4
[MoviePy] Writing video additional_1_animation.mp4
[MoviePy] Done.
[MoviePy] >>>> Video ready: additional_1_animation.mp4<jupyter_text>Creating animation around center of mass:<jupyter_code>duration = 10.0

fig_mpl, ax = plt.subplots(1,figsize=(10,10), facecolor='white')

x_com_1 = np.zeros(122)
y_com_1 = np.zeros(122)
S_add1 = (1e11)/3
M_add1 = 1e11
for i in range(0,int(len(ic_add1)/4)):
    cm_x_1 = (S_add1*sol_add1[0][0])/(M_add1+S_add1)
    cm_y_1 = (S_add1*sol_add1[0][1])/(M_add1+S_add1)
    x_com_1[i] = sol_add1[0][4*i]-cm_x_1
    y_com_1[i] = sol_add1[0][4*i+1]-cm_y_1
    x_com_1[121] = 0-cm_x_1
    y_com_1[121] = 0-cm_y_1

plt.sca(ax)

plt.ylim(-100,100)
plt.xlim(-100,100)

scat = ax.scatter(x_com_1, y_com_1);

def make_frame_mpl_com_1(t):
    cm_x_1 = (S_add1*sol_add1[10*t][0])/(M_add1+S_add1)
    cm_y_1 = (S_add1*sol_add1[10*t][1])/(M_add1+S_add1)
    newx_com_1 = np.zeros(122)
    newy_com_1 = np.zeros(122)
    for i in range(0,121):
        newx_com_1[i] = sol_add1[10*t][4*i]-cm_x_1
        newy_com_1[i] = sol_add1[10*t][4*i+1]-cm_y_1
        newx_com_1[121] = 0-cm_x_1
        newy_com_1[121] = 0-cm_y_1
    scat.set_offsets(np.transpose(np.vstack([newx_com_1, newy_com_1])))
    return mplfig_to_npimage(fig_mpl)

animation_1_com = mpy.VideoClip(make_frame_mpl_com_1, duration=duration)
animation_1_com.write_videofile("additional_1_animation_com.mp4", fps=24)<jupyter_output>[MoviePy] >>>> Building video additional_1_animation_com.mp4
[MoviePy] Writing video additional_1_animation_com.mp4
[MoviePy] Done.
[MoviePy] >>>> Video ready: additional_1_animation_com.mp4<jupyter_text>Additional Question 2<jupyter_code>f = open('additional_2_data.npz','r')
r = np.load('additional_2_data.npz')
sol_add2 = r['arr_0']
ic_add2 = r['arr_1']
f.close()<jupyter_output><empty_output><jupyter_text>Creating animation centered around main galaxy:<jupyter_code>duration = 10.0

fig_mpl, ax = plt.subplots(1,figsize=(10,10), facecolor='white')

x_2 = np.zeros(122)
y_2 = np.zeros(122)
for i in range(0,int(len(ic_add2)/4)):
    x_2[i] = sol_add2[0][4*i]
    y_2[i] = sol_add2[0][4*i+1]
    

plt.sca(ax)

plt.ylim(-50,50)
plt.xlim(-50,50)

scat = ax.scatter(x_2, y_2);

def make_frame_mpl_2(t):
    newx_2 = np.zeros(122)
    newy_2 = np.zeros(122)
    for i in range(0,121):
        newx_2[i] = sol_add2[10*t][4*i]
        newy_2[i] = sol_add2[10*t][4*i+1]
    scat.set_offsets(np.transpose(np.vstack([newx_2, newy_2])))
    return mplfig_to_npimage(fig_mpl)

animation_add2 = mpy.VideoClip(make_frame_mpl_2, duration=duration)
animation_add2.write_videofile("additional_2_animation.mp4", fps=24)<jupyter_output>[MoviePy] >>>> Building video additional_2_animation.mp4
[MoviePy] Writing video additional_2_animation.mp4
[MoviePy] Done.
[MoviePy] >>>> Video ready: additional_2_animation.mp4<jupyter_text>Center of mass animation:<jupyter_code>duration = 10.0

fig_mpl, ax = plt.subplots(1,figsize=(10,10), facecolor='white')

x_com_2 = np.zeros(122)
y_com_2 = np.zeros(122)
S_add2 = 1e11
M_add2 = (1e11)/3
for i in range(0,int(len(ic_add2)/4)):
    cm_x_2 = (S_add2*sol_add2[0][0])/(M_add2+S_add2)
    cm_y_2 = (S_add2*sol_add2[0][1])/(M_add2+S_add2)
    x_com_2[i] = sol_add2[0][4*i]-cm_x_2
    y_com_2[i] = sol_add2[0][4*i+1]-cm_y_2
    x_com_2[121] = 0-cm_x_2
    y_com_2[121] = 0-cm_y_2

plt.sca(ax)

plt.ylim(-100,100)
plt.xlim(-100,100)

scat = ax.scatter(x_com_2, y_com_2);

def make_frame_mpl_com_2(t):
    cm_x_2 = (S_add2*sol_add2[10*t][0])/(M_add2+S_add2)
    cm_y_2 = (S_add2*sol_add2[10*t][1])/(M_add2+S_add2)
    newx_com_2 = np.zeros(122)
    newy_com_2 = np.zeros(122)
    for i in range(0,121):
        newx_com_2[i] = sol_add2[10*t][4*i]-cm_x_2
        newy_com_2[i] = sol_add2[10*t][4*i+1]-cm_y_2
        newx_com_2[121] = 0-cm_x_2
        newy_com_2[121] = 0-cm_y_2
    scat.set_offsets(np.transpose(np.vstack([newx_com_2, newy_com_2])))
    return mplfig_to_npimage(fig_mpl)

animation_2_com = mpy.VideoClip(make_frame_mpl_com_2, duration=duration)
animation_2_com.write_videofile("additional_2_animation_com.mp4", fps=24)<jupyter_output>[MoviePy] >>>> Building video additional_2_animation_com.mp4
[MoviePy] Writing video additional_2_animation_com.mp4
[MoviePy] Done.
[MoviePy] >>>> Video ready: additional_2_animation_com.mp4
{'fraction_non_alphanumeric': 0.1566897209635106, 'fraction_numerical': 0.07226329596947294, 'mean_word_length': 5.491486068111455, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 87, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '263674', 'license': 'MIT', 'n_tokens_mistral': 4176, 'n_tokens_neox': 3869, 'n_words': 529, 'path': 'galaxy_project/H) Animator.ipynb', 'repo_name': 'bjshaw/phys202-project', 'size': '8386'}