[FieldTrip] Leadfield computation generates NaNs

Topkan, Tugberk Tugberk.Topkan at medizin.uni-leipzig.de
Tue Feb 20 08:50:30 CET 2024


Dear Chengyuan,


Thank you so much for your detailed response. I came across a few similar discussions and solution suggestions. Apparently, none of them works for my case. Setting up 'openmeeg' seems to be one possible option.


I still could not understand, why 'bemcp' method generates 'NaN's.


Thank you very much once again for your suggestions.


I would appreciate any other comments.


Dr. Andac Topkan
University of Leipzig
Department of Neurology


________________________________
From: fieldtrip <fieldtrip-bounces at science.ru.nl> on behalf of 二姬 via fieldtrip <fieldtrip at science.ru.nl>
Sent: Sunday, February 18, 2024 8:41:01 AM
To: FieldTrip discussion list
Cc: 二姬
Subject: Re: [FieldTrip] Leadfield computation generates NaNs

WARNUNG: Diese E-Mail kam von außerhalb der Organisation. Klicken Sie nicht auf Links oder öffnen Sie keine Anhänge, es sei denn, Sie kennen den Absender und wissen, dass der Inhalt sicher ist.

Dear Andac Topkan,

I came across your query regarding the computation of leadfields resulting in NaNs for most participants. While I am not an expert in leadfield computation myself, I recall encountering a similar discussion that might shed some light on the issue.

It has been noted that using the 'bemcp' method for leadfield computation could potentially lead to the generation of NaNs due to inherent algorithmic characteristics. A commonly suggested workaround is to explore alternative methods. For instance, the 'dipoli' method is highly recommended, albeit with the caveat that it requires a Linux environment and administrator permissions to run successfully.

Alternatively, the 'openmeeg' method presents another viable option, compatible with Windows systems. However, it's worth mentioning that setting up 'openmeeg' can be somewhat complex, and the available documentation might not provide the clarity needed for a straightforward installation.

If these methods do not offer a viable solution, you might consider utilizing Brainstorm. Brainstorm is known for its user-friendly, visual, and automated approach to source modeling, which could potentially circumvent the problem you're facing.

I hope this information proves helpful.

Best wishes in your research endeavors,

Chengyuan Wu

Topkan, Tugberk via fieldtrip <fieldtrip at science.ru.nl<mailto:fieldtrip at science.ru.nl>> 于2024年2月18日周日 13:44写道:

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


_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
https://doi.org/10.1371/journal.pcbi.1002202
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20240220/1baf8d61/attachment.htm>


More information about the fieldtrip mailing list