Source localization with only EEG data

Dear MNE users,

When I have only EEG data (19 ch zeto dry EEG electrode, resting state EEG (without triggers) without the position information of EEG sensors (for example, measured using polymus) and structural MRI for each subject. I tried to do source localization.

Here, I used standard position for EEG sensors and normalized MRI. Could you check my code? If something wrong, please let me know.

Kyu

import os.path as op
import numpy as np
import matplotlib.pyplot as plt

import mne
from mne.datasets import eegbci
from mne.datasets import fetch_fsaverage
from mne.minimum_norm import make_inverse_operator, apply_inverse
from mne.datasets import sample

# Download fsaverage files
fs_dir = fetch_fsaverage(verbose=True)
subjects_dir = op.dirname(fs_dir)

# The files live in:
subject = 'fsaverage'
trans = 'fsaverage'  # MNE has a built-in fsaverage transformation
src = op.join(fs_dir, 'bem', 'fsaverage-ico-5-src.fif')
bem = op.join(fs_dir, 'bem', 'fsaverage-5120-5120-5120-bem-sol.fif')

raw = mne.io.read_raw_edf('FEMALE_zhi7619.edf', preload=True)
# Clean channel names to be able to use a standard 1005 montage
new_names = dict(
    (ch_name,
     ch_name.rstrip('.').upper().replace('Z', 'z').replace('FP', 'Fp'))
    for ch_name in raw.ch_names)
raw.rename_channels(new_names)
raw.drop_channels('ECG')
raw.drop_channels('BIN PHOTIC')
# Read and set the EEG electrode locations

mont1020 = mne.channels.make_standard_montage('standard_1020')
del mont1020.ch_names
mont1020.ch_names = ['EEG Fp1', 'EEG Fpz', 'EEG Fp2', 'EEG AF9', 'EEG AF7', 'EEG AF5', 'EEG AF3', 'EEG AF1', 'EEG AFz', 'EEG AF2', 'EEG AF4', 'EEG AF6', 'EEG AF8', 'EEG AF10', 'EEG F9', 'EEG F7', 'EEG F5', 'EEG F3', 'EEG F1', 'EEG Fz', 'EEG F2', 'EEG F4', 'EEG F6', 'EEG F8', 'EEG F10', 'EEG FT9', 'EEG FT7', 'EEG FC5', 'EEG FC3', 'EEG FC1', 'EEG FCz', 'EEG FC2', 'EEG FC4', 'EEG FC6', 'EEG FT8', 'EEG FT10', 'EEG T9', 'EEG T7', 'EEG C5', 'EEG C3', 'EEG C1', 'EEG Cz', 'EEG C2', 'EEG C4', 'EEG C6', 'EEG T8', 'EEG T10', 'EEG TP9', 'EEG TP7', 'EEG CP5', 'EEG CP3', 'EEG CP1', 'EEG CPz', 'EEG CP2', 'EEG CP4', 'EEG CP6', 'EEG TP8', 'EEG TP10', 'EEG P9', 'EEG P7', 'EEG P5', 'EEG P3', 'EEG P1', 'EEG Pz', 'EEG P2', 'EEG P4', 'EEG P6', 'EEG P8', 'EEG P10', 'EEG PO9', 'EEG PO7', 'EEG PO5', 'EEG PO3', 'EEG PO1', 'EEG POz', 'EEG PO2', 'EEG PO4', 'EEG PO6', 'EEG PO8', 'EEG PO10', 'EEG O1', 'EEG Oz', 'EEG O2', 'EEG O9', 'EEG Iz', 'EEG O10', 'EEG T3', 'EEG T5', 'EEG T4', 'EEG T6', 'EEG M1', 'EEG M2', 'EEG A1', 'EEG A2']

raw = raw.set_montage(mont1020)
raw.set_eeg_reference(projection=True)  # needed for inverse modeling

epochs = mne.make_fixed_length_epochs(raw, duration=30, preload=False)

fwd = mne.make_forward_solution(raw.info, trans=trans, src=src,
                                bem=bem, eeg=True, mindist=5.0, n_jobs=1)


noise_cov = mne.compute_covariance(epochs, tmax=0., method=['shrunk', 'empirical'])
evoked = epochs.average().pick_types(eeg=True)

info = evoked.info
inverse_operator = make_inverse_operator(info, fwd, noise_cov,
                                         loose=0.2, depth=0.8)
del fwd

method = "dSPM"
snr = 3.
lambda2 = 1. / snr ** 2
stc = apply_inverse(evoked, inverse_operator, lambda2,
                    method=method, pick_ori=None)

vertno_max, time_max = stc.get_peak(hemi='rh')
data_path = sample.data_path()
subjects_dir = data_path + '/subjects'
surfer_kwargs = dict(
    hemi='rh', subjects_dir=subjects_dir,
    clim=dict(kind='value', lims=[8, 12, 15]), views='lateral',
    initial_time=time_max, time_unit='s', size=(800, 800), smoothing_steps=5)
brain = stc.plot(**surfer_kwargs)
brain.add_foci(vertno_max, coords_as_verts=True, hemi='rh', color='blue',
               scale_factor=0.6, alpha=0.5)
brain.add_text(0.1, 0.9, 'dSPM (plus location of maximal activation)', 'title',
               font_size=14)

Hi MNE users, could you check my code? I am waiting for your reply. You feedback is very helpful for me.
Thanks, Kyu

Hi MNE users, if you give me any feedback about the code above, I really appreciate it. I am waiting any feedback. Thanks.

Kyu

Hi @kyuwanchoi, do you have any specific question or worry regarding the code you posted? I think you will get more replies this way.

Mikolaj, thanks for your feedback. I would like to do source localization from only EEG. Could you check my code? Is it Okay? I need your feedback.

I’m sorry, Kyu, but reviewing 70 lines of code is not a service we normally provide in this forum. If you want help from the MNE-Python developers, you need to ask specific questions, provide minimal code samples, and demonstrate that you’ve put in some effort to find the answers yourself first. This is a fairly well-established etiquette when asking for programming help online; it is described in many places but this is a good summary:

Dan, I see. I understand. Thanks for your feedback! Kyu