Skip to content

Commit 82b0209

Browse files
FIX Brain.save_movie(): prevent greater than possible frame times
np.arange() sometimes returns values larger than `stop` due to floating point round-off, which becomes relevant with large `time_dilation` values.
1 parent 4edbe61 commit 82b0209

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,5 +1,6 @@
11
import os
22
from os.path import join as pjoin
3+
import sys
34
from tempfile import mkdtemp
45
from warnings import warn
56

@@ -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
2183+
tstep = 1. / (framerate * time_dilation)
21812184
if tmax is None:
21822185
tmax = self._times[-1]
2183-
elif tmax >= self._times[-1]:
2186+
elif tmax > self._times[-1]:
21842187
raise ValueError("tmax=%r is greater than the latest time point "
21852188
"(%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)
2189+
times = np.arange(tmin, tmax + sys.float_info.epsilon, tstep)
2190+
while times[-1] > tmax:
2191+
times = times[:-1]
21942192
interp_func = interp1d(self._times, np.arange(self.n_times))
21952193
time_idx = interp_func(times)
21962194

0 commit comments

Comments
 (0)