[FieldTrip] Leadfield computation generates NaNs

二姬 wcy131608 at gmail.com
Sun Feb 18 08:41:01 CET 2024


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> 于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/20240218/aea909f6/attachment.htm>


More information about the fieldtrip mailing list