Skip to content

Extend plot_csd support to SEEG, ECoG, and DBS channel types#13713

Open
Aniketsy wants to merge 11 commits intomne-tools:mainfrom
Aniketsy:fix-13711
Open

Extend plot_csd support to SEEG, ECoG, and DBS channel types#13713
Aniketsy wants to merge 11 commits intomne-tools:mainfrom
Aniketsy:fix-13711

Conversation

@Aniketsy
Copy link
Contributor

@Aniketsy Aniketsy commented Mar 2, 2026

Fixes #13711

@Aniketsy Aniketsy requested a review from drammock as a code owner March 2, 2026 12:57
@Aniketsy Aniketsy marked this pull request as draft March 2, 2026 13:22
Copy link
Contributor

@tsbinns tsbinns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for opening this, definitely on the right track! Some comments below.

@Aniketsy
Copy link
Contributor Author

Aniketsy commented Mar 3, 2026

@tsbinns thanks for the review and for suggesting this approach, it makes much more sense than my earlier implementation. please have a look and let me know if any further improvements are needed.

Copy link
Contributor

@tsbinns tsbinns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good changes! A couple small comments on the code, and a slightly bigger one for to refine the test. Let me know if anything's unclear.

@tsbinns tsbinns marked this pull request as ready for review March 4, 2026 19:37
@tsbinns
Copy link
Contributor

tsbinns commented Mar 4, 2026

@larsoner @wmvanvliet I noticed that the existing behaviour when plotting is that if no valid channel types are present (currently only EEG, Mag, Grad; this PR would change it to all valid data types), it just returns an empty figs container list.

I was a bit surprised by this. My expectation was at least a warning would be given that there is nothing valid to plot. WDYT?

Aniketsy and others added 3 commits March 5, 2026 13:53
Co-authored-by: Thomas S. Binns <t.s.binns@outlook.com>
Co-authored-by: Thomas S. Binns <t.s.binns@outlook.com>
Copy link
Contributor

@tsbinns tsbinns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good progress! A couple minor comments to tidy things up.

mne/viz/misc.py Outdated
# The units in which to plot the CSD
units = dict(eeg="µV²", grad="fT²/cm²", mag="fT²")
scalings = dict(eeg=1e12, grad=1e26, mag=1e30)
indices, titles, _, _, ch_types = _index_info_by_ch_type(info, csd.ch_names)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use the units and scalings returned here rather than re-finding them below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes , that make sense this will reduce redundancy

mne/viz/misc.py Outdated
Comment on lines +1549 to +1551
if mode == "csd":
scaling = DEFAULTS["scalings"].get(ch_type, 1)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be removed if using the scalings returned above.

mne/viz/misc.py Outdated
Comment on lines +56 to +80
"""Build channel-type-grouped indices and metadata for an object's channels.

Parameters
----------
info : Info
The measurement info, already restricted to the channels of interest
(e.g. via :func:`pick_info`).
obj_ch_names : list of str
Channel names of the object being indexed (e.g. the channel list of a
:class:`~mne.time_frequency.CrossSpectralDensity` or the filtered
channel list derived from a :class:`~mne.Covariance`).

Returns
-------
indices : list of list of int
Channel indices into *obj_ch_names*, one list per channel type.
titles : list of str
Human-readable title for each channel type.
units : list of str
Unit string for each channel type.
scalings : list of float
Scaling factor for each channel type.
ch_types : list of str
Channel type key for each group.
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We often forgo detailed docstrings for small private functions where the inputs/outputs are clear. In this case info and ch_names are ubiquitous and don't need explanation, and now the outputs are named, so I'd say this can be removed (just keep the first line).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it that make sense

mne/viz/misc.py Outdated
)


def _index_info_by_ch_type(info, obj_ch_names):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just ch_names would be the typical param name.

Comment on lines +316 to +326
@pytest.mark.parametrize(
"ch_types, expected_n_figs",
[
(None, 1),
("eeg", 1),
("ecog", 1),
(["grad", "dbs"], 2),
("misc", 0),
],
)
def test_plot_csd(ch_types, expected_n_figs):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer if expected_n_figs is set programatically within the test function, i.e., based on the number of valid data types in ch_types (with an exception for when ch_types is None).

Aniketsy and others added 5 commits March 6, 2026 09:59
Co-authored-by: Thomas S. Binns <t.s.binns@outlook.com>
Co-authored-by: Thomas S. Binns <t.s.binns@outlook.com>
Co-authored-by: Thomas S. Binns <t.s.binns@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expand channel types supported for CSD plotting

2 participants