Skip to content

Conversation

tsbinns
Copy link
Contributor

@tsbinns tsbinns commented Aug 12, 2025

Reference issue (if any)

Fixes #13374

What does this implement/fix?

Allows equalize_channels to support BaseSpectrum objects.

Additional information

Also adds a setter for BaseSpectrum.nave which is also required for grand_average().

@tsbinns tsbinns force-pushed the grand_avg_spectrum_support branch from e805d81 to f65c6ff Compare August 12, 2025 16:33
Comment on lines 153 to +154
from ..time_frequency import BaseTFR, CrossSpectralDensity
from ..time_frequency.spectrum import BaseSpectrum
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Small note: can't import BaseSpectrum directly from the time_frequency module, and it's not included in the API reference, but BaseTFR is.

Comment on lines +247 to +254
def test_equalize_channels(raw_spectrum):
"""Test equalization of channels for instances of `BaseSpectrum`."""
spect1 = raw_spectrum.copy()
spect2 = spect1.copy().pick(["MEG 0122", "MEG 0111"])
spect1, spect2 = equalize_channels([spect1, spect2])

assert spect1.ch_names == ["MEG 0111", "MEG 0122"]
assert spect2.ch_names == ["MEG 0111", "MEG 0122"]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This follows the existing tests for checking equalize_channels with Raw, Evoked, CSD, etc...

@tsbinns
Copy link
Contributor Author

tsbinns commented Aug 12, 2025

def test_equalize_channels():
"""Test equalizing channels and their ordering."""
# This function only tests the generic functionality of equalize_channels.
# Additional tests for each instance type are included in the accompanying
# test suite for each type.

Going over this, I noticed this comment isn't technically true anymore, as equalize_channels supports TFR objects, but there isn't an equivalent test. However, there is one instance where equalize_channels is called on TFR data as part of another test:

power_pick, power_drop = mne.equalize_channels([power_pick, power_drop])

Is it worth adding a dedicated test as the comment alludes to?

@tsbinns tsbinns marked this pull request as ready for review August 12, 2025 18:37
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.

TypeError in mne.grand_average with Spectrum objects in MNE 1.10.1
1 participant