Skip to content

Commit 61a5973

Browse files
committed
Merge pull request #133 from christianbrodbeck/movietimes
FIX Brain.save_movie(): prevent greater than possible frame times
2 parents 4edbe61 + b99732f commit 61a5973

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

surfer/viz.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from math import floor
12
import os
23
from os.path import join as pjoin
34
from tempfile import mkdtemp
@@ -2178,19 +2179,16 @@ def save_movie(self, fname, time_dilation=4., tmin=None, tmax=None,
21782179
raise ValueError("tmin=%r is smaller than the first time point "
21792180
"(%r)" % (tmin, self._times[0]))
21802181

2182+
# find indexes at which to create frames
21812183
if tmax is None:
21822184
tmax = self._times[-1]
2183-
elif tmax >= self._times[-1]:
2185+
elif tmax > self._times[-1]:
21842186
raise ValueError("tmax=%r is greater than the latest time point "
21852187
"(%r)" % (tmax, self._times[-1]))
2186-
2187-
# find indexes at which to create frames
2188-
tstep = 1. / (framerate * time_dilation)
2189-
if np.allclose((tmax - tmin) % tstep, 0):
2190-
tstop = tmax + tstep / 2.
2191-
else:
2192-
tstop = tmax
2193-
times = np.arange(tmin, tstop, tstep)
2188+
n_frames = floor((tmax - tmin) * time_dilation * framerate)
2189+
times = np.arange(n_frames)
2190+
times /= framerate * time_dilation
2191+
times += tmin
21942192
interp_func = interp1d(self._times, np.arange(self.n_times))
21952193
time_idx = interp_func(times)
21962194

0 commit comments

Comments
 (0)