Skip to content

TypeError in mne.grand_average with Spectrum objects in MNE 1.10.1 #13374

Description

@kuraifune

Description of the problem

When attempting to compute a grand average of a list of mne.time_frequency.spectrum.Spectrum objects, the mne.grand_average function raises a TypeError:

TypeError: Instances to be modified must be an instance of Raw, Epochs, Evoked, TFR, Forward, Covariance, CrossSpectralDensity or Info, got <class 'mne.time_frequency.spectrum.Spectrum'> instead.

According to the documentation of mne version 1.10.1, 'Spectrum' objects seems to be added since 1.10.0.

Steps to reproduce

import numpy as np
import mne

# Create some dummy data to simulate a multi-subject study
n_subjects = 3
epochs_list = []
for i in range(n_subjects):
    data = np.random.randn(20, 10, 500)  # 20 epochs, 10 channels, 500 time points
    info = mne.create_info(ch_names=[f'ch{c}' for c in range(10)], sfreq=250, ch_types='eeg')
    epochs = mne.EpochsArray(data, info)
    epochs_list.append(epochs)

# Compute the PSD for each subject and get the average Spectrum object
subject_psds = []
for epochs in epochs_list:
    psd = epochs.compute_psd(method="multitaper", fmin=1, fmax=30, n_jobs=1).average()
    subject_psds.append(psd)

# Try to compute the grand average of the Spectrum objects
grand_average_psd = mne.grand_average(subject_psds)

Link to data

No response

Expected results

The mne.grand_average function should successfully compute a grand average Spectrum object from the list of Spectrum objects and return it without raising an error.

Actual results

Executing the code block above on MNE version 1.10.1 results in the following error:

TypeError: Instances to be modified must be an instance of Raw, Epochs, Evoked, TFR, Forward, Covariance, CrossSpectralDensity or Info, got <class 'mne.time_frequency.spectrum.Spectrum'> instead.

Additional information

mne.sys_info()
Platform Linux-6.14.0-27-generic-x86_64-with-glibc2.39
Python 3.12.3 (main, Jun 18 2025, 17:59:45) [GCC 13.3.0]
Executable
CPU AMD Ryzen Threadripper PRO 5955WX 16-Cores (32 cores)
Memory 125.6 GiB
Core
├☑ mne 1.10.1 (latest release)
├☑ numpy 2.3.1 (OpenBLAS 0.3.29 with 32 threads)
├☑ scipy 1.16.0
└☑ matplotlib 3.10.3 (backend=module://backend_interagg)
Numerical (optional)
├☑ sklearn 1.7.0
├☑ pandas 2.3.1
├☑ h5io 0.2.5
├☑ h5py 3.14.0
└☐ unavailable numba, nibabel, nilearn, dipy, openmeeg, cupy
Visualization (optional)
└☐ unavailable pyvista, pyvistaqt, vtk, qtpy, ipympl, pyqtgraph, mne-qt-browser, ipywidgets, trame_client, trame_server, trame_vtk, trame_vuetify
Ecosystem (optional)
├☑ mne-icalabel 0.7.0
└☐ unavailable mne-bids, mne-nirs, mne-features, mne-connectivity, mne-bids-pipeline, neo, eeglabio, edfio, mffpy, pybv

Activity

  1. changed the title [-]TypeError in mne.grand_average with mne.time_frequency.spectrum.Spectrum objects in MNE 1.10.1[/-] [+]TypeError in `mne.grand_average` Spectrum` objects in MNE 1.10.1[/+] on Aug 12, 2025
  2. changed the title [-]TypeError in `mne.grand_average` Spectrum` objects in MNE 1.10.1[/-] [+]TypeError in `mne.grand_average `Spectrum` objects in MNE 1.10.1[/+] on Aug 12, 2025
  3. changed the title [-]TypeError in `mne.grand_average `Spectrum` objects in MNE 1.10.1[/-] [+]TypeError in `mne.grand_average with `Spectrum` objects in MNE 1.10.1[/+] on Aug 12, 2025
  4. changed the title [-]TypeError in `mne.grand_average with `Spectrum` objects in MNE 1.10.1[/-] [+]TypeError in `mne.grand_average` with `Spectrum` objects in MNE 1.10.1[/+] on Aug 12, 2025
  5. tsbinns commented on Aug 12, 2025

    @tsbinns
    Contributor

    Thanks for raising this! Can confirm I can replicate this with the provided example.

    It's due to equalize_channels() not supporting Spectrum objects. BaseTFR objects are already supported, so fixing this should be simple.

    @kuraifune would you be comfortable submitting a PR to fix this, or would you like me to?

  6. kuraifune commented on Aug 12, 2025

    @kuraifune
    Author

    Thanks for raising this! Can confirm I can replicate this with the provided example.

    It's due to equalize_channels() not supporting Spectrum objects. BaseTFR objects are already supported, so fixing this should be simple.

    @kuraifune would you be comfortable submitting a PR to fix this, or would you like me to?

    @tsbinns Thanks for the update and for confirming the issue! I'm quite not comfortable yet, so I would really appreciate it if you could handle it. Thanks alot!

  7. drammock commented on Aug 12, 2025

    @drammock
    Member

    @kuraifune let's not close the issue until it's actually fixed :)

  8. tsbinns commented on Aug 12, 2025

    @tsbinns
    Contributor

    No problem @kuraifune, I will open a PR!

  9. tsbinns commented on Sep 4, 2025

    @tsbinns
    Contributor

    @kuraifune Just fyi, this is now fixed and is available in the development version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions