Skip to content
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
1 change: 1 addition & 0 deletions doc/changes/latest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Current (1.4.dev0)
Enhancements
~~~~~~~~~~~~
- Adjusted the algorithm used in :class:`mne.decoding.SSD` to support non-full rank data (:gh:`11458` by :newcontrib:`Thomas Binns`)
- Changed suggested type for ``ch_groups``` in `mne.viz.plot_sensors` from array to list of list(s) (arrays are still supported). (:gh:`11465` by `Hyonyoung Shin`_)
- Add support for UCL/FIL OPM data using :func:`mne.io.read_raw_fil` (:gh:`11366` by :newcontrib:`George O'Neill` and `Robert Seymour`_)
- Added ability to read stimulus durations from SNIRF files when using :func:`mne.io.read_raw_snirf` (:gh:`11397` by `Robert Luke`_)
- Add :meth:`mne.Info.save` to save an :class:`mne.Info` object to a fif file (:gh:`11401` by `Alex Rockhill`_)
Expand Down
2 changes: 2 additions & 0 deletions doc/changes/names.inc
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@

.. _Hüseyin Orkun Elmas: https://github.com/HuseyinOrkun

.. _Hyonyoung Shin: https://github.com/mcvain

.. _Ilias Machairas: https://github.com/JungleHippo

.. _Ivana Kojcic: https://github.com/ikojcic
Expand Down
2 changes: 2 additions & 0 deletions mne/viz/tests/test_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,8 @@ def test_plot_sensors(raw):
raw.plot_sensors(ch_groups='position', axes=ax)
raw.plot_sensors(ch_groups='selection', to_sphere=False)
raw.plot_sensors(ch_groups=[[0, 1, 2], [3, 4]])
raw.plot_sensors(ch_groups=np.array([[0, 1, 2], [3, 4, 5]]))
raw.plot_sensors(ch_groups=np.array([[0, 1, 2], [3, 4]], dtype=object))
pytest.raises(ValueError, raw.plot_sensors, ch_groups='asd')
pytest.raises(TypeError, plot_sensors, raw) # needs to be info
pytest.raises(ValueError, plot_sensors, raw.info, kind='sasaasd')
Expand Down
17 changes: 10 additions & 7 deletions mne/viz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -924,11 +924,13 @@ def plot_sensors(info, kind='topomap', ch_type=None, title=None,
show_names : bool | array of str
Whether to display all channel names. If an array, only the channel
names in the array are shown. Defaults to False.
ch_groups : 'position' | array of shape (n_ch_groups, n_picks) | None
ch_groups : 'position' | list of list | None
Channel groups for coloring the sensors. If None (default), default
coloring scheme is used. If 'position', the sensors are divided
into 8 regions. See ``order`` kwarg of :func:`mne.viz.plot_raw`. If
array, the channels are divided by picks given in the array.
array, the channels are divided by picks given in the array. Also
accepts a list of lists to allow channel groups of the same or
different sizes.

.. versionadded:: 0.13.0
to_sphere : bool
Expand Down Expand Up @@ -1019,12 +1021,16 @@ def plot_sensors(info, kind='topomap', ch_type=None, title=None,

ch_names = np.array([ch['ch_name'] for ch in chs])
bads = [idx for idx, name in enumerate(ch_names) if name in info['bads']]
_validate_type(ch_groups, (list, np.ndarray, str, None), 'ch_groups')
if ch_groups is None:
def_colors = _handle_default('color')
colors = ['red' if i in bads else def_colors[channel_type(info, pick)]
for i, pick in enumerate(picks)]
else:
if ch_groups in ['position', 'selection']:
if isinstance(ch_groups, str):
_check_option(
'ch_groups', ch_groups, ['position', 'selection'],
extra='when str')
# Avoid circular import
from ..channels import (read_vectorview_selection, _SELECTIONS,
_EEG_SELECTIONS, _divide_to_regions)
Expand All @@ -1048,13 +1054,10 @@ def plot_sensors(info, kind='topomap', ch_type=None, title=None,
x, y, z = pos[color_picks].T
color = np.mean(_rgb(x, y, z), axis=0)
color_vals[idx, :3] = color # mean of spatial color
else:
else: # array-like
import matplotlib.pyplot as plt
colors = np.linspace(0, 1, len(ch_groups))
color_vals = [plt.cm.jet(colors[i]) for i in range(len(ch_groups))]
if not isinstance(ch_groups, (np.ndarray, list)):
raise ValueError("ch_groups must be None, 'position', "
"'selection', or an array. Got %s." % ch_groups)
colors = np.zeros((len(picks), 4))
for pick_idx, pick in enumerate(picks):
for ind, value in enumerate(ch_groups):
Expand Down