-
Notifications
You must be signed in to change notification settings - Fork 0
/
2022-12-23_video-abstract.py
261 lines (203 loc) · 10.2 KB
/
2022-12-23_video-abstract.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
"""
# 2022-12-23_video-abstract
Using the template @ https://laurentperrinet.github.io/sciblog/posts/2019-09-11_video-abstract-vision.html
and using that @ https://github.com/chloepasturel/AnticipatorySPEM/blob/master/2020-03_video-abstract/2020-03-24_video-abstract.ipynb
cp 2022-12-23_polychrony-review_video-abstract.mp4 /Users/laurentperrinet/metagit/blog/hugo_academic/content/publication/grimaldi-22-polychronies/
"""
# Creating the movie using the (*excellent*) [MoviePy](http://zulko.github.io/moviepy/index.html) library:
videoname = "2022-12-23_polychrony-review_video-abstract"
gifname = videoname + ".gif"
gifname = None
fps = 30
from moviepy.editor import VideoFileClip, ImageClip, TextClip, CompositeVideoClip
H, W = 500, 800
H_fig, W_fig = int(H-H/(1.618*3)), int(W-W/(1.618*3))
opt_t = dict(font="Arial", size=(W,H), method='caption')
opt_st = dict(font="Arial", size=(W,H), method='caption')
# opt_t = dict(size=(W,H), method='caption')
# opt_st = dict(size=(W,H), method='caption')
clip = []
t = 0
#################################################################################
# TITRE
#################################################################################
#
texts = ["""Precise spiking motifs in neurobiological and neuromorphic data
""", """Precise spiking motifs in neurobiological and neuromorphic data
Grimaldi, Gruel, Besnainou,
Jérémie, Martinet, and Perrinet
""", """Precise spiking motifs in neurobiological and neuromorphic data
Grimaldi, Gruel, Besnainou,
Jérémie, Martinet, and Perrinet
Brain Sciences (2022)
"""]
txt_opts = dict(align='center', color='white', **opt_t) #stroke_color='gray', stroke_width=.5
duration = 1.5
for text in texts:
txt = TextClip(text, fontsize=35, **txt_opts).set_start(t).set_duration(duration)
t += duration
clip.append(txt)
#################################################################################
# INTRO
#################################################################################
intro_subs = ["""
The majority of information passing
in the brain is mediated by all-or-none events,
""", """
The majority of information passing
in the brain is mediated by all-or-none events,
*spikes*.
""", """
The majority of information passing
in the brain is mediated by all-or-none events,
*spikes*.
We review here novel evidence for the
role of their precise timing from
neurobiological and neuromorphic data.
"""]
sub_opts = dict(fontsize=32, align='center', color='white', **opt_t)
sub_durations = [1.5, 1.5, 2.5]
for subtitle, sub_duration in zip(intro_subs, sub_durations):
sub = TextClip(subtitle, **sub_opts).set_start(t).set_duration(sub_duration)
t += sub_duration
clip.append(sub)
clip.append(sub) # another bit on the last bit
#################################################################################
#################################################################################
chapters = [dict(title="Visual system", color='green',
content=[dict(figure='figures/visual-latency_bg.jpg', duration=3, subtitle=[
"The visual system is very efficient in generating a...",
"...decision from the retinal image to the different ..."]),
dict(figure='figures/visual-latency.jpg', duration=3, subtitle=[
"...stages of the visual pathways, here a reaction...",
"...of finger muscles in about 300 milliseconds."]),
dict(figure='/Users/laurentperrinet/metagit/ABCD/AG_figures/animated_neurons/LIF.mp4', duration=5, subtitle=[
"It is thought that this efficiency is achieved by spikes...",
"...that is, brief all-or-none events which are passed...",
"...in the very large network which forms the brain...",
"...from assemblies of neurons to others."])]),
dict(title="Polychrony", color='orange',
content=[dict(figure='figures/izhikevich.png', duration=5, subtitle=[
"We review here an hypothesis in which, rather than the...",
"...firing frequency of spikes, it is their precise timing...",
"...which would allow or not this message passing."]),
dict(figure='figures/THC_1a_k.png', duration=3, subtitle=[
"We present different mathematical models for extracting...",
"...such precise spiking motifs and..."]),
dict(figure='figures/THC_1a.png', duration=5, subtitle=[
"...also some novel tools for extracting these motifs...",
"...in arbitrary raster plots from neurobiology...",
"...or neuromorphic engineering."])]),
dict(title="Neurobiology", color='red',
content=[dict(figure='figures/haimerl2019.jpg', duration=5, subtitle=[
"This hypothesis is reviewed with respect to our ...",
"...knowledge of the neurobiology, for instance in the...",
"...hippocampus of rodents. We also review..."]),
dict(figure='figures/Ikegaya2004zse0150424620001.jpeg', duration=5, subtitle=[
"...numerous and extensive work on mechanisms...",
"...which may allow the neural system to learn...",
"...to actually use that precise spiking motifs",
"...by attuning the delay between pairs of neurons."])]),
dict(title="Neuromorphic", color='blue',
content=[dict(figure='figures/event_driven_computations.png', duration=5, subtitle=[
"We also review evidence from computational neuroscience...",
"...and neuromorphic engineering, in particular for novel...",
"...device such as event-based cameras which directly...",
"...transform lumnious information into spikes."]),
dict(figure='/Users/laurentperrinet/metagit/ABCD/pyTERtorch/2022-11-30_BiolCybernetics/figures/2022-11-10_MotionDetection_input.mp4', duration=5, subtitle=[
"For instance, we show how precise spike times may be...",
"...used to detect the direction of motion from such...",
"...a stream of events in an ultrafast fashion."])]),
]
# http://zulko.github.io/moviepy/ref/VideoClip/VideoClip.html?highlight=compositevideoclip#textclip
txt_opts = dict(fontsize=65, bg_color='white', align='center', **opt_st)
sub_opts = dict(fontsize=28, align='South', color='white', **opt_st)
for chapter in chapters:
duration = 1
txt = TextClip(chapter['title'], color=chapter['color'], **txt_opts).set_start(t).set_duration(duration)
t += duration
clip.append(txt)
for content in chapter['content']:
# set the figure
figname = content['figure']
duration = content['duration']
if figname[-4:]=='.mp4' :
img = VideoFileClip(figname, audio=False)
print(figname, '--> duration:', img.duration, ', fps:', img.fps)
# duration = img.duration
else:
img = ImageClip(figname)
H_clip, W_clip, three = img.get_frame(0).shape
if H_clip/W_clip > H_fig/W_fig: # portrait-like
img = img.resize(height=H_fig)
else: # landscape-like
img = img.resize(width=W_fig)
img = img.set_duration(duration)
img = img.set_start(t).set_pos('center')#.resize(height=H_fig, width=W_fig)
t += duration
clip.append(img)
# write the subtitles
t_sub = t - duration
sub_duration = duration / len(content['subtitle'])
for subtitle in content['subtitle']:
sub = TextClip(subtitle, **sub_opts).set_start(t_sub).set_duration(sub_duration)
t_sub += sub_duration
clip.append(sub)
#################################################################################
#################################################################################
#################################################################################
# OUTRO
#################################################################################
texts = ["""
Overall, this manuscript reviews the potential
of using precise spiking motifs to design
""",
"""
Overall, this manuscript reviews the potential
of using precise spiking motifs to design
more efficient machine learning algorithms,
that is, faster and more energy-frugal,
""",
"""
Overall, this manuscript reviews the potential
of using precise spiking motifs to design
more efficient machine learning algorithms,
that is, faster and more energy-frugal,
but also to better understand
neurobiological processes and their disorders...
"""]
txt_opts = dict(fontsize=30, align='center', **opt_t)
duration = 3
for text in texts:
txt = TextClip(text, color='white', **txt_opts).set_start(t).set_duration(duration)
t += duration
clip.append(txt)
# FIN
texts = ["""
For more info, and the full, open-sourced code... visit
""", """
For more info, and the full, open-sourced code... visit
https://laurentperrinet.github.io/publication/grimaldi-22-polychronies
""",
]
txt_opts = dict(align='center', **opt_t)
duration = 2.5
for text in texts:
txt = TextClip(text, color='orange', fontsize=26, **txt_opts).set_start(t).set_duration(duration)
t += duration
clip.append(txt)
# QRCODE
#
# qrencode -o figures/qrcode.png -d 200 https://laurentperrinet.github.io/publication/grimaldi-22-polychronies
img = ImageClip('figures/qrcode.png').set_duration(duration)
img = img.resize(width=(W_fig*2)//3).set_start(t).set_pos('center')
clip.append(img)
#################################################################################
# COMPOSITING
#################################################################################
video = CompositeVideoClip(clip)
video.write_videofile(videoname + '.mp4', fps=fps)
if not(gifname is None):
video.write_gif(gifname, fps=fps)
from pygifsicle import optimize
optimize(gifname)