diff --git a/mne/beamformer/tests/test_lcmv.py b/mne/beamformer/tests/test_lcmv.py index d92c60a111d..56cb2d86203 100644 --- a/mne/beamformer/tests/test_lcmv.py +++ b/mne/beamformer/tests/test_lcmv.py @@ -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 diff --git a/mne/cov.py b/mne/cov.py index cb80013b7d1..d2d6e7e1c06 100644 --- a/mne/cov.py +++ b/mne/cov.py @@ -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) diff --git a/mne/source_estimate.py b/mne/source_estimate.py index 2051d72a923..cab78d88295 100644 --- a/mne/source_estimate.py +++ b/mne/source_estimate.py @@ -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] diff --git a/mne/utils.py b/mne/utils.py index 5155257bc40..884b3406960 100644 --- a/mne/utils.py +++ b/mne/utils.py @@ -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 diff --git a/mne/viz/tests/test_topomap.py b/mne/viz/tests/test_topomap.py index 6c2bdece21e..c11808b274a 100644 --- a/mne/viz/tests/test_topomap.py +++ b/mne/viz/tests/test_topomap.py @@ -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')) diff --git a/mne/viz/topomap.py b/mne/viz/topomap.py index 247873c8c38..d73771de4f4 100644 --- a/mne/viz/topomap.py +++ b/mne/viz/topomap.py @@ -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) @@ -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)