forked from bernhardkaplan/bcpnn-mt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dynamic_image.py
executable file
·74 lines (64 loc) · 2.2 KB
/
dynamic_image.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
69
70
71
72
73
74
#!/usr/bin/env python
"""
An animated image
"""
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import simulation_parameters
#import pylab
import utils
PS = simulation_parameters.parameter_storage()
params = PS.params
n_cells = params['n_exc']
fn = params['tuning_prop_means_fn']
tp = np.loadtxt(fn)
plt.rcParams['lines.markeredgewidth'] = 0
iteration = 4
motion_params_fn = params['parameters_folder'] + 'input_params.txt'
all_mp = np.loadtxt(motion_params_fn)
mp = all_mp[iteration, :]
activity_fn = params['activity_folder'] + 'output_activity_%d.dat' % (iteration)
activity = np.loadtxt(activity_fn)
activity_max = activity.max()
activity_min = activity.min()
scale = 1 / 10.
def paint_dots(num, pos, colors):
print 'Frame:', num
fig1.clear()
dots = []
for i in xrange(pos[:, 0].size):
c = colors[num, i, :]
# l, = plt.plot(pos[i, 0], pos[i, 1], 'o', c=c)
l = plt.quiver(tp[i, 0], tp[i, 1], scale * tp[i, 2], scale * tp[i, 3], angles='xy', scale_units='xy', scale=1, color=c, headwidth=1)
dots.append(l)
l = plt.quiver(mp[0], mp[1], mp[2], mp[3], angles='xy', scale_units='xy', scale=1, color='k', headwidth=4)
dots.append(l)
l = plt.annotate('Stimulus', (mp[0]+.5*mp[2], mp[1]+0.1), fontsize=12, color='k')
dots.append(l)
return dots
fig1 = plt.figure()
n_frames = activity[:, 0].size
pos = np.zeros((n_cells, 2))
pos[:, 0], pos[:, 1] = tp[:, 0], tp[:, 1]
colors = np.zeros((n_frames, n_cells, 3))
s = 1. # saturation
for frame in xrange(n_frames):
for cell in xrange(n_cells):
if activity[frame, cell] < 0:
l = 1. - 0.5 * activity[frame, cell] / activity_min
h = 0.
else:
l = 1. - 0.5 * activity[frame, cell] / activity_max
h = 240.
assert (0 <= h and h < 360)
assert (0 <= l and l <= 1)
assert (0 <= s and s <= 1)
(r, g, b) = utils.convert_hsl_to_rgb(h, s, l)
colors[frame, cell, :] = [r, g, b]
dot_ani = animation.FuncAnimation(fig1, paint_dots, n_frames, fargs=(pos, colors), interval=50, blit=True)
output_fn = 'dynamic_images.mp4'
print 'Saving movie', output_fn
dot_ani.save(output_fn)
print 'Finished'
#plt.show()