From 0b6afb9782b0e4b25853c4253ec8df4de1dfd638 Mon Sep 17 00:00:00 2001 From: Ivan Zubarev Date: Wed, 4 Oct 2023 10:23:44 +0300 Subject: [PATCH 01/17] mne.channels.read_ch_adjacency 'picks' argument does not function as described #11608, buggfix and docstring update --- mne/channels/channels.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/mne/channels/channels.py b/mne/channels/channels.py index d57610d257f..4f5ab1749f1 100644 --- a/mne/channels/channels.py +++ b/mne/channels/channels.py @@ -1340,8 +1340,14 @@ def read_ch_adjacency(fname, picks=None): You can retrieve the names of all built-in channel adjacencies via :func:`mne.channels.get_builtin_ch_adjacencies`. - %(picks_all)s - Picks must match the template. + picks : list + Channels to include. Slices and lists of integers will be interpreted + as channel indices. In lists, channel name strings (e.g., + ['MEG0111', 'MEG2623'] will pick the given channels. + None (default) will pick all channels. Note that channels in + info['bads'] will be included if their names or + indices are explicitly provided. Picks must match the template. + Returns ------- @@ -1401,7 +1407,8 @@ def read_ch_adjacency(fname, picks=None): nb = loadmat(fname)["neighbours"] ch_names = _recursive_flatten(nb["label"], str) - picks = _picks_to_idx(len(ch_names), picks) + temp_info = create_info(ch_names, 1.) + picks = _picks_to_idx(temp_info, picks) neighbors = [_recursive_flatten(c, str) for c in nb["neighblabel"].flatten()] assert len(ch_names) == len(neighbors) adjacency = _ch_neighbor_adjacency(ch_names, neighbors) @@ -1409,12 +1416,6 @@ def read_ch_adjacency(fname, picks=None): adjacency = adjacency[picks][:, picks] ch_names = [ch_names[p] for p in picks] - # make sure MEG channel names contain space after "MEG" - for idx, ch_name in enumerate(ch_names): - if ch_name.startswith("MEG") and not ch_name[3] == " ": - ch_name = ch_name.replace("MEG", "MEG ") - ch_names[idx] = ch_name - return adjacency, ch_names From 915f3b99528897198a5d3ed976f35e0c1addded9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 4 Oct 2023 07:33:00 +0000 Subject: [PATCH 02/17] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mne/channels/channels.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/mne/channels/channels.py b/mne/channels/channels.py index 4f5ab1749f1..9330d1d3639 100644 --- a/mne/channels/channels.py +++ b/mne/channels/channels.py @@ -1341,13 +1341,13 @@ def read_ch_adjacency(fname, picks=None): built-in channel adjacencies via :func:`mne.channels.get_builtin_ch_adjacencies`. picks : list - Channels to include. Slices and lists of integers will be interpreted - as channel indices. In lists, channel name strings (e.g., - ['MEG0111', 'MEG2623'] will pick the given channels. - None (default) will pick all channels. Note that channels in - info['bads'] will be included if their names or - indices are explicitly provided. Picks must match the template. - + Channels to include. Slices and lists of integers will be interpreted + as channel indices. In lists, channel name strings (e.g., + ['MEG0111', 'MEG2623'] will pick the given channels. + None (default) will pick all channels. Note that channels in + info['bads'] will be included if their names or + indices are explicitly provided. Picks must match the template. + Returns ------- @@ -1407,7 +1407,7 @@ def read_ch_adjacency(fname, picks=None): nb = loadmat(fname)["neighbours"] ch_names = _recursive_flatten(nb["label"], str) - temp_info = create_info(ch_names, 1.) + temp_info = create_info(ch_names, 1.0) picks = _picks_to_idx(temp_info, picks) neighbors = [_recursive_flatten(c, str) for c in nb["neighblabel"].flatten()] assert len(ch_names) == len(neighbors) From 3e2adf7e17a43429fc8d4bcc2fec08265ace02b6 Mon Sep 17 00:00:00 2001 From: Ivan Zubarev Date: Wed, 4 Oct 2023 14:35:18 +0300 Subject: [PATCH 03/17] updated devel.rst and test_channels.py to include channels subset selection --- doc/changes/devel.rst | 1 + mne/channels/channels.py | 2 +- mne/channels/tests/test_channels.py | 23 ++++++++++++++++++++--- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/doc/changes/devel.rst b/doc/changes/devel.rst index a639a64428b..2f56c69a2e2 100644 --- a/doc/changes/devel.rst +++ b/doc/changes/devel.rst @@ -62,6 +62,7 @@ Bugs - Correctly prune channel-specific :class:`~mne.Annotations` when creating :class:`~mne.Epochs` without the channel(s) included in the channel specific annotations (:gh:`12010` by `Mathieu Scheltienne`_) - Fix :func:`~mne.viz.plot_volume_source_estimates` with :class:`~mne.VolSourceEstimate` which include a list of vertices (:gh:`12025` by `Mathieu Scheltienne`_) - Correctly handle passing ``"eyegaze"`` or ``"pupil"`` to :meth:`mne.io.Raw.pick` (:gh:`12019` by `Scott Huberty`_) +- Fix bug with :func: `mne.channels.read_channel_adj` (:gh:`11608` by :newcontrib:`Ivan Zubarev`) " API changes ~~~~~~~~~~~ diff --git a/mne/channels/channels.py b/mne/channels/channels.py index 4f5ab1749f1..e6b64096642 100644 --- a/mne/channels/channels.py +++ b/mne/channels/channels.py @@ -1408,7 +1408,7 @@ def read_ch_adjacency(fname, picks=None): nb = loadmat(fname)["neighbours"] ch_names = _recursive_flatten(nb["label"], str) temp_info = create_info(ch_names, 1.) - picks = _picks_to_idx(temp_info, picks) + picks = _picks_to_idx(temp_info, picks, none='all') neighbors = [_recursive_flatten(c, str) for c in nb["neighblabel"].flatten()] assert len(ch_names) == len(neighbors) adjacency = _ch_neighbor_adjacency(ch_names, neighbors) diff --git a/mne/channels/tests/test_channels.py b/mne/channels/tests/test_channels.py index 42695ae76bf..e7165e0f6c1 100644 --- a/mne/channels/tests/test_channels.py +++ b/mne/channels/tests/test_channels.py @@ -244,6 +244,7 @@ def test_get_builtin_ch_adjacencies(): def test_read_ch_adjacency(tmp_path): + """Test reading channel adjacency templates.""" a = partial(np.array, dtype=" Date: Wed, 4 Oct 2023 14:35:53 +0300 Subject: [PATCH 04/17] Update mne/channels/channels.py Co-authored-by: Eric Larson --- mne/channels/channels.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mne/channels/channels.py b/mne/channels/channels.py index 9330d1d3639..5dc9aa1c82a 100644 --- a/mne/channels/channels.py +++ b/mne/channels/channels.py @@ -1343,10 +1343,10 @@ def read_ch_adjacency(fname, picks=None): picks : list Channels to include. Slices and lists of integers will be interpreted as channel indices. In lists, channel name strings (e.g., - ['MEG0111', 'MEG2623'] will pick the given channels. - None (default) will pick all channels. Note that channels in - info['bads'] will be included if their names or - indices are explicitly provided. Picks must match the template. + ['MEG0111', 'MEG2623'] will pick the given channels. + None (default) will pick all channels. Note that channels in + info['bads'] will be included if their names or + indices are explicitly provided. Picks must match the template. Returns From 311bde882cb198de297b9fae056be9b8ad976ded Mon Sep 17 00:00:00 2001 From: Ivan Zubarev Date: Wed, 4 Oct 2023 14:39:07 +0300 Subject: [PATCH 05/17] update to mne/channels/tests/test_channels.py --- mne/channels/tests/test_channels.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mne/channels/tests/test_channels.py b/mne/channels/tests/test_channels.py index e7165e0f6c1..138bd6bc3c0 100644 --- a/mne/channels/tests/test_channels.py +++ b/mne/channels/tests/test_channels.py @@ -259,7 +259,7 @@ def test_read_ch_adjacency(tmp_path): dtype=[("label", "O"), ("neighblabel", "O")], ) mat = dict(neighbours=nbh) - mat_fname = tmp_path + "test_mat.mat" + mat_fname = tmp_path / "test_mat.mat" savemat(mat_fname, mat, oned_as="row") ch_adjacency, ch_names = read_ch_adjacency(mat_fname) @@ -301,7 +301,7 @@ def test_read_ch_adjacency(tmp_path): dtype=[("label", "O"), ("neighblabel", "O")], ) mat = dict(neighbours=nbh) - mat_fname = tmp_path + "test_isolated_mat.mat" + mat_fname = tmp_path / "test_isolated_mat.mat" savemat(mat_fname, mat, oned_as="row") ch_adjacency, ch_names = read_ch_adjacency(mat_fname) x = ch_adjacency.todense() @@ -326,7 +326,7 @@ def test_read_ch_adjacency(tmp_path): dtype=[("label", "O"), ("neighblabel", "O")], ) mat = dict(neighbours=nbh) - mat_fname = tmp_path + "test_error_mat.mat" + mat_fname = tmp_path / "test_error_mat.mat" savemat(mat_fname, mat, oned_as="row") pytest.raises(ValueError, read_ch_adjacency, mat_fname) From e4abce288e1f1a59c6d60853005547298a955104 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 4 Oct 2023 11:42:41 +0000 Subject: [PATCH 06/17] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mne/channels/channels.py | 2 +- mne/channels/tests/test_channels.py | 18 ++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/mne/channels/channels.py b/mne/channels/channels.py index 217b7f01ac2..039b74e5143 100644 --- a/mne/channels/channels.py +++ b/mne/channels/channels.py @@ -1408,7 +1408,7 @@ def read_ch_adjacency(fname, picks=None): nb = loadmat(fname)["neighbours"] ch_names = _recursive_flatten(nb["label"], str) temp_info = create_info(ch_names, 1.0) - picks = _picks_to_idx(temp_info, picks, none='all') + picks = _picks_to_idx(temp_info, picks, none="all") neighbors = [_recursive_flatten(c, str) for c in nb["neighblabel"].flatten()] assert len(ch_names) == len(neighbors) adjacency = _ch_neighbor_adjacency(ch_names, neighbors) diff --git a/mne/channels/tests/test_channels.py b/mne/channels/tests/test_channels.py index 138bd6bc3c0..6bb8c640834 100644 --- a/mne/channels/tests/test_channels.py +++ b/mne/channels/tests/test_channels.py @@ -244,7 +244,6 @@ def test_get_builtin_ch_adjacencies(): def test_read_ch_adjacency(tmp_path): - """Test reading channel adjacency templates.""" a = partial(np.array, dtype=" Date: Wed, 4 Oct 2023 14:52:20 +0300 Subject: [PATCH 07/17] fixed typo in devel.rst --- doc/changes/devel.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/changes/devel.rst b/doc/changes/devel.rst index 2f56c69a2e2..c58f91d8b86 100644 --- a/doc/changes/devel.rst +++ b/doc/changes/devel.rst @@ -62,7 +62,7 @@ Bugs - Correctly prune channel-specific :class:`~mne.Annotations` when creating :class:`~mne.Epochs` without the channel(s) included in the channel specific annotations (:gh:`12010` by `Mathieu Scheltienne`_) - Fix :func:`~mne.viz.plot_volume_source_estimates` with :class:`~mne.VolSourceEstimate` which include a list of vertices (:gh:`12025` by `Mathieu Scheltienne`_) - Correctly handle passing ``"eyegaze"`` or ``"pupil"`` to :meth:`mne.io.Raw.pick` (:gh:`12019` by `Scott Huberty`_) -- Fix bug with :func: `mne.channels.read_channel_adj` (:gh:`11608` by :newcontrib:`Ivan Zubarev`) " +- Fix bug with :func: `mne.channels.read_channel_adj` (:gh:`11608` by :newcontrib:`Ivan Zubarev`) API changes ~~~~~~~~~~~ From 5ef52e4a70d8c83dca1bddcccb10df78fb2f3821 Mon Sep 17 00:00:00 2001 From: Ivan Zubarev Date: Wed, 4 Oct 2023 15:10:47 +0300 Subject: [PATCH 08/17] more typos to devel.rst --- doc/changes/devel.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/changes/devel.rst b/doc/changes/devel.rst index c58f91d8b86..d889e479721 100644 --- a/doc/changes/devel.rst +++ b/doc/changes/devel.rst @@ -62,7 +62,7 @@ Bugs - Correctly prune channel-specific :class:`~mne.Annotations` when creating :class:`~mne.Epochs` without the channel(s) included in the channel specific annotations (:gh:`12010` by `Mathieu Scheltienne`_) - Fix :func:`~mne.viz.plot_volume_source_estimates` with :class:`~mne.VolSourceEstimate` which include a list of vertices (:gh:`12025` by `Mathieu Scheltienne`_) - Correctly handle passing ``"eyegaze"`` or ``"pupil"`` to :meth:`mne.io.Raw.pick` (:gh:`12019` by `Scott Huberty`_) -- Fix bug with :func: `mne.channels.read_channel_adj` (:gh:`11608` by :newcontrib:`Ivan Zubarev`) +- Fix bug with :func:`mne.channels.read_channel_adj` (:gh:`11608` by :newcontrib:`Ivan Zubarev`) API changes ~~~~~~~~~~~ From ab01d2d01cf30d2889bd32f952509aaa6bcc4a9d Mon Sep 17 00:00:00 2001 From: Ivan Zubarev Date: Wed, 4 Oct 2023 21:28:26 +0300 Subject: [PATCH 09/17] Docdict-based docstring in mne.channels.read_ch_adjacency --- doc/changes/devel.rst | 2 +- mne/channels/channels.py | 10 ++-------- mne/utils/docs.py | 16 ++++++++++------ 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/doc/changes/devel.rst b/doc/changes/devel.rst index d889e479721..6b6be7588c8 100644 --- a/doc/changes/devel.rst +++ b/doc/changes/devel.rst @@ -42,6 +42,7 @@ Bugs - Fix bugs with :func:`mne.preprocessing.realign_raw` where the start of ``other`` was incorrectly cropped; and onsets and durations in ``other.annotations`` were left unsynced with the resampled data (:gh:`11950` by :newcontrib:`Qian Chu`) - Fix bug where ``encoding`` argument was ignored when reading annotations from an EDF file (:gh:`11958` by :newcontrib:`Andrew Gilbert`) - Mark tests ``test_adjacency_matches_ft`` and ``test_fetch_uncompressed_file`` as network tests (:gh:`12041` by :newcontrib:`Maksym Balatsko`) +- Fix bug with :func:`mne.channels.read_ch_adjacency` (:gh:`11608` by :newcontrib:`Ivan Zubarev`) - Fix bugs with saving splits for :class:`~mne.Epochs` (:gh:`11876` by `Dmitrii Altukhov`_) - Fix bug with multi-plot 3D rendering where only one plot was updated (:gh:`11896` by `Eric Larson`_) - Fix bug where subject birthdays were not correctly read by :func:`mne.io.read_raw_snirf` (:gh:`11912` by `Eric Larson`_) @@ -62,7 +63,6 @@ Bugs - Correctly prune channel-specific :class:`~mne.Annotations` when creating :class:`~mne.Epochs` without the channel(s) included in the channel specific annotations (:gh:`12010` by `Mathieu Scheltienne`_) - Fix :func:`~mne.viz.plot_volume_source_estimates` with :class:`~mne.VolSourceEstimate` which include a list of vertices (:gh:`12025` by `Mathieu Scheltienne`_) - Correctly handle passing ``"eyegaze"`` or ``"pupil"`` to :meth:`mne.io.Raw.pick` (:gh:`12019` by `Scott Huberty`_) -- Fix bug with :func:`mne.channels.read_channel_adj` (:gh:`11608` by :newcontrib:`Ivan Zubarev`) API changes ~~~~~~~~~~~ diff --git a/mne/channels/channels.py b/mne/channels/channels.py index 039b74e5143..53941d6d58c 100644 --- a/mne/channels/channels.py +++ b/mne/channels/channels.py @@ -1340,14 +1340,8 @@ def read_ch_adjacency(fname, picks=None): You can retrieve the names of all built-in channel adjacencies via :func:`mne.channels.get_builtin_ch_adjacencies`. - picks : list - Channels to include. Slices and lists of integers will be interpreted - as channel indices. In lists, channel name strings (e.g., - ['MEG0111', 'MEG2623'] will pick the given channels. - None (default) will pick all channels. Note that channels in - info['bads'] will be included if their names or - indices are explicitly provided. Picks must match the template. - + + %(picks_all_notypes)s Returns ------- diff --git a/mne/utils/docs.py b/mne/utils/docs.py index d32e1923aa4..be4c97be50d 100644 --- a/mne/utils/docs.py +++ b/mne/utils/docs.py @@ -3355,11 +3355,12 @@ def _reflow_param_docstring(docstring, has_first_line=True, width=75): _picks_header = f"picks : {_picks_types}" _picks_desc = "Channels to include." _picks_int = "Slices and lists of integers will be interpreted as channel " "indices." -_picks_str = """In lists, channel *type* strings - (e.g., ``['meg', 'eeg']``) will pick channels of those - types, channel *name* strings (e.g., ``['MEG0111', 'MEG2623']`` - will pick the given channels. Can also be the string values - "all" to pick all channels, or "data" to pick :term:`data channels`. +_picks_str_types = "channel *type* strings (e.g., ``['meg', 'eeg']``) will pick channels of those types, " +_picks_str_names = "channel *name* strings (e.g., ``['MEG0111', 'MEG2623']`` will pick the given channels. " +_picks_str_values = """Can also be the string values "all" to pick all channels, or "data" to pick :term:`data channels`. """ +_picks_str = f"""In lists, {_picks_str_types}{_picks_str_names}{_picks_str_values} + None (default) will pick""" +_picks_str_notypes = f"""In lists, {_picks_str_names} None (default) will pick""" _reminder = ( "Note that channels in ``info['bads']`` *will be included* if " @@ -3370,6 +3371,8 @@ def _reflow_param_docstring(docstring, has_first_line=True, width=75): noref = f"(excluding reference MEG channels). {reminder}" picks_base = f"""{_picks_header} {_picks_desc} {_picks_int} {_picks_str}""" +picks_base_notypes = f"""picks : list of int | list of str | slice | None + {_picks_desc} {_picks_int} {_picks_str_notypes}""" docdict["picks_all"] = _reflow_param_docstring(f"{picks_base} all channels. {reminder}") docdict["picks_all_data"] = _reflow_param_docstring( f"{picks_base} all data channels. {reminder}" @@ -3377,6 +3380,7 @@ def _reflow_param_docstring(docstring, has_first_line=True, width=75): docdict["picks_all_data_noref"] = _reflow_param_docstring( f"{picks_base} all data channels {noref}" ) +docdict["picks_all_notypes"] = _reflow_param_docstring(f"{picks_base_notypes} all channels. {reminder}") docdict["picks_base"] = _reflow_param_docstring(picks_base) docdict["picks_good_data"] = _reflow_param_docstring( f"{picks_base} good data channels. {reminder}" @@ -3588,7 +3592,7 @@ def _reflow_param_docstring(docstring, has_first_line=True, width=75): the data. If ``None``, use ``projs`` from `~mne.Report` creation. """ -# %% + # %% # R docdict[ From 7c72a26c12a43f676912f213e7896ad2805cda66 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 4 Oct 2023 18:29:41 +0000 Subject: [PATCH 10/17] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mne/channels/channels.py | 2 +- mne/utils/docs.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/mne/channels/channels.py b/mne/channels/channels.py index 53941d6d58c..33eb707c9e8 100644 --- a/mne/channels/channels.py +++ b/mne/channels/channels.py @@ -1340,7 +1340,7 @@ def read_ch_adjacency(fname, picks=None): You can retrieve the names of all built-in channel adjacencies via :func:`mne.channels.get_builtin_ch_adjacencies`. - + %(picks_all_notypes)s Returns diff --git a/mne/utils/docs.py b/mne/utils/docs.py index be4c97be50d..db206cf69f0 100644 --- a/mne/utils/docs.py +++ b/mne/utils/docs.py @@ -3380,7 +3380,9 @@ def _reflow_param_docstring(docstring, has_first_line=True, width=75): docdict["picks_all_data_noref"] = _reflow_param_docstring( f"{picks_base} all data channels {noref}" ) -docdict["picks_all_notypes"] = _reflow_param_docstring(f"{picks_base_notypes} all channels. {reminder}") +docdict["picks_all_notypes"] = _reflow_param_docstring( + f"{picks_base_notypes} all channels. {reminder}" +) docdict["picks_base"] = _reflow_param_docstring(picks_base) docdict["picks_good_data"] = _reflow_param_docstring( f"{picks_base} good data channels. {reminder}" @@ -3592,7 +3594,7 @@ def _reflow_param_docstring(docstring, has_first_line=True, width=75): the data. If ``None``, use ``projs`` from `~mne.Report` creation. """ - # %% +# %% # R docdict[ From b8fde4fcfcdb8884a5f619c40e93db0e03bef268 Mon Sep 17 00:00:00 2001 From: Ivan Zubarev Date: Thu, 5 Oct 2023 09:22:23 +0300 Subject: [PATCH 11/17] style fixes to /utils/docs.py --- mne/utils/docs.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/mne/utils/docs.py b/mne/utils/docs.py index be4c97be50d..cd382a4cee0 100644 --- a/mne/utils/docs.py +++ b/mne/utils/docs.py @@ -3355,10 +3355,14 @@ def _reflow_param_docstring(docstring, has_first_line=True, width=75): _picks_header = f"picks : {_picks_types}" _picks_desc = "Channels to include." _picks_int = "Slices and lists of integers will be interpreted as channel " "indices." -_picks_str_types = "channel *type* strings (e.g., ``['meg', 'eeg']``) will pick channels of those types, " -_picks_str_names = "channel *name* strings (e.g., ``['MEG0111', 'MEG2623']`` will pick the given channels. " -_picks_str_values = """Can also be the string values "all" to pick all channels, or "data" to pick :term:`data channels`. """ -_picks_str = f"""In lists, {_picks_str_types}{_picks_str_names}{_picks_str_values} +_picks_str_types = """channel *type* strings (e.g., ``['meg', 'eeg']``) will + pick channels of those types,""" +_picks_str_names = """channel *name* strings (e.g., ``['MEG0111', 'MEG2623']`` + will pick the given channels.""" +_picks_str_values = """Can also be the string values "all" to pick + all channels, or "data" to pick :term:`data channels`.""" +_picks_str = f"""In lists, {_picks_str_types} {_picks_str_names} + {_picks_str_values} None (default) will pick""" _picks_str_notypes = f"""In lists, {_picks_str_names} None (default) will pick""" @@ -3592,7 +3596,7 @@ def _reflow_param_docstring(docstring, has_first_line=True, width=75): the data. If ``None``, use ``projs`` from `~mne.Report` creation. """ - # %% +# %% # R docdict[ From 8a1c06840a6f698f8754d62283a5b6abaf8c0ef2 Mon Sep 17 00:00:00 2001 From: Ivan Zubarev Date: Thu, 5 Oct 2023 09:37:28 +0300 Subject: [PATCH 12/17] style fixes to /utils/docs.py#2 --- mne/utils/docs.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mne/utils/docs.py b/mne/utils/docs.py index 286e6614d25..b1998984503 100644 --- a/mne/utils/docs.py +++ b/mne/utils/docs.py @@ -3358,11 +3358,11 @@ def _reflow_param_docstring(docstring, has_first_line=True, width=75): _picks_header = f"picks : {_picks_types}" _picks_desc = "Channels to include." _picks_int = "Slices and lists of integers will be interpreted as channel " "indices." -_picks_str_types = """channel *type* strings (e.g., ``['meg', 'eeg']``) will +_picks_str_types = """channel *type* strings (e.g., ``['meg', 'eeg']``) will pick channels of those types,""" -_picks_str_names = """channel *name* strings (e.g., ``['MEG0111', 'MEG2623']`` +_picks_str_names = """channel *name* strings (e.g., ``['MEG0111', 'MEG2623']`` will pick the given channels.""" -_picks_str_values = """Can also be the string values "all" to pick +_picks_str_values = """Can also be the string values "all" to pick all channels, or "data" to pick :term:`data channels`.""" _picks_str = f"""In lists, {_picks_str_types} {_picks_str_names} {_picks_str_values} From 52b68631ccecbae8523492bf0ba785ce40ef31db Mon Sep 17 00:00:00 2001 From: Ivan Zubarev Date: Thu, 5 Oct 2023 10:06:38 +0300 Subject: [PATCH 13/17] Update mne/channels/tests/test_channels.py Co-authored-by: Daniel McCloy --- mne/channels/tests/test_channels.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/mne/channels/tests/test_channels.py b/mne/channels/tests/test_channels.py index 6bb8c640834..c6690af5921 100644 --- a/mne/channels/tests/test_channels.py +++ b/mne/channels/tests/test_channels.py @@ -342,8 +342,6 @@ def test_read_ch_adjacency(tmp_path): ch_subset_adjacency_slice, slice_subset_names = read_ch_adjacency( name, subset_slice ) - # import pdb - # pdb.set_trace() assert_array_equal(ch_subset_names, subset_names) assert_array_equal(ind_subset_names, subset_names) assert_array_equal(slice_subset_names, subset_names) From c8515216a333d5011b17ce9be9e4159e67fce6d3 Mon Sep 17 00:00:00 2001 From: Ivan Zubarev Date: Thu, 5 Oct 2023 10:34:53 +0300 Subject: [PATCH 14/17] style fix in docs.py --- mne/utils/docs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mne/utils/docs.py b/mne/utils/docs.py index ba9d4187b0d..b62b7f07fd1 100644 --- a/mne/utils/docs.py +++ b/mne/utils/docs.py @@ -3364,7 +3364,7 @@ def _reflow_param_docstring(docstring, has_first_line=True, width=75): will pick the given channels.""" _picks_str_values = """Can also be the string values "all" to pick all channels, or "data" to pick :term:`data channels`.""" -_picks_str = f"""In lists, {_picks_str_types} {_picks_str_names} +_picks_str = f"""In lists, {_picks_str_types} {_picks_str_names} {_picks_str_values} None (default) will pick""" _picks_str_notypes = f"""In lists, {_picks_str_names} From 44ec2e199205ff664e02a5a306fee13bb9d82a2e Mon Sep 17 00:00:00 2001 From: Ivan Zubarev Date: Thu, 5 Oct 2023 11:26:34 +0300 Subject: [PATCH 15/17] Added: test_read_builtin_ch_adjacency_picks --- mne/channels/channels.py | 1 - mne/channels/tests/test_channels.py | 39 +++++++++++++++-------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/mne/channels/channels.py b/mne/channels/channels.py index 33eb707c9e8..1dd4aa49d14 100644 --- a/mne/channels/channels.py +++ b/mne/channels/channels.py @@ -1340,7 +1340,6 @@ def read_ch_adjacency(fname, picks=None): You can retrieve the names of all built-in channel adjacencies via :func:`mne.channels.get_builtin_ch_adjacencies`. - %(picks_all_notypes)s Returns diff --git a/mne/channels/tests/test_channels.py b/mne/channels/tests/test_channels.py index 6bb8c640834..d2f7c846140 100644 --- a/mne/channels/tests/test_channels.py +++ b/mne/channels/tests/test_channels.py @@ -243,6 +243,26 @@ def test_get_builtin_ch_adjacencies(): assert len(name_and_description) == 2 +@pytest.mark.parametrize('name', get_builtin_ch_adjacencies()) +@pytest.mark.parametrize('picks', ['pick-slice', 'pick-arange', 'pick-names']) +def test_read_builtin_ch_adjacency_picks(name, picks): + """Test picking channel subsets when reading builtin adjacency matrices.""" + + ch_adjacency, ch_names = read_ch_adjacency(name) + assert_equal(ch_adjacency.shape[0], len(ch_names)) + subset_names = ch_names[::2] + if picks == 'pick-slice': + subset = slice(None, None, 2) + elif picks == 'pick-arange': + subset = np.arange(0, len(ch_names), 2) + else: + assert picks == 'pick-names' + subset = subset_names + + ch_subset_adjacency, ch_subset_names = read_ch_adjacency(name, subset) + assert_array_equal(ch_subset_names, subset_names) + + def test_read_ch_adjacency(tmp_path): """Test reading channel adjacency templates.""" a = partial(np.array, dtype=" Date: Thu, 5 Oct 2023 08:35:28 +0000 Subject: [PATCH 16/17] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mne/channels/tests/test_channels.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mne/channels/tests/test_channels.py b/mne/channels/tests/test_channels.py index aeaf3db59fc..3fe1704ff4c 100644 --- a/mne/channels/tests/test_channels.py +++ b/mne/channels/tests/test_channels.py @@ -243,20 +243,20 @@ def test_get_builtin_ch_adjacencies(): assert len(name_and_description) == 2 -@pytest.mark.parametrize('name', get_builtin_ch_adjacencies()) -@pytest.mark.parametrize('picks', ['pick-slice', 'pick-arange', 'pick-names']) +@pytest.mark.parametrize("name", get_builtin_ch_adjacencies()) +@pytest.mark.parametrize("picks", ["pick-slice", "pick-arange", "pick-names"]) def test_read_builtin_ch_adjacency_picks(name, picks): """Test picking channel subsets when reading builtin adjacency matrices.""" ch_adjacency, ch_names = read_ch_adjacency(name) assert_equal(ch_adjacency.shape[0], len(ch_names)) subset_names = ch_names[::2] - if picks == 'pick-slice': + if picks == "pick-slice": subset = slice(None, None, 2) - elif picks == 'pick-arange': + elif picks == "pick-arange": subset = np.arange(0, len(ch_names), 2) else: - assert picks == 'pick-names' + assert picks == "pick-names" subset = subset_names ch_subset_adjacency, ch_subset_names = read_ch_adjacency(name, subset) @@ -349,6 +349,7 @@ def test_read_ch_adjacency(tmp_path): savemat(mat_fname, mat, oned_as="row") pytest.raises(ValueError, read_ch_adjacency, mat_fname) + def _download_ft_neighbors(target_dir): """Download the known neighbors from FieldTrip.""" From 65e50969e99aee5356e71accc4c8bd9d86df3b89 Mon Sep 17 00:00:00 2001 From: Ivan Zubarev Date: Thu, 5 Oct 2023 12:31:22 +0300 Subject: [PATCH 17/17] style fix --- mne/channels/tests/test_channels.py | 1 - 1 file changed, 1 deletion(-) diff --git a/mne/channels/tests/test_channels.py b/mne/channels/tests/test_channels.py index aeaf3db59fc..c5b2c7dd505 100644 --- a/mne/channels/tests/test_channels.py +++ b/mne/channels/tests/test_channels.py @@ -247,7 +247,6 @@ def test_get_builtin_ch_adjacencies(): @pytest.mark.parametrize('picks', ['pick-slice', 'pick-arange', 'pick-names']) def test_read_builtin_ch_adjacency_picks(name, picks): """Test picking channel subsets when reading builtin adjacency matrices.""" - ch_adjacency, ch_names = read_ch_adjacency(name) assert_equal(ch_adjacency.shape[0], len(ch_names)) subset_names = ch_names[::2]