diff --git a/doc/changes/dev/13570.newfeature.rst b/doc/changes/dev/13570.newfeature.rst new file mode 100644 index 00000000000..284614e1b9e --- /dev/null +++ b/doc/changes/dev/13570.newfeature.rst @@ -0,0 +1,3 @@ +Add an optional ``show_channel_names`` parameter to +:meth:`mne.viz.plot_alignment` to overlay channel labels at sensor +locations in the 3D alignment view, by :newcontrib:`Aman Srivastava`. diff --git a/doc/changes/names.inc b/doc/changes/names.inc index 29db588a9d9..79db14d44e3 100644 --- a/doc/changes/names.inc +++ b/doc/changes/names.inc @@ -14,6 +14,7 @@ .. _Alex Rockhill: https://github.com/alexrockhill/ .. _Alexander Rudiuk: https://github.com/ARudiuk .. _Alexandre Barachant: https://alexandre.barachant.org +.. _Aman Srivastava: https://github.com/aman-coder03 .. _Andrea Brovelli: https://brovelli.github.io/ .. _Andreas Hojlund: https://github.com/ahoejlund .. _Andres Rodriguez: https://github.com/infinitejest/ diff --git a/examples/visualization/eeg_on_scalp.py b/examples/visualization/eeg_on_scalp.py index f3201bd39f1..1146ae229ef 100644 --- a/examples/visualization/eeg_on_scalp.py +++ b/examples/visualization/eeg_on_scalp.py @@ -35,6 +35,7 @@ meg=[], coord_frame="head", subjects_dir=subjects_dir, + show_channel_names=True, ) # Set viewing angle diff --git a/mne/viz/_3d.py b/mne/viz/_3d.py index cc660fe4986..080fb69d71f 100644 --- a/mne/viz/_3d.py +++ b/mne/viz/_3d.py @@ -554,6 +554,7 @@ def plot_alignment( sensor_colors=None, *, sensor_scales=None, + show_channel_names=False, verbose=None, ): """Plot head, sensor, and source space alignment in 3D. @@ -648,6 +649,11 @@ def plot_alignment( %(sensor_scales)s .. versionadded:: 1.9 + show_channel_names : bool + If True, overlay channel names at sensor locations. + Default is False. + + .. versionadded:: 1.12 %(verbose)s Returns @@ -942,6 +948,23 @@ def plot_alignment( sensor_scales=sensor_scales, ) + if show_channel_names and picks.size > 0: + chs = [info["chs"][pi] for pi in picks] + + # channel positions are in head coordinates + pos = np.array([ch["loc"][:3] for ch in chs]) + + # transform to current coord frame + pos = apply_trans(to_cf_t["head"], pos) + + for ch, xyz in zip(chs, pos): + renderer.text3d( + *xyz, + ch["ch_name"], + scale=0.005, + color=(1.0, 1.0, 1.0), + ) + if src is not None: atlas_ids, colors = read_freesurfer_lut() for ss in src: