Skip to content

mne.preprocessing.ICA.fit() does not work for Evoked objects #8167

@wsxmxm

Description

@wsxmxm

Describe the bug

The MNE tutorial says mne.preprocessing.ICA.fit() can work for Raw, Epochs or Evoked objects. But my test shows it does not work for Evoked objects. Please see the following code, where the Evoked object is created according to the example in the tutorial.

Steps to reproduce

import os
import mne
from mne.preprocessing import ICA
sample_data_folder = mne.datasets.sample.data_path()
sample_data_raw_file = os.path.join(sample_data_folder, 'MEG', 'sample',
                                    'sample_audvis_raw.fif')
raw = mne.io.read_raw_fif(sample_data_raw_file, verbose=False)
events = mne.find_events(raw, stim_channel='STI 014')
event_dict = {'auditory/left': 1, 'auditory/right': 2, 'visual/left': 3,
              'visual/right': 4}
epochs = mne.Epochs(raw, events, tmin=-0.3, tmax=0.7, event_id=event_dict,
                    preload=True)
evoked = epochs['auditory/left'].average()
ica = ICA(n_components=15)
ica.fit(evoked)

Expected results

The code can run without error.

Actual results

For the last line, there is a TypeError: inst must be an instance of Raw or Epochs, got <class 'mne.evoked.EvokedArray'> instead

Additional information

I have checked the source code and feel that the source code does not really account for Evoked objects. My system is Windows 8.1. My MNE version is 0.20.7 or 0.21. My Python version is 3.7.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions