Skip to content

Commit

Permalink
ENH: Expose origin parameter (mne-tools#5588)
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner authored and agramfort committed Oct 7, 2018
1 parent c5b43b0 commit e648023
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
2 changes: 2 additions & 0 deletions doc/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`_
Expand Down
10 changes: 8 additions & 2 deletions mne/channels/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 <tut_logging>`
Expand All @@ -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'] = []
Expand Down
9 changes: 7 additions & 2 deletions mne/channels/interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <tut_logging>` for more).
Expand All @@ -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)
4 changes: 2 additions & 2 deletions mne/channels/tests/test_interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
19 changes: 10 additions & 9 deletions mne/forward/_field_interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------
Expand Down Expand Up @@ -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 <tut_logging>` for more).
Expand Down Expand Up @@ -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 <tut_logging>` for more).
.. versionadded:: 0.11
Returns
-------
surf_maps : list
Expand Down

0 comments on commit e648023

Please sign in to comment.