[FieldTrip] issues with ft_connectivityanalysis, interpolation, and parcellation in EEG

Schoffelen, J.M. (Jan Mathijs) jan.schoffelen at donders.ru.nl
Thu May 23 09:06:31 CEST 2019


Hi Christian,

The code ‘an sich’ looks OK’ish, although I don’t know your motivation for doing:


   [SourceData] = ft_sourcedescriptives([], SourceData);

Also, it is still not clear why the coherence matrix is larger than the number of dipoles in the source model.
You may want to check the output SourceData after ft_sourceanalysis, and compare it with the output of ft_sourcedescriptives.
Also, you may want to go through ft_connectivityanalysis step-by-step, using the debugging features in matlab (set a breakpoint at the beginning of the function, which allows you to step through and inspect the result of the execution of each line of code in the function).

Things to look at with priority are the presence of a SourceData.avg.mom field, and the dimension of each of the elements (after ft_sourceanalysis, and after ft_sourcedescriptives), and the input/output to the call to univariate2bivariate (which is called from ft_connectivityanalysis).

Best wishes,
Jan-Mathijs

On 22 May 2019, at 16:34, Christian Mista <cmista at ingenieria.uner.edu.ar<mailto:cmista at ingenieria.uner.edu.ar>> wrote:

Hi Jan-Mathijs,

Thank you for your replay. I tried to describe the problem as clear as possible, but it seems I ended omitting information in the process. Here is all my code so far. I still can't find what i'm doing wrong.

My data is a preprocessed continuous eeg recording.

% prepare layout
    cfg = [];
%I have to rotate the axis layout
    aux_elec         = chanloc.elec;
    aux_elec.pnt(:,1) = -chanloc.elec.pnt(:,2);
    aux_elec.pnt(:,2) = chanloc.elec.pnt(:,1);
%update direction
    chanloc.elec.pnt = aux_elec.pnt;
%layout for plotting
    cfg.elec          = chanloc.elec;
    layout            = ft_prepare_layout(cfg);

% subdivide into trials of 1 seconds 10% overlap
     cfg              = [];
% single number (in unit of time, typically seconds) of the required snippets
     cfg.length      = 1;
% single number (between 0 and 1 (exclusive)) specifying the fraction of overlap between snippets (0 = no overlap)
     cfg.overlap     = 0.1;
%cut
     data            = ft_redefinetrial(cfg, data);

%%  calculate cross-spectrum
    cfg               = [];
    cfg.method      = 'mtmfft';
    cfg.taper         = 'hanning';
%For connectivity analysis we need power and phase -> 'fourier'
    cfg.output        = 'fourier';
    cfg.keeptrials    = 'yes';
%frequency of interest foilim at 10 Hz +/- 1 Hz
    cfg.foi            = 10;
    cfg.tapsmofrq    = 1;
%frequency analysis
    freq1             = ft_freqanalysis(cfg, data);

%% Calculate source model
    [headmodel sourcemodel] = read_custom_head_source_model(freq1);  %function at the end of the email

%% do the source reconstruction
    cfg                    = [];
    cfg.frequency         = freq1.freq;
    cfg.method            = 'pcc';                   % Dynamic Imaging of Coherent Sources
    cfg.headmodel        = headmodel;
    cfg.grid                = sourcemodel;          % Our grid and the leadfield
    cfg.pcc.projectnoise   = 'yes';                   % estimate noise
    cfg.pcc.lambda        = '10%';                  % how to regularise
    cfg.pcc.keepfilter      = 'yes';                  % keep the spatial filter in the output
    cfg.pcc.realfilter       = 'yes';                  % retain the real values
    cfg.keeptrials          = 'yes';
    cfg.senstype           = 'eeg';

    SourceData = ft_sourceanalysis(cfg, freq1);
   [SourceData] = ft_sourcedescriptives([], SourceData);

   %% connectivity (this is the code I posted before)
    cfg         = [];
    cfg.method  = 'coh';
    cfg.complex = 'absimag';
    source_conn = ft_connectivityanalysis(cfg, SourceData);

    %The conectome
    figure;imagesc(source_conn.cohspctrm);

    %Parcellation
    atlas = ft_read_atlas('/fieldtrip-master/template/atlas/aal/ROI_MNI_V4.nii');

    cfg = [];
    cfg.interpmethod='nearest';
    cfg.parameter='tissue';
    [int_atlas] = ft_sourceinterpolate(cfg, atlas, source_conn);
    int_atlas.pos = source_conn.pos; % otherwise the parcellation won't work

    % and call ft_sourceparcellate:
    cfg = [];
    cfg.parcellation = 'tissue';
    cfg.parameter    = 'cohspctrm';
    parc_conn = ft_sourceparcellate(cfg, source_conn, int_atlas);

    figure;imagesc(parc_conn.cohspctrm);

+++ continue code


function [hdm lf] = read_custom_head_source_model(data)
%% read labels and search positions in template
    elec = ft_read_sens('standard_1020.elc');
    % Change unit for visivility
    data.elec.unit = 'mm';

    for labelindex = 1:length(data.label)
       %position of my electrodes in the template standard_1020
       Index = find(strcmpi(elec.label, data.label{labelindex}));

       %writing the real position of the electrodes in my data
       data.elec.chanpos(labelindex,:) = elec.chanpos(Index,:);
       data.elec.elecpos(labelindex,:) = elec.elecpos(Index,:);
    end

% Load template head model
    load('/fieldtrip-master/template/headmodel/symetric_headmodel.mat')
    headmodel = ft_convert_units(headmodel, data.elec.unit);

%% compute the leadfield
    cfg                = [];
    cfg.elec           = data.elec;
    cfg.elec.unit     = 'mm';
    cfg.headmodel    = headmodel;
    cfg.grid.resolution = 20;           % use a 3-D grid with a 20 mm resolution
    [lf] = ft_prepare_leadfield(cfg);
end

I attached a figure how the source nai index looks in a sourceplot. Thanks for your help.

All the best,
Christian

El mar., 21 may. 2019 a las 15:44, Schoffelen, J.M. (Jan Mathijs) (<jan.schoffelen at donders.ru.nl<mailto:jan.schoffelen at donders.ru.nl>>) escribió:
Hi Christian,

I guess you need to figure out why the dimension of the coherence matrix does not match the expectations.
Based on the information you provide (i.e. the lack thereof: it’s not clear how you compute SourceData, and how you spectrally transformed your sensor data that goes into the source reconstruction step) there is lottle to go on.

Best wishes,
Jan-Mathijs



On 21 May 2019, at 19:27, Christian Mista <cmista at ingenieria.uner.edu.ar<mailto:cmista at ingenieria.uner.edu.ar>> wrote:

Hi FieldTrip community,

I've been trying to perform a connectivity analysis using a 66 eeg recording database. So far, I've being able to solve the sourceanalysis (following the tutorial http://www.fieldtriptoolbox.org/tutorial/networkanalysis/) and plot the source activity. However, the problem starts when I'm trying the connectivity analysis. Any grid dimension lower than 20 mm in the sourcemodel calculation results in a matlab error (Out of memory) in the connectivity analysis. I guess that a grid dimension lower than 20 mm conveys to huge matrix sizes, not manageable by my OS (linux + Matlab).

%% This is how I compute the sourcemodel (run ok)
    cfg                 = [];
    cfg.elec            = data.elec;
    cfg.elec.unit = 'mm';                   % unit in cm
    cfg.headmodel       = headmodel;
    cfg.grid.resolution = 20;     % use a 3-D grid with a 20 mm resolution
    [lf] = ft_prepare_leadfield(cfg);


After computing the sourcemodel using the 20 mm grid, I have issues to parcellate my data. My main concern is about the mismatch size between the connectivity matrix and the atlas.

source_conn =
          dim: [7 9 8]
       inside: [504×1 logical]
          pos: [504×3 double]
    cohspctrm: [5544×5544 double]
       dimord: 'pos_pos_freq'
         freq: 10
          cfg: [1×1 struct]


atlas =
            dim: [91 109 91]
            hdr: [1×1 struct]
      transform: [4×4 double]
           unit: 'mm'
         tissue: [91×109×91 double]
    tissuelabel: {1×116 cell}
       coordsys: 'mni'

I'd tried to interpolate and parcellate the matrix, but I must be missing or confusing something... Below is the code to calculate the connectivity and the parcellation.

%% connectivity
    cfg         = [];
    cfg.method  = 'coh';
    cfg.complex = 'absimag';
    source_conn = ft_connectivityanalysis(cfg, SourceData);

    %The conectome
    figure;imagesc(source_conn.cohspctrm); %5544x5544 double

    %Parcellation
    atlas = ft_read_atlas('/fieldtrip-master/template/atlas/aal/ROI_MNI_V4.nii');

    cfg = [];
    cfg.interpmethod='nearest';
    cfg.parameter='tissue';
    [int_atlas] = ft_sourceinterpolate(cfg, atlas, source_conn);
    int_atlas.pos = source_conn.pos; % otherwise the parcellation won't work

    % and call ft_sourceparcellate:
    cfg = [];
    cfg.parcellation = 'tissue';
    cfg.parameter    = 'cohspctrm';
    parc_conn = ft_sourceparcellate(cfg, source_conn, int_atlas);

    figure;imagesc(parc_conn.cohspctrm);

++Error in command windows matlab

there are in total 504 positions, 230 positions are inside the brain, 181 positions have a label
168 of the positions inside the brain have a label
168 of the labeled positions are inside the brain
62 of the positions inside the brain do not have a label
Error using ft_notification (line 340)
unsupported dimord unknown_unknown_freq

Error in ft_error (line 39)
  ft_notification(varargin{:});

Error in ft_sourceparcellate (line 309)
    ft_error('unsupported dimord %s', dimord{i})

Two questions
-Is 20 mm the min grid size to calculate connectivity?
-What I'm missing in the parcellation process?

I would really appreciate any advice, I've been scratching my head for a while on this one.

Best,
Christian
_______________________________________________
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
<sourceNAI.jpg>_______________________________________________
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/20190523/03166e10/attachment-0002.html>
-------------- next part --------------
_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
https://doi.org/10.1371/journal.pcbi.1002202


More information about the fieldtrip mailing list