[FieldTrip] Leadfield computation generates NaNs
Topkan, Tugberk
Tugberk.Topkan at medizin.uni-leipzig.de
Sun Feb 18 06:28:20 CET 2024
Dear Fieldtrip experts,
I am currently trying to carry out source localization of EEG oscillations of a dataset. Although computation of leadfields of some participants seems fine, the computations of most participants generate only NaNs in leadfield matrices. I took a look at the previous messages and saw that many researchers also experienced the same problem, but could not find any relevant solution.
I would really appreciate it, if the experts with more experience on it could guide me to solve this problem.
Here is the code I currently use.
ft_defaults;
mri = ft_read_mri('f73.nii');
ft_determine_coordsys(mri)
cfg = [];
cfg.method = 'interactive'
[mri] = ft_volumerealign(cfg, mri);
save mri mri
cfg = [];
cfg.output = {'brain','skull','scalp'};
cfg.scalpthreshold = 0.05;
segmentedmri = ft_volumesegment(cfg, mri);
save segmentedmri segmentedmri
cfg = [];
cfg.tissue = {'brain','skull','scalp'};
cfg.numvertices = [3000 2000 1000];
bnd = ft_prepare_mesh(cfg,segmentedmri);
save bnd bnd
cfg = [];
cfg.method = 'bemcp';
vol = ft_prepare_headmodel(cfg, bnd);
save vol vol
cfg = [];
cfg.tissue = 'scalp';
cfg.numvertices = 10000;
scalp = ft_prepare_mesh(cfg, segmentedmri);
save scalp scalp
%get elec info
load(fullfile(current_dir,'elec_template.mat'));
elec = ft_determine_coordsys(elec)
% markerpos = table2cell(readtable(['load(fullfile('C:\Users\......',['elec_template.mat']));marker_positions_' subj '.csv']));
% markerpos = table2cell(readtable(['marker_positions_P30.csv']));
markerpos = table2cell(readtable(['D:......\',[subj '.csv']]));
%%% align the electrodes %%%
for i = 1:length(markerpos)
elec.label{i} = char(markerpos{i,2});
elec.elecpos(i,:) = cell2mat(markerpos(i,3:5));
elec.chanunit{i} = 'V';
elec.chantype{i} = 'eeg';
end
elec.chanpos = elec.elecpos;
nas = mri.cfg.fiducial.nas;
lpa = mri.cfg.fiducial.lpa;
rpa = mri.cfg.fiducial.rpa;
transm = mri.transform;
nas = ft_warp_apply(transm,nas, 'homogenous');
lpa = ft_warp_apply(transm,lpa, 'homogenous');
rpa = ft_warp_apply(transm,rpa, 'homogenous');
% create a structure similar to a template set of electrodes
fid.elecpos = [nas; lpa; rpa]; % ctf-coordinates of fiducials
fid.label = {'nasion','Left Tragus','Right Tragus'}; % same labels as in elec
fid.unit = 'mm'; % same units as mri
% alignment
cfg = [];
cfg.method = 'fiducial';
cfg.target = fid; % see above
cfg.elec = elec;
cfg.headshape = vol; %scalp
cfg.fiducial = {'nasion','Left Tragus','Right Tragus'}; % labels of fiducials in fid and in elec
elec_aligned = ft_electroderealign(cfg);
cfg = [];
cfg.method = 'interactive';
cfg.elec = elec_aligned;
cfg.headshape = vol.bnd(3);
elec_aligned = ft_electroderealign(cfg);
save elec_aligned elec_aligned
% Create the sourcemodel
cfg = [];
cfg.resolution = 7.5;
cfg.threshold = 0.1;
cfg.smooth = 5;
cfg.headmodel = vol;
sourcemodel = ft_prepare_sourcemodel(cfg);
% Compute the leadfield
cfg = [];
cfg.sourcemodel = sourcemodel;
cfg.headmodel = vol;
cfg.elec = elec_aligned;
cfg.channel = {'all','-AFz','-M1','-M2','-nasion','-Left Eye','-Right Eye','-Left Tragus','-Right Tragus','-nose tip','-chin tip'};
cfg.reducerank = 3;
grid = ft_prepare_leadfield(cfg);
Thanks in advance,
Andac Topkan
University of Leipzig
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20240218/b46345b4/attachment.htm>
More information about the fieldtrip
mailing list