In [4]:
import numpy as np
import matplotlib.pyplot as plt

from matplotlib import animation, rc
from IPython.display import HTML

weights = np.load("./simulated_data/weights_10h.npy")
n_data = weights.shape[0]
N_out_x, N_out_y = 10, 10
N_out = N_out_x * N_out_y

# get a list of frames every 3 minutes
# frames = np.arange(0, n_data, 3)

# get a list of frames of the first hour
frames = np.arange(60)

# get a list of 150 frames exponentially speeding up
# frames = ((np.logspace(0, 1, 150) - 1) / 9 * (n_data - 1))
# frames = frames.astype(np.int)


seconds = 6
framelength = int(seconds * 1000 / frames.size)
weights_resh = weights.reshape(n_data, N_out, 20, 20)


fig, sps = plt.subplots(10, 10)
images = []
for i, sp in enumerate(sps.flat):
    im = sp.imshow(weights_resh[-1, i, ...].squeeze(), interpolation="None", cmap="viridis")
    images.append(im)
    sp.set_xlabel("")
    sp.set_ylabel("")
    sp.set_xticklabels("")
    sp.set_yticklabels("")

fig.set_size_inches(8, 8)
# plt.show()

In [5]:
# animation function.  This is called sequentially

# get color minimum and maximum value from specific frame for all frames
cframe = 60
vmax = np.max(weights[cframe, ...])
vmin = np.min(weights[cframe, ...])
# vmax = np.max(weights)
# vmin = np.min(weights)
def animate(i): 
    # show progress in console
    print(i, end=", ")
    hours = np.floor((i + 1) / 60).astype(np.int)
    minutes = ((i + 1) % 60).astype(np.int)
    fig.suptitle("t = %1ih %.2imin" % (hours, minutes), fontsize=16)
    for j, image in enumerate(images):
        image.set_clim(vmax=vmax, vmin=vmin)
        image.set_array(weights_resh[i, j, ...])
    return images


anim = animation.FuncAnimation(fig, animate, frames=frames, interval=framelength, blit=False)

HTML(anim.to_html5_video())


0, 0, 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, 
Out[5]:

In [3]:
anim.save('./visualisations/weight_change_jet.mp4', fps=15, extra_args=['-vcodec', 'libx264'])


0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19, 21, 22, 24, 25, 26, 28, 29, 31, 32, 34, 36, 37, 39, 40, 42, 44, 46, 47, 49, 51, 53, 55, 56, 58, 60, 62, 64, 66, 68, 71, 73, 75, 77, 79, 82, 84, 86, 89, 91, 94, 96, 99, 101, 104, 106, 109, 112, 115, 118, 120, 123, 126, 129, 132, 135, 139, 142, 145, 148, 152, 155, 159, 162, 166, 169, 173, 177, 180, 184, 188, 192, 196, 200, 205, 209, 213, 217, 222, 226, 231, 236, 240, 245, 250, 255, 260, 265, 270, 275, 281, 286, 292, 297, 303, 309, 315, 320, 326, 333, 339, 345, 352, 358, 365, 371, 378, 385, 392, 399, 407, 414, 422, 429, 437, 445, 453, 461, 469, 477, 486, 494, 503, 512, 521, 530, 540, 549, 559, 568, 578, 588, 599,