Skip to content

Commit 4a5479d

Browse files
aman-coder03pre-commit-ci[bot]drammock
authored
ENH: Add optional channel name overlay to plot_alignment (#13570)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Daniel McCloy <dan@mccloy.info>
1 parent 7032648 commit 4a5479d

4 files changed

Lines changed: 28 additions & 0 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Add an optional ``show_channel_names`` parameter to
2+
:meth:`mne.viz.plot_alignment` to overlay channel labels at sensor
3+
locations in the 3D alignment view, by :newcontrib:`Aman Srivastava`.

doc/changes/names.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
.. _Alex Rockhill: https://github.com/alexrockhill/
1515
.. _Alexander Rudiuk: https://github.com/ARudiuk
1616
.. _Alexandre Barachant: https://alexandre.barachant.org
17+
.. _Aman Srivastava: https://github.com/aman-coder03
1718
.. _Andrea Brovelli: https://brovelli.github.io/
1819
.. _Andreas Hojlund: https://github.com/ahoejlund
1920
.. _Andres Rodriguez: https://github.com/infinitejest/

examples/visualization/eeg_on_scalp.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
meg=[],
3636
coord_frame="head",
3737
subjects_dir=subjects_dir,
38+
show_channel_names=True,
3839
)
3940

4041
# Set viewing angle

mne/viz/_3d.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,7 @@ def plot_alignment(
554554
sensor_colors=None,
555555
*,
556556
sensor_scales=None,
557+
show_channel_names=False,
557558
verbose=None,
558559
):
559560
"""Plot head, sensor, and source space alignment in 3D.
@@ -648,6 +649,11 @@ def plot_alignment(
648649
%(sensor_scales)s
649650
650651
.. versionadded:: 1.9
652+
show_channel_names : bool
653+
If True, overlay channel names at sensor locations.
654+
Default is False.
655+
656+
.. versionadded:: 1.12
651657
%(verbose)s
652658
653659
Returns
@@ -942,6 +948,23 @@ def plot_alignment(
942948
sensor_scales=sensor_scales,
943949
)
944950

951+
if show_channel_names and picks.size > 0:
952+
chs = [info["chs"][pi] for pi in picks]
953+
954+
# channel positions are in head coordinates
955+
pos = np.array([ch["loc"][:3] for ch in chs])
956+
957+
# transform to current coord frame
958+
pos = apply_trans(to_cf_t["head"], pos)
959+
960+
for ch, xyz in zip(chs, pos):
961+
renderer.text3d(
962+
*xyz,
963+
ch["ch_name"],
964+
scale=0.005,
965+
color=(1.0, 1.0, 1.0),
966+
)
967+
945968
if src is not None:
946969
atlas_ids, colors = read_freesurfer_lut()
947970
for ss in src:

0 commit comments

Comments
 (0)