Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MRG, FIX: Fix get_channel_types #7878

Merged
merged 1 commit into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/changes/latest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ Bug

- Fix bug with :func:`mne.bem.make_watershed_bem` where the RAS coordinates of watershed bem surfaces were not updated correctly from the volume file by `Yu-Han Luo`_

- Fix bug with :meth:`mne.io.Raw.get_channel_types` and related methods where the ordering of ``picks`` was not preserved, by `Eric Larson`_

- Fix bug with :meth:`mne.io.Raw.plot_psd` with ``average=False`` and multiple channel types where channel locations were not shown properly by `Eric Larson`_

- Fix bug in FieldTrip reader functions when channels are missing in the ``info`` object by `Thomas Hartmann`_

- Throw proper error when trying to import FieldTrip Epochs data with non-uniform time for trials by `Thomas Hartmann`_
Expand Down
3 changes: 1 addition & 2 deletions mne/io/pick.py
Original file line number Diff line number Diff line change
Expand Up @@ -1141,8 +1141,7 @@ def _get_channel_types(info, picks=None, unique=False, only_data_chs=False):
"""Get the data channel types in an info instance."""
none = 'data' if only_data_chs else 'all'
picks = _picks_to_idx(info, picks, none, (), allow_empty=False)
ch_types = [channel_type(info, idx) for idx in range(info['nchan'])
if idx in picks]
ch_types = [channel_type(info, pick) for pick in picks]
if only_data_chs:
ch_types = [ch_type for ch_type in ch_types
if ch_type in _DATA_CH_TYPES_SPLIT]
Expand Down
26 changes: 22 additions & 4 deletions mne/io/tests/test_pick.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from copy import deepcopy
import inspect
import os.path as op

from numpy.testing import assert_array_equal, assert_equal
Expand All @@ -21,14 +20,14 @@
from mne.datasets import testing
from mne.utils import run_tests_if_main, catch_logging, assert_object_equal

io_dir = op.join(op.dirname(inspect.getfile(inspect.currentframe())), '..')
data_path = testing.data_path(download=False)
fname_meeg = op.join(data_path, 'MEG', 'sample',
'sample_audvis_trunc-meg-eeg-oct-4-fwd.fif')
fname_mc = op.join(data_path, 'SSS', 'test_move_anon_movecomp_raw_sss.fif')

base_dir = op.join(op.dirname(__file__), 'data')
ctf_fname = op.join(base_dir, 'test_ctf_raw.fif')
io_dir = op.join(op.dirname(__file__), '..')
ctf_fname = op.join(io_dir, 'tests', 'data', 'test_ctf_raw.fif')
fif_fname = op.join(io_dir, 'tests', 'data', 'test_raw.fif')


def _picks_by_type_old(info, meg_combined=False, ref_meg=False,
Expand Down Expand Up @@ -570,4 +569,23 @@ def test_pick_types_deprecation():
assert list(pick_types(info2, eeg=True)) == [0, 1]


@pytest.mark.parametrize('meg', [True, False, 'grad', 'mag'])
@pytest.mark.parametrize('eeg', [True, False])
@pytest.mark.parametrize('ordered', [True, False])
def test_get_channel_types_equiv(meg, eeg, ordered):
"""Test equivalence of get_channel_types."""
raw = read_raw_fif(fif_fname)
pick_types(raw.info, meg=meg, eeg=eeg)
picks = pick_types(raw.info, meg=meg, eeg=eeg)
if not ordered:
picks = np.random.RandomState(0).permutation(picks)
if not meg and not eeg:
with pytest.raises(ValueError, match='No appropriate channels'):
raw.get_channel_types(picks=picks)
return
types = np.array(raw.get_channel_types(picks=picks))
types_iter = np.array([channel_type(raw.info, idx) for idx in picks])
assert_array_equal(types, types_iter)


run_tests_if_main()