ICA preprocessing error failed

I’m trying to make preprocessing via ICA for further analysis. Below my script:
import os

import mne

data_path = './'
vhdr_file_base_1 = os.path.join(data_path, 'S01_exp.vhdr')
raw = mne.io.read_raw_brainvision(vhdr_file_base_1, preload=True)  # read raw data with mne
raw.set_montage('biosemi32', on_missing='ignore')
raw.filter(l_freq=1, h_freq=None)  # High-pass filter above 1 Hz
raw.filter(l_freq=None, h_freq=40)  # Low-pass filter below 40 Hz
raw.filter(l_freq=8, h_freq=30)  # Band-pass filter between 8 and 30 Hz
raw.notch_filter(freqs=50)  # Notch filter at 50 Hz (power line noise)

# The regression technique works regardless of chosen reference. However, it is
# important to choose a reference before proceeding with the analysis.
raw.set_eeg_reference("average")

# Removing slow drifts makes for more stable regression coefficients. Make sure
# to apply the same filter to both EEG and EOG channels!
raw.filter(0.3, 40)

raw.compute_psd(fmax=50).plot(picks="data", exclude="bads", amplitude=False)
raw.plot(duration=5, n_channels=30)

# set up and fit the ICA
ica = mne.preprocessing.ICA(n_components=20, random_state=97, max_iter=800)
ica.fit(raw)
ica.exclude = [1, 2]  # details on how we picked these are omitted here
ica.plot_properties(raw, picks=ica.exclude)

when I run this script I get an errors and warning:

Using matplotlib as 2D backend.
Fitting ICA to data using 32 channels (please be patient, this may take a while)
Selecting by number: 20 components
Fitting ICA took 9.0s.
    Using multitaper spectrum estimation with 7 DPSS windows
WARNING:root:Did not find any electrode locations (in the info object), will attempt to use digitization points instead. However, if digitization points do not correspond to the EEG electrodes, this will lead to bad results. Please verify that the sensor locations in the plot are accurate.
...
RuntimeError: Did not find any digitization points of kind FIFFV_POINT_EEG (3) in the info.

I looked here little bit for a solution, but saw only this question which mostly did not help me at all. Before getting this error, I had problems with scikit-learn which was no available, but I think in the end this package does not make any influence.

Thank you in advance for any tips and help!

The problem occurs when you want to create the properties plot (which will want to generate a topoplot) without a montage being set. You need to set an EEG montage for this to work.

but this one:

raw.set_montage('biosemi32', on_missing='ignore')

does not work? I tried to use this montage and I thought it is implemented

Also when I’m setting montage by:

montage = mne.channels.make_standard_montage("biosemi32")
raw.set_montage(montage)

I get such error:

ValueError: DigMontage is only a subset of info. There are 32 channel positions not present in the DigMontage. The channels missing from the montage are:

['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32'].

Consider using inst.rename_channels to match the montage nomenclature, or inst.set_channel_types if these are not EEG channels, or use the on_missing parameter if the channel positions are allowed to be unknown in your analyses.

It’s like all channels are now available. In the topic it was suggested to use rename_channels:
raw.rename_channels({'BrainVision': 'BrainVision'}) and error:
ValueError: Invalid channel name(s) {'BrainVision'} is not present in info

so via direct renaming:

info = raw.info

for ch in range(0, 32):
    mne.rename_channels(info, {info["ch_names"][ch]: montage.ch_names[ch]})

I got such results:
default montage from standard biosemi32 - ['Fp1', 'AF3', 'F7', 'F3', 'FC1', 'FC5', 'T7', 'C3', 'CP1', 'CP5', 'P7', 'P3', 'Pz', 'PO3', 'O1', 'Oz', 'O2', 'PO4', 'P4', 'P8', 'CP6', 'CP2', 'C4', 'T8', 'FC6', 'FC2', 'F4', 'F8', 'AF4', 'Fp2', 'Fz', 'Cz']

final montage - ['Fp1', 'AF3', 'F7', 'F3', 'FC1', 'FC5', 'T7', 'C3', 'CP1', 'CP5', 'P7', 'P3', 'Pz', 'PO3', 'O1', 'Oz', 'O2', 'PO4', 'P4', 'P8', 'CP6', 'CP2', 'C4', 'T8', 'FC6', 'FC2', 'F4', 'F8', 'AF4', 'Fp2', 'Fz', 'Cz', 'x_dir', 'y_dir', 'z_dir']

Your channel names are non-standard, so they don’t match those found in the montage. You need to rename your channels according to the 10/20 system (Fp1, Fp2, etc.) before setting the montage.

Best wishes,
Richard

Thank you for you help. yes, it looks I did not set it before but just after setting montage, now I get such output:

Fitting ICA to data using 32 channels (please be patient, this may take a while)
Selecting by number: 20 components
Fitting ICA took 5.1s.
    Using multitaper spectrum estimation with 7 DPSS windows
Not setting metadata
77 matching events found
No baseline correction applied
0 projection items activated
Not setting metadata
77 matching events found
No baseline correction applied
0 projection items activated

and also two images:

and how interpolate when I used just this code:

ica = mne.preprocessing.ICA(n_components=20, random_state=97, max_iter=800)
ica.fit(raw)
ica.exclude = [1, 2]  # details on how we picked these are omitted here
ica.plot_properties(raw, picks=ica.exclude)

I mean that I did not set usage for two plots, or is it normal?

I’m sorry, I don’t understand your question. It seems to be working now, no?

in general yes but I don’t understand why I have two plots when I call the method plot_properties only one time

You get one per picked component, so two in your case.

Okay, thank you for your help :slight_smile:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.