[FieldTrip] R: EEG source analysis Leadfield issue
Elisa Tatti
elisatatti at msn.com
Thu Dec 10 22:14:02 CET 2020
Thank you very much Vahab!
In the end we managed to create a good leadfield model by computing our own headmodel instead of loading a Fieldtrip one. Our scale is lower than the the one shown in the tutorial but the leadfield looks ok!
I am going to get back to your answer in the future and try to use SPM for the forward model. Indeed, I hope your answer is going to be useful to other users as well!
Best wishes.
Elisa
Elisa Tatti, Ph.D
Post Doctoral Research Fellow
CUNY, School of Medicine
160 Convent ave
10031
New York City, NY
Tel. +1 3472043952
________________________________
Da: Youssofzadeh, Vahab <vyoussofzadeh at mcw.edu>
Inviato: giovedì 10 dicembre 2020 13:24
A: Elisatatti at msn.com <Elisatatti at msn.com>
Oggetto: EEG source analysis Leadfield issue
Hi Elisa,
I saw your post in the FT community, I am no expert by all means in EEG source modeling, however, I had a similar issue with a hdEEG dataset I was working on 2 years ago. I thought these scripts might be helpful. For forwarding modeling and channel alignment, I used SPM, and I found it superior to FT functions. It is a bit mess, hope you can grab the required details (eg, you can comment the spm beamforming part),
%% forward model from SPM
outputdir1 = fullfile(outputdir, 'spm_source');
cd(outputdir1);
name = ['m',subj,'_',run];
if exist([name,'.mat'], 'file') == 2
D = spm_eeg_load(name);
else
cfg = [];
cfg.toilim = [-0.4 1];
eint_data = ft_redefinetrial(cfg, data);
vy_source_spm(eint_data,mridir,name);
D = spm_eeg_load(name);
end
% cd(outputdir)
volsens = spm_eeg_inv_get_vol_sens(D, 1, 'MNI-aligned', 'inv', 'EEG');
clear D
vol = volsens.EEG.vol;
sens = volsens.EEG.sens;
vol = ft_convert_units(vol,'mm');
sens = ft_convert_units(sens,'mm');
[vol, sens] = ft_prepare_vol_sens(vol, sens, 'channel', data.label');
grid = vy_leadfield_eeg(sens, vol);
% figure; ft_plot_vol(vol, 'edgecolor', 'none', 'facealpha', 0.2); camlight;
% hold on
% ft_plot_mesh(grid.pos(grid.inside, :));
% view([-45 20]);
function vy_source_spm(int_data,mridir,subj)
%% initial settings
% restoredefaultpath
spm_path = 'F:\My Matlab\SPM\spm12_4\spm12\spm12';
addpath(genpath(spm_path))
%%
D = spm_eeg_ft2spm(int_data, subj);
%% Avergaring
% datafile3 = ['.\aefspmeeg_',name];
% S = [];
% S.D = name;
% S.robust = false;
% S.prefix = 'm';
% D = spm_eeg_average(S);
% % spm_eeg_review(D)
% D.save
% D = spm_eeg_load(datafile3);
% spm_eeg_review(D)
%% Re-ref
% S = [];
% S.D = D;
% S.refchan = 'average';
% [D, ~] = spm_eeg_reref_eeg(S);
% D.save
% spm_eeg_review(D)
%% adding layout, elec pos
layout = 'F:\My Matlab\My codes\My GitHub\fieldtrip_041718\fieldtrip-master\template\electrode\GSN-HydroCel-256.sfp';
S = [];
S.D = D;
S.task = 'loadeegsens';
S.source = 'locfile';
S.sensfile = layout;
D = spm_eeg_prep(S);
D.save
% spm_eeg_review(D)
%% Create 2D channel layout
S = [];
S.task = 'project3D';
S.modality = 'EEG';
S.updatehistory = 1;
S.D = D;
D = spm_eeg_prep(S);
D.save
% spm_eeg_review(D)
%%
path_montage = 'F:\My Matlab\My codes\My scripts\UTHSC\hd-EEG\My scripts\SPM analysis\Data_file';
S = [];
S.D = D;
S.task = 'montage';
S.montagefile = {fullfile(path_montage,'Data_file/montage')};
S.keepothers = 0;
% S.montage.mode.write.blocksize = 655360;
S.prefix = 'g';
D = spm_eeg_prep(S);
% spm_eeg_review(D)
D.save
%% mri segmentation & mesh generation
sMRI = fullfile(mridir,[subj,'_T1.nii']);
if exist(sMRI, 'file') ~= 2
sMRI = 'F:\My Matlab\SPM\spm12_4\spm12\spm12\canonical\single_subj_T1.nii';
end
Msize = 2; val = 1;
D = spm_eeg_inv_mesh_ui(D, val, sMRI, Msize);
D.save
% spm_eeg_review(D)
%% Coreg
selection = 1:3;
eegfid = D.fiducials;
eegfid.fid.pnt = eegfid.fid.pnt(selection, :);
eegfid.fid.label = eegfid.fid.label(selection);
newmrifid = D.inv{val}.mesh.fid;
newmrifid.fid.pnt = D.inv{val}.mesh.fid.fid.pnt(1:3,:);
newmrifid.fid.label = {'FidNz';'FidT9';'FidT10'}; %{'Nasion';'LPA';'RPA'};
useheadshape = 1;
D = spm_eeg_inv_datareg_ui(D, val, eegfid, newmrifid, useheadshape);
S.prefix = 'e';
D.save
% D = spm_eeg_inv_datareg_ui(D);
%% forward modelling
D.inv{1}.forward(1).voltype = 'EEG BEM';
D = spm_eeg_inv_forward(D);
spm_eeg_inv_checkforward(D,1);
% D = spm_eeg_inv_forward_ui(D);
D.save
% spm_eeg_review(D)
%% source BF
% datafile = ['.\e',name];
% D = spm_eeg_load(datafile);
S = [];
S.D = D;
S.trigger{1} = {'Undefined'};
S.timewindows{1}=[.4;.7];
S.timewindows{2}=[-.3;0];
S.trigger{2} = {'Undefined'};
S.freqbands{1} = [2,30];
S.gridstep = 6;
S.regpc = 10;
S.preview = 1;
spm_eeg_ft_beamformer_gui(S);
%% Avergaring
S = [];
S.D = D;
S.robust = false;
S.prefix = 'm';
D = spm_eeg_average(S);
% spm_eeg_review(D)
D.save
%% source task
% inv_typ = 'GS';% 'GS'; %'COH'; % (MSP)%inv_typ = 'IID'; % Minimum Norm Least-Squares
inv_typ = 'COH'; % Loreta
woi = [-400 999];
D.inv{val}.inverse = [];
D.inv{val}.inverse.type = inv_typ;
D.inv{val}.inverse.lpf = 0.1;
D.inv{val}.inverse.hpf = 48;
D.inv{val}.inverse.woi = woi;
D.inv{val}.inverse.Han = 1;
D.inv{val}.inverse.modality = {'eeg'};
D = spm_eeg_invert(D);
D.save
woi1 = [400,700];
con_win = {woi1; 0};
D.inv{val}.contrast.woi = con_win{1};
D.inv{val}.contrast.fboi = con_win{2};
D.inv{val}.contrast.type = 'evoked';
D = spm_eeg_inv_results(D);
savepath = ['t',num2str(con_win{1}(1)),'_',num2str(con_win{1}(2))];
hcp_write_figure([savepath,'.png'], gcf, 'resolution', 300);
D.inv{val}.contrast.smooth = 12;
D.inv{val}.contrast.format = {'image'};
D = spm_eeg_inv_Mesh2Voxels(D);
D.save
% spm_eeg_inv_imag_api
%
% inv_typ = 'COH'; % Loreta
% woi = [-400 999];
% D.inv{val}.inverse = [];
% D.inv{val}.inverse.type = inv_typ;
% D.inv{val}.inverse.lpf = 0;
% D.inv{val}.inverse.hpf = 48;
% D.inv{val}.inverse.woi = woi;
% D.inv{val}.inverse.Han = 1;
% D.inv{val}.inverse.modality = {'eeg'};
% D = spm_eeg_invert(D);
%
% con_win = {woi; 0};
% D.inv{val}.contrast.woi = con_win{1};
% D.inv{val}.contrast.fboi = con_win{2};
% D.inv{val}.contrast.type = 'evoked';
% D = spm_eeg_inv_results(D);
%
% D.inv{val}.contrast.smooth = 12;
% D.inv{val}.contrast.format = {'image'};
% D = spm_eeg_inv_Mesh2Voxels(D);
% D.save
% D = spm_eeg_invert_ui(D);
% spm_eeg_inv_imag_api
% spm_eeg_inv_imag_api(D)
function leadfield_eeg = vy_leadfield_eeg(elec, vol)
% begin with leadfield computation
% clear grid
cfg = [];
cfg.elec = elec;
cfg.headmodel = vol;
cfg.reducerank = 3;
cfg.grid.resolution = 12; % specified in mm
% cfg.grid.tight = 'yes';
leadfield_eeg = ft_prepare_leadfield(cfg);
I wasn’t confident to share this with the community 😃
Let me know if you need more details or had any questions.
Best,
Vahab
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20201210/914edb76/attachment.htm>
More information about the fieldtrip
mailing list