Skip to content

Commit

Permalink
Merge pull request #133 from christianbrodbeck/movietimes
Browse files Browse the repository at this point in the history
FIX Brain.save_movie():  prevent greater than possible frame times
  • Loading branch information
larsoner committed May 11, 2015
2 parents 4edbe61 + b99732f commit 61a5973
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions surfer/viz.py
@@ -1,3 +1,4 @@
from math import floor
import os
from os.path import join as pjoin
from tempfile import mkdtemp
Expand Down Expand Up @@ -2178,19 +2179,16 @@ def save_movie(self, fname, time_dilation=4., tmin=None, tmax=None,
raise ValueError("tmin=%r is smaller than the first time point "
"(%r)" % (tmin, self._times[0]))

# find indexes at which to create frames
if tmax is None:
tmax = self._times[-1]
elif tmax >= self._times[-1]:
elif tmax > self._times[-1]:
raise ValueError("tmax=%r is greater than the latest time point "
"(%r)" % (tmax, self._times[-1]))

# find indexes at which to create frames
tstep = 1. / (framerate * time_dilation)
if np.allclose((tmax - tmin) % tstep, 0):
tstop = tmax + tstep / 2.
else:
tstop = tmax
times = np.arange(tmin, tstop, tstep)
n_frames = floor((tmax - tmin) * time_dilation * framerate)
times = np.arange(n_frames)
times /= framerate * time_dilation
times += tmin
interp_func = interp1d(self._times, np.arange(self.n_times))
time_idx = interp_func(times)

Expand Down

0 comments on commit 61a5973

Please sign in to comment.