Skip to content

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

@kuraifune

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

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