Problems to interpolate channels in EEG

  • MNE-Python version: 0.23.0
  • operating system: Windows 10 Education 20H2

I followed the tutorials to create routine in order to preprocess EEG data for a resting EEG analysis.

But once i reached the point to interpolate bad channels i got the following error message which seems to be not known. Or at least, no one seemed to have this problem, yet.

Here, my code so far. If you need more infos, let me know:

# import libraries
import os
from copy import deepcopy
import numpy as np
import mne
from mne.preprocessing import (ICA, create_eog_epochs, create_ecg_epochs,corrmap)
import matplotlib
import matplotlib.pyplot as plt
from mne.preprocessing import annotate_muscle_zscore

# set working directory
print("Current Working Directory " , os.getcwd())
os.chdir('Z:/Project1_Encoding/02_Data/02_EEG/RAW_stim/')                                                   

#___________________________________________________________________________________________________________________________
# rest eeg before stim

included_extensions = ['RestPreStim.vhdr']
files = [f for f in os.listdir('.') if any(f.endswith(ext) for ext in included_extensions)]

# access to plots
%matplotlib qt 

for f in files [:1]: #[:1]
    raw_pre = mne.io.read_raw_brainvision(f)
    
    # marking and handling bad channels
    raw_pre.plot (block = True)
    print(raw_pre.info['bads'])
    
    raw_pre.load_data()
    # eeg_data = raw_pre.copy().pick_types(eeg=True, exclude=[])
    eeg_data_interp = eeg_data.copy().interpolate_bads(method=dict(eeg='MNE'), verbose=True)

What do I have to change, to get it work?

Best, Sven

Hello @SvenPassmann and welcome to the forum!

I think you forgot to include the actual error message here…?

uh damn… sorry, so here we go:

for f in files [:1]: #[:1]
    raw_pre = mne.io.read_raw_brainvision(f)
    
    # marking and handling bad channels
    raw_pre.plot (block = True)
    print(raw_pre.info['bads'])
    
    raw_pre.load_data()
    # eeg_data = raw_pre.copy().pick_types(eeg=True, exclude=[])
    eeg_data_interp = eeg_data.copy().interpolate_bads(method=dict(eeg='MNE'), verbose=True)
Extracting parameters from ThetaMEM_encoding_VP23_(Session01)_RestPreStim.vhdr...
Setting channel info structure...
Channels marked as bad: ['T7', 'T8', 'TP10', 'TP9']
['T7', 'T8', 'TP10', 'TP9']
Reading 0 ... 102719  =      0.000 ...   205.438 secs...
Interpolating bad channels
Traceback (most recent call last):

  File "<ipython-input-45-755c15541dc7>", line 10, in <module>
    eeg_data_interp = eeg_data.copy().interpolate_bads(method=dict(eeg='MNE'), verbose=True)

  File "<decorator-gen-39>", line 22, in interpolate_bads

  File "C:\Users\lape3812\Anaconda3\lib\site-packages\mne\channels\channels.py", line 1176, in interpolate_bads
    origin = _check_origin(origin, self.info)

  File "C:\Users\lape3812\Anaconda3\lib\site-packages\mne\bem.py", line 1002, in _check_origin
    R, origin = fit_sphere_to_headshape(info, verbose=False,

  File "<decorator-gen-57>", line 22, in fit_sphere_to_headshape

  File "C:\Users\lape3812\Anaconda3\lib\site-packages\mne\bem.py", line 855, in fit_sphere_to_headshape
    radius, origin_head, origin_device = _fit_sphere_to_headshape(

  File "<decorator-gen-59>", line 24, in _fit_sphere_to_headshape

  File "C:\Users\lape3812\Anaconda3\lib\site-packages\mne\bem.py", line 940, in _fit_sphere_to_headshape
    hsp = get_fitting_dig(info, dig_kinds)

  File "<decorator-gen-58>", line 24, in get_fitting_dig

  File "C:\Users\lape3812\Anaconda3\lib\site-packages\mne\bem.py", line 894, in get_fitting_dig
    raise RuntimeError('Cannot fit headshape without digitization '

RuntimeError: Cannot fit headshape without digitization , info["dig"] is None

Hi @SvenPassmann, the problem is that your Raw object (raw_pre) does not know about the locations of your electrodes:

Cannot fit headshape without digitization , info[“dig”] is None

Take a look at: mne.io.Raw — MNE 1.7.0.dev15+gb107d92ec documentation

If your EEG data was recorded with standard 10-20 positions, you can load a standard template montage and add these template locations to your Raw object.

Something like the following should work, but please read the docstrings carefully and follow the links to understand it properly:

raw_pre.set_montage(montage="standard_1020") # call this after reading the data

1 Like