Skip to content

Commit

Permalink
Merge pull request #2129 from dengemann/fix_time_sel
Browse files Browse the repository at this point in the history
FIX: precision errors in times plot topomap
  • Loading branch information
larsoner committed May 21, 2015
2 parents 81ce093 + 14599b6 commit 26ea818
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 3 additions & 1 deletion mne/viz/tests/test_topomap.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ def test_plot_topomap():
baseline=(None, 0))
ev_bad = evoked.pick_types(meg=False, eeg=True, copy=True)
ev_bad.pick_channels(ev_bad.ch_names[:2])
ev_bad.plot_topomap() # auto, should plot EEG
ev_bad.plot_topomap(times=ev_bad.times[:2] - 1e-6) # auto, should plot EEG
assert_raises(ValueError, ev_bad.plot_topomap, ch_type='mag')
assert_raises(TypeError, ev_bad.plot_topomap, head_pos='foo')
assert_raises(KeyError, ev_bad.plot_topomap, head_pos=dict(foo='bar'))
assert_raises(ValueError, ev_bad.plot_topomap, head_pos=dict(center=0))
assert_raises(ValueError, ev_bad.plot_topomap, times=[-100]) # bad time
assert_raises(ValueError, ev_bad.plot_topomap, times=[[0]]) # bad time

evoked.plot_topomap(0.1, layout=layout, scale=dict(mag=0.1))
plt.close('all')
Expand Down
13 changes: 9 additions & 4 deletions mne/viz/topomap.py
Original file line number Diff line number Diff line change
Expand Up @@ -1047,14 +1047,19 @@ def plot_evoked_topomap(evoked, times=None, ch_type=None, layout=None,
times = np.linspace(evoked.times[0], evoked.times[-1], 10)
elif np.isscalar(times):
times = [times]
times = np.array(times)
if times.ndim != 1:
raise ValueError('times must be 1D, got %d dimensions' % times.ndim)
if len(times) > 20:
raise RuntimeError('Too many plots requested. Please pass fewer '
'than 20 time instants.')
tmin, tmax = evoked.times[[0, -1]]
for t in times:
if not tmin <= t <= tmax:
raise ValueError('Times should be between %0.3f and %0.3f. (Got '
'%0.3f).' % (tmin, tmax, t))
_time_comp = _time_mask(times=times, tmin=tmin, tmax=tmax)
if not np.all(_time_comp):
raise ValueError('Times should be between {0:0.3f} and {1:0.3f}. (Got '
'{2}).'.format(tmin, tmax,
['%03.f' % t
for t in times[_time_comp]]))

picks, pos, merge_grads, names, ch_type = _prepare_topo_plot(
evoked, ch_type, layout)
Expand Down

0 comments on commit 26ea818

Please sign in to comment.