diff --git a/doc/whats_new.rst b/doc/whats_new.rst index c0522b7cc99..269ca3aa743 100644 --- a/doc/whats_new.rst +++ b/doc/whats_new.rst @@ -57,6 +57,8 @@ Changelog - Add `split_naming` parameter to the `Raw.save` method to allow for BIDS-compatible raw file name construction by `Teon Brooks`_ +- Add ``origin`` parameter to :meth:`mne.Evoked.interpolate_bads` and related methods by `Eric Larson`_ + - Add capability to save a :class:`mne.Report` to an HDF5 file to :meth:`mne.Report.save` by `Marijn van Vliet`_ - Add :func:`mne.open_report` to read back a :class:`mne.Report` object that was saved to an HDF5 file by `Marijn van Vliet`_ diff --git a/mne/channels/channels.py b/mne/channels/channels.py index 0be7217d88e..dc38eb005a8 100644 --- a/mne/channels/channels.py +++ b/mne/channels/channels.py @@ -888,7 +888,7 @@ class InterpolationMixin(object): @verbose def interpolate_bads(self, reset_bads=True, mode='accurate', - verbose=None): + origin=(0., 0., 0.04), verbose=None): """Interpolate bad MEG and EEG channels. Operates in place. @@ -901,6 +901,12 @@ def interpolate_bads(self, reset_bads=True, mode='accurate', Either ``'accurate'`` or ``'fast'``, determines the quality of the Legendre polynomial expansion used for interpolation of MEG channels. + origin : array-like, shape (3,) | str + Origin of the sphere in the head coordinate frame and in meters. + Can be ``'auto'``, which means a head-digitization-based origin + fit. Default is ``(0., 0., 0.04)``. + + .. versionadded:: 0.17 verbose : bool, str, int, or None If not None, override default verbose level (see :func:`mne.verbose` and :ref:`Logging documentation ` @@ -924,7 +930,7 @@ def interpolate_bads(self, reset_bads=True, mode='accurate', return self _interpolate_bads_eeg(self) - _interpolate_bads_meg(self, mode=mode) + _interpolate_bads_meg(self, mode=mode, origin=origin) if reset_bads is True: self.info['bads'] = [] diff --git a/mne/channels/interpolation.py b/mne/channels/interpolation.py index 9c6fdafa235..3da3ca40932 100644 --- a/mne/channels/interpolation.py +++ b/mne/channels/interpolation.py @@ -156,7 +156,8 @@ def _interpolate_bads_eeg(inst, verbose=None): @verbose -def _interpolate_bads_meg(inst, mode='accurate', verbose=None): +def _interpolate_bads_meg(inst, mode='accurate', origin=(0., 0., 0.04), + verbose=None): """Interpolate bad channels from data in good channels. Parameters @@ -167,6 +168,10 @@ def _interpolate_bads_meg(inst, mode='accurate', verbose=None): Either `'accurate'` or `'fast'`, determines the quality of the Legendre polynomial expansion used for interpolation. `'fast'` should be sufficient for most applications. + origin : array-like, shape (3,) | str + Origin of the sphere in the head coordinate frame and in meters. + Can be ``'auto'``, which means a head-digitization-based origin + fit. Default is ``(0., 0., 0.04)``. verbose : bool, str, int, or None If not None, override default verbose level (see :func:`mne.verbose` and :ref:`Logging documentation ` for more). @@ -192,5 +197,5 @@ def _interpolate_bads_meg(inst, mode='accurate', verbose=None): inst_info['comps'] = [] info_from = pick_info(inst_info, picks_good) info_to = pick_info(inst_info, picks_bad) - mapping = _map_meg_channels(info_from, info_to, mode=mode) + mapping = _map_meg_channels(info_from, info_to, mode=mode, origin=origin) _do_interp_dots(inst, mapping, picks_good, picks_bad) diff --git a/mne/channels/tests/test_interpolation.py b/mne/channels/tests/test_interpolation.py index 9cb3eb91cd4..166059577b6 100644 --- a/mne/channels/tests/test_interpolation.py +++ b/mne/channels/tests/test_interpolation.py @@ -145,10 +145,10 @@ def test_interpolation(): assert np.corrcoef(data1, data2)[0, 1] > thresh assert len(epochs_meg.info['bads']) == 0 - # MEG -- evoked + # MEG -- evoked (plus auto origin) data1 = evoked.data[pick] evoked.info.normalize_proj() - data2 = evoked.interpolate_bads().data[pick] + data2 = evoked.interpolate_bads(origin='auto').data[pick] assert np.corrcoef(data1, data2)[0, 1] > thresh diff --git a/mne/forward/_field_interpolation.py b/mne/forward/_field_interpolation.py index 356569b8dad..be6b0d23714 100644 --- a/mne/forward/_field_interpolation.py +++ b/mne/forward/_field_interpolation.py @@ -118,6 +118,10 @@ def _map_meg_channels(info_from, info_to, mode='fast', origin=(0., 0., 0.04)): Either `'accurate'` or `'fast'`, determines the quality of the Legendre polynomial expansion used. `'fast'` should be sufficient for most applications. + origin : array-like, shape (3,) | str + Origin of the sphere in the head coordinate frame and in meters. + Can be ``'auto'``, which means a head-digitization-based origin + fit. Default is ``(0., 0., 0.04)``. Returns ------- @@ -239,9 +243,9 @@ def _make_surface_mapping(info, surf, ch_type='meg', trans=None, mode='fast', n_jobs : int Number of permutations to run in parallel (requires joblib package). origin : array-like, shape (3,) | str - Origin of internal and external multipolar moment space in head - coords and in meters. The default is ``'auto'``, which means - a head-digitization-based origin fit. + Origin of the sphere in the head coordinate frame and in meters. + The default is ``'auto'``, which means a head-digitization-based + origin fit. verbose : bool, str, int, or None If not None, override default verbose level (see :func:`mne.verbose` and :ref:`Logging documentation ` for more). @@ -363,20 +367,17 @@ def make_field_map(evoked, trans='auto', subject=None, subjects_dir=None, Should be ``'helmet'`` or ``'head'`` to specify in which surface to compute the MEG field map. The default value is ``'helmet'`` origin : array-like, shape (3,) | str - Origin of internal and external multipolar moment space in head - coords and in meters. Can be ``'auto'``, which means - a head-digitization-based origin fit. Default is ``(0., 0., 0.04)``. + Origin of the sphere in the head coordinate frame and in meters. + Can be ``'auto'``, which means a head-digitization-based origin + fit. Default is ``(0., 0., 0.04)``. .. versionadded:: 0.11 - n_jobs : int The number of jobs to run in parallel. verbose : bool, str, int, or None If not None, override default verbose level (see :func:`mne.verbose` and :ref:`Logging documentation ` for more). - .. versionadded:: 0.11 - Returns ------- surf_maps : list