Skip to content

Commit

Permalink
Consistency for loose time mask.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeilepp committed Feb 2, 2016
1 parent 07a42c2 commit 004b8b8
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion mne/beamformer/tests/test_lcmv.py
Expand Up @@ -83,7 +83,7 @@ def _get_data(tmin=-0.1, tmax=0.15, all_forward=True, epochs=True,
eeg=0.1, proj=True)
if data_cov:
with warnings.catch_warnings(record=True):
data_cov = mne.compute_covariance(epochs, tmin=0.04, tmax=0.15)
data_cov = mne.compute_covariance(epochs, tmin=0.04, tmax=0.145)
else:
data_cov = None

Expand Down
2 changes: 1 addition & 1 deletion mne/cov.py
Expand Up @@ -51,7 +51,7 @@ def _check_covs_algebra(cov1, cov2):

def _get_tslice(epochs, tmin, tmax):
"""get the slice."""
mask = _time_mask(epochs.times, tmin, tmax, strict=True)
mask = _time_mask(epochs.times, tmin, tmax, sfreq=epochs.info['sfreq'])
tstart = np.where(mask)[0][0] if tmin is not None else None
tend = np.where(mask)[0][-1] + 1 if tmax is not None else None
tslice = slice(tstart, tend, None)
Expand Down
3 changes: 1 addition & 2 deletions mne/source_estimate.py
Expand Up @@ -494,8 +494,7 @@ def crop(self, tmin=None, tmax=None):
tmax : float | None
The last time point in seconds. If None the last present is used.
"""
mask = _time_mask(self.times, tmin, tmax, strict=True,
sfreq=self.sfreq)
mask = _time_mask(self.times, tmin, tmax, sfreq=self.sfreq)
self.tmin = self.times[np.where(mask)[0][0]]
if self._kernel is not None and self._sens_data is not None:
self._sens_data = self._sens_data[:, mask]
Expand Down
4 changes: 2 additions & 2 deletions mne/utils.py
Expand Up @@ -1884,9 +1884,9 @@ def _time_mask(times, tmin=None, tmax=None, strict=False, sfreq=None):
else:
tmax = times[-1]
deltas = np.abs(times - tmax) # Find nearest times
tmax = times.flat[np.where(deltas == deltas.min())[0]][-1]
tmax = times[np.where(deltas == deltas.min())[0]][-1]
deltas = np.abs(times - tmin)
tmin = times.flat[np.where(deltas == deltas.min())[0]][-1]
tmin = times[np.where(deltas == deltas.min())[0]][-1]
mask = (times >= tmin)
mask &= (times <= tmax)
return mask
Expand Down
2 changes: 1 addition & 1 deletion mne/viz/tests/test_topomap.py
Expand Up @@ -68,7 +68,7 @@ def test_plot_topomap():

ev_bad = evoked.pick_types(meg=False, eeg=True, copy=True)
ev_bad.pick_channels(ev_bad.ch_names[:2])
ev_bad.plot_topomap(times=ev_bad.times[1:3] - 1e-6) # auto, plots EEG
ev_bad.plot_topomap(times=ev_bad.times[:2] - 1e-6) # auto, plots 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'))
Expand Down
5 changes: 3 additions & 2 deletions mne/viz/topomap.py
Expand Up @@ -1126,7 +1126,9 @@ def plot_evoked_topomap(evoked, times="auto", ch_type=None, layout=None,
times = _process_times(evoked, times, n_peaks=len(axes))
else:
times = _process_times(evoked, times, n_peaks=None)
if max(times) > evoked.times[-1] or min(times) < evoked.times[0]:
space = 1 / (2. * evoked.info['sfreq'])
if (max(times) > max(evoked.times) + space or
min(times) < min(evoked.times) - space):
raise ValueError('Times should be between {0:0.3f} and '
'{1:0.3f}.'.format(evoked.times[0], evoked.times[-1]))
n_times = len(times)
Expand All @@ -1147,7 +1149,6 @@ def plot_evoked_topomap(evoked, times="auto", ch_type=None, layout=None,
'or turn it off with colorbar=False.')
if len(axes) != n_times:
raise RuntimeError('Axes and times must be equal in sizes.')
tmin, tmax = evoked.times[[0, -1]]

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

0 comments on commit 004b8b8

Please sign in to comment.