Iâm newbie to mne library. I encountered the above error while trying to find bad channels in my EEG file, how can I solve it?
My code:
import os
import mne
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
raw = mne.io.read_raw_edf("/.edf", preload=True)
ten_twenty_montage = mne.channels.make_standard_montage('standard_1020')
print(ten_twenty_montage)
raw.filter(1,15)
ica = mne.preprocessing.ICA(n_components=15, random_state=42)
ica.fit(raw.copy().filter(4,15))
ica.plot_components(outlines="skirt") # <------ I got error from this code.
Making the montage is one step, but you should also add it to your raw data!
Once you have the variable containing the montage, in this case, ten_twenty_montage, use raw.set_montage(ten_twenty_montage) to apply it to your raw data.
The error you get is due to ica.plot_components trying to plot topographic maps, which requires the channel locations (montage), which are absent from your raw data.
As I wrote, you can add them in MNE. In the code snippet you provide, you are creating the montage (contains the channel locations) with mne.channels.make_standard_montage('standard_1020'). You just need to add them to your raw data with:
I got this error: ValueError: DigMontage is only a subset of info. There are 19 channel positions not present in the DigMontage. The required channels are:
Consider using 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.
and i found that @agramfort answered this questions in another topic he said " default montage requires your channels to be called âFp1â and not 'EEG
Fp1-LEâ Now i try to how to fix this issue
One problem is solved, another problem begins. programmersâ sad truth
Hello Richard,
Many thanks!!!
I just try the method you mentioned, there is no error now, this really helpful!!!
just past my code here in case other people may need
eeg_raw = mne.io.read_raw_edf('Mm_Tt_2022-12-28_13-08-03_Segment_0.edf')
print(eeg_raw)
print('\n')
print(eeg_raw.info)
# check channel names
ch_names = eeg_raw.ch_names
print(ch_names)
print(len(ch_names))
print('\n')
eeg_raw.load_data()
# apply the method, my original channel name is 'EEG Fp1-CPz'
def map_channel_name(old_name):
"""Clean a channel name."""
new_name = old_name.replace('EEG ', '').replace('-CPz', '')
return new_name
eeg_raw.rename_channels(mapping=map_channel_name)
eeg_raw.set_montage('standard_1020')
ch_names = eeg_raw.ch_names
print(ch_names)
# see raw data wave
# eeg_raw.plot()
# power line artifacts are easiest to see on plots of the spectrum
# eeg_raw.plot_psd(fmax=250)
# info = mne.create_info(31, sfreq=128)
# print(info)
# To filter the noise and remove the artifacts process the data with a bandpass filter between 1 Hz and 75 Hz
eeg_band_pass = eeg_raw.copy().filter(l_freq=1, h_freq=75)
# eeg_band_pass.plot()
# downsample the raw data
eeg_downsampled = eeg_band_pass.copy().resample(128)
# eeg_downsampled.plot()
# get the data matrix
data_matrix = eeg_downsampled.get_data()
print(data_matrix.shape)
eog_epochs = create_eog_epochs(eeg_downsampled, ch_name=ch_names, baseline=(-0.5, -0.2)) #baseline=None
eog_epochs.plot_image(combine='mean')
eog_epochs.average().plot_joint() #### here is what I got the error
Iâm glad itâs working now! And thanks for sharing your solution, this will sure be helpful to others!
I reformatted the code as a code block so itâs easier to read. The way to do this is to select the code and then click on the âPreformatted textâ button in the toolbar here.