[FieldTrip] Fwd: EEG beamformer source analyses

Schoffelen, J.M. (Jan Mathijs) jan.schoffelen at donders.ru.nl
Tue Sep 15 14:32:22 CEST 2020



Begin forwarded message:

From: Patrick Wiegel <patrick.wiegel at sport.uni-freiburg.de<mailto:patrick.wiegel at sport.uni-freiburg.de>>
Subject: Re: [FieldTrip] EEG beamformer source analyses
Date: 15 September 2020 at 14:30:18 CEST
To: "jan.schoffelen at donders.ru.nl<mailto:jan.schoffelen at donders.ru.nl>" <jan.schoffelen at donders.ru.nl<mailto:jan.schoffelen at donders.ru.nl>>

Dear Jan,

it seemed to be indeed a path problem. I was not aware that SPM was on my path all the time as well and as soon as I removed SPM from the path the error did not appear at that line.

However, it seems there is another problem with the data/code. I cannot understand the error message (see below). It would be great if you help out.

I checked my headmodel (constructed from the template MRI) and the corresponding electrode alignment. Both look good I think (see attachment).

Is it because of the warning that the dipole collides with one of the electrodes?

Best, Patrick





Here is the code that appears once I start the section.

the input is freq data with 64 channels, 1 frequencybins and no timebins
the call to "ft_selectdata" took 0 seconds and required the additional allocation of an estimated 2 MB
converting the linearly indexed channelcombinations into a square CSD-matrix
computing the leadfields on the fly
Your data and configuration allow for multiple sensor definitions.
Warning: using electrodes specified in the configuration\n
determining source compartment (3)
electrode transfer and system matrix were already combined
creating sourcemodel based on user specified dipole positions
using electrodes specified in the configuration
3466 dipoles inside, 3266 dipoles outside brain
the call to "ft_prepare_sourcemodel" took 0 seconds and required the additional allocation of an estimated 3 MB
computing forward model on the fly
scanning grid
scanning grid 64/3466
Warning: dipole collides with one of the electrodes
 In eeg_infinite_dipole at line 64
 In eeg_leadfieldb at line 92
 In ft_compute_leadfield at line 432
 In ft_inverse_dics at line 375
 In ft_sourceanalysis at line 763

Error using svd
Input to SVD must not contain NaN or Inf.

Error in ft_inverse_dics>pinv (line 590)
  [U,S,V] = svd(A,0);

Error in ft_inverse_dics (line 475)
        filt = pinv(lf' * invC * lf) * lf' * invC; % Gross eqn. 3 & van Veen eqn. 23, use PINV/SVD to cover rank deficient
        leadfield

Error in ft_sourceanalysis (line 763)
          dip(i) = ft_inverse_dics(sourcemodel, sens, headmodel, [],  squeeze_Cf, methodopt{:}, leadfieldopt{:});

Error in BEAMformer (line 133)
sourceAll = ft_sourceanalysis(cfg, frequ_all);



Patrick Wiegel
Department of Sport and Sport Science

University of Freiburg
Sandfangweg 4
79117 Freiburg i. Br .

phone: +49 (0)761/ 203-4550
email: patrick.wiegel at sport.uni-freiburg.de<mailto:patrick.wiegel at sport.uni-freiburg.de>
web: www.sport.uni-freiburg.de<http://www.sport.uni-freiburg.de>

Am 15.09.2020 um 12:00 schrieb Schoffelen, J.M. (Jan Mathijs) <jan.schoffelen at donders.ru.nl<mailto:jan.schoffelen at donders.ru.nl>>:

OK, thanks for updating.

What’s the error stack now?

Also, are you sure that you don’t have a messed up matlab path (e.g. have an overloaded rusty version from EEGLAB/SPM included)?

If the error is the same, i.e. something happening in ‘ft_checkconfig, line 307’, this suggests that MATLAB still ends up using outdated code.

Best wishes,
JM


On 15 Sep 2020, at 11:53, Patrick Wiegel <patrick.wiegel at sport.uni-freiburg.de<mailto:patrick.wiegel at sport.uni-freiburg.de>> wrote:

Dear Jan-Mathijs,

thanks for the note. I updated the version but the error still appears.

I attached my script if that helps to understand the issue.

Best, Patrick



Patrick Wiegel
Department of Sport and Sport Science

University of Freiburg
Sandfangweg 4
79117 Freiburg i. Br .

phone: +49 (0)761/ 203-4550
email: patrick.wiegel at sport.uni-freiburg.de<mailto:patrick.wiegel at sport.uni-freiburg.de>
web: www.sport.uni-freiburg.de<http://www.sport.uni-freiburg.de/>

Am 15.09.2020 um 11:15 schrieb Schoffelen, J.M. (Jan Mathijs) <jan.schoffelen at donders.ru.nl<mailto:jan.schoffelen at donders.ru.nl>>:

Dear Patrick,

Just to be sure: can you get the latest release version of the code and try whether this error persists (e.g. http://github.com/fieldtrip/fieldtrip/releases/tag/20200911)? The reason I ask is that your reported line number (i.e. line 217 in ft_sourcenalasysis) that throws the error does not match the current state of the code. I’d like to be sure that this is a genuine error, or that you happen to have stumbled upon a dysfunctional version (for which we humbly apologize :) ).

Best wishes,
Jan-Mathijs


On 15 Sep 2020, at 10:55, Patrick Wiegel <patrick.wiegel at sport.uni-freiburg.de<mailto:patrick.wiegel at sport.uni-freiburg.de>> wrote:

Dear Fieldtrip community,

I am a PhD student from Germany and I am working with EEG data. I would like to do Beamformer source analyses on power data.

I don’t have individual MRIs or related electrode positions available, so I am taking the standard MRI and BEM headmodel from the fieldtrip templates. Doing the source_analyses, I am getting an error message. Can anyone tell me if I missed something and what the reason for that error is? The error appears when running the last part of the script ft_sourceanalyses:



the input is freq data with 64 channels, 1 frequencybins and no timebins
Undefined function or variable 'fieldname'.

Error in ft_checkconfig (line 307)
    for i=1:length(fieldname)

Error in ft_sourceanalysis (line 217)
cfg = ft_checkconfig(cfg, 'createtopcfg', cfg.method);

Error in BEAMformer (line 116)
sourceAll = ft_sourceanalysis(cfg, frequ_all);


I added my code below. I would appreciate any help. I added information on my existing variables below the code.

Best, Patrick

%% import EEG data
EEG_Data = eeglab2fieldtrip( EEG, 'raw', 'none' );

%% define trials for frequency analyses
cfg = [];
cfg.trials = Indexes_correct{1, 1};
cfg.toilim = [0.25 0.55];
data_fed_correct = ft_redefinetrial(cfg, EEG_Data);


cfg = [];
cfg.trials = Indexes_incorrect{1, 1};
cfg.toilim = [0.25 0.55];
data_fed_incorrect = ft_redefinetrial(cfg, EEG_Data);

%% run frequenc analyses
cfg = [];
cfg.method    = 'mtmfft';
cfg.output    = 'powandcsd';
cfg.tapsmofrq = 4;
cfg.foilim    = [25 25];
frequ_correct = ft_freqanalysis(cfg, data_fed_correct);

cfg = [];
cfg.method    = 'mtmfft';
cfg.output    = 'powandcsd';
cfg.tapsmofrq = 4;
cfg.foilim    = [25 25];
frequ_incorrect = ft_freqanalysis(cfg, data_fed_incorrect);

cfg = [];
cfg.method    = 'mtmfft';
cfg.output    = 'powandcsd';
cfg.tapsmofrq = 4;
cfg.foilim    = [25 25];
frequ_all = ft_freqanalysis(cfg,EEG_Data);


%% load MRI and BEM templates
load('/Users/patrickwiegel/Documents/MATLAB/Scripts/2020/TF_Data/fieldtrip-20200603/template/headmodel/standard_bem.mat')
load('/Users/patrickwiegel/Documents/MATLAB/Scripts/2020/TF_Data/fieldtrip-20200603/template/headmodel/standard_mri.mat')

%% segment mri
cfg = [];
cfg.write      = 'no';
[segmentedmri] = ft_volumesegment(cfg, mri);

disp(segmentedmri)
%%
mri = ft_volumereslice(cfg, segmentedmri);
display(mri)


%% align electrodes
load('elec_aligned')
elec_aligned = ft_convert_units(elec_aligned, 'cm');
vol = ft_convert_units(vol, 'cm'); % Convert the vol to cm, because the CTF convenction is to express everything in cm.

%%
[headmodel, elec_aligned]=ft_prepare_vol_sens (vol,elec_aligned);

cfg           = [];
cfg.method    = 'interactive';
cfg.elec      = elec_aligned;
cfg.headshape = headmodel.bnd(1);
elec_aligned  = ft_electroderealign(cfg);

%%
% construct the dipole grid in the template brain coordinates
% the negative inwardshift means an outward shift of the brain surface for inside/outside detection
cfg              = [];
cfg.resolution   = 1;
cfg.tight        = 'yes';
cfg.inwardshift  = -1.5;
cfg.headmodel    = headmodel;
sourcemodel    = ft_prepare_sourcemodel(cfg);

%%
cfg              = [];
cfg.method       = 'dics';
cfg.frequency    = 25;
cfg.sourcemodel  = sourcemodel;
cfg.headmodel    = headmodel;
cfg.elec         = elec_aligned;
cfg.dics.projectnoise = 'yes';
cfg.dics.lambda       = '5%';
cfg.dics.keepfilter   = 'yes';
cfg.dics.realfilter   = 'yes';
sourceAll = ft_sourceanalysis(cfg, frequ_all);





sourcemodel =

  struct with fields:

       dim: [17 22 18]
       pos: [6732×3 double]
      unit: 'cm'
    inside: [6732×1 logical]
       cfg: [1×1 struct]





elec_aligned =

  struct with fields:

        chanpos: [64×3 double]
       chantype: {64×1 cell}
       chanunit: {64×1 cell}
        elecpos: [64×3 double]
    homogeneous: [4×4 double]
          label: {1×64 cell}
            tra: [64×64 double]
           type: 'eeg1010'
           unit: 'cm'
            cfg: [1×1 struct]





headmodel =

  struct with fields:

                    bnd: [1×3 struct]
                   cond: [0.3300 0.0041 0.3300]
                    mat: [64×3000 double]
                   type: 'dipoli'
                   unit: 'cm'
           skin_surface: 1
    inner_skull_surface: 3
                 source: 3


Patrick Wiegel
Department of Sport and Sport Science

University of Freiburg
Sandfangweg 4
79117 Freiburg i. Br .

phone: +49 (0)761/ 203-4550
email: patrick.wiegel at sport.uni-freiburg.de<mailto:patrick.wiegel at sport.uni-freiburg.de>
web: www.sport.uni-freiburg.de<http://www.sport.uni-freiburg.de/>

_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
https://doi.org/10.1371/journal.pcbi.1002202

_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
https://doi.org/10.1371/journal.pcbi.1002202

<BEAMformer.m>_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
https://doi.org/10.1371/journal.pcbi.1002202

_______________________________________________
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/20200915/054623d1/attachment-0002.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: electrodes+head.fig
Type: application/octet-stream
Size: 99941 bytes
Desc: electrodes+head.fig
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20200915/054623d1/attachment-0001.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20200915/054623d1/attachment-0003.htm>


More information about the fieldtrip mailing list