[FieldTrip] Error in ft_sourceanalysis: DICS

Laura Rueda Delgado Laura.Rueda at faber.kuleuven.be
Tue Jun 3 15:30:56 CEST 2014


Dear Kousik,

I found that thread and made some tests on my data as well. The solution that is proposed there (reject the vertices of C11st/C22st where the NaN values are present) is not feasible in my case because I would need to reject 2908 vertices from the 3000 ones present in the brain compartment. Also, the xyz coordinates of these critical vertices (vol.bnd(1).pnt) and their corresponding triangles (vol.bnd(1).tri) do not converge into a single point, which would be the reason to reject them in the first place.

I’ve checked and re-checked the segmented volumes and meshes (errors at these steps seem to be the most common problem), but all the compartments are closed surfaces and do not intersect.

Best regards,

Laura Rueda Delgado

From: fieldtrip-bounces at science.ru.nl [mailto:fieldtrip-bounces at science.ru.nl] On Behalf Of kousik sarathy
Sent: dinsdag 3 juni 2014 14:47
To: FieldTrip discussion list
Subject: Re: [FieldTrip] Error in ft_sourceanalysis: DICS

Hey Laura,

I'm not very familiar with BEM's. I assumed the problem to be more superficial and it is not.

So I re-ran some codes and I too have a vol.vol that has only NaN's. I think the problem has been previously raised here.
http://mailman.science.ru.nl/pipermail/fieldtrip/2010-February/002618.html

Let's wait to see if someone more experienced has something to say.

--
Regards,
Kousik Sarathy, S


On Tue, Jun 3, 2014 at 10:28 AM, Laura Rueda Delgado <Laura.Rueda at faber.kuleuven.be<mailto:Laura.Rueda at faber.kuleuven.be>> wrote:
Dear Kousik,

The solution that you propose requires the use of Freesurfer to create the sourcespace. If I’d like to restrict to use Fieldtrip and its toolboxes, how could I constrain it to calculate leadfields for points inside the brain? I tried to restrict the ft_sourceanalysis by including only the points of the grid that are inside the brain, but I still get the SVD error.

I checked the NaN values of vol.mat and all the elements on this matrix are NaN. I suppose that’s where the error is, however I don’t know how to correct for it, because I just generate the volume structure from the mesh (see first message).


Best regards,

Laura Rueda Delgado

From: fieldtrip-bounces at science.ru.nl<mailto:fieldtrip-bounces at science.ru.nl> [mailto:fieldtrip-bounces at science.ru.nl<mailto:fieldtrip-bounces at science.ru.nl>] On Behalf Of kousik sarathy
Sent: woensdag 28 mei 2014 18:10

To: FieldTrip discussion list
Subject: Re: [FieldTrip] Error in ft_sourceanalysis: DICS

Oh. Yes.
FT puts NaN's into sourcespace points outside the brain. You can constrain FT to only calculate leadfields for sourcespace points inside the brain. I generally do this. I don't know how FT handles those outside the brain source points really. You could give this a try.

Check this tutorial/code:
http://fieldtrip.fcdonders.nl/tutorial/minimumnormestimate#forward_solution

--
Regards,
Kousik Sarathy, S


On Wed, May 28, 2014 at 6:01 PM, Laura Rueda Delgado <Laura.Rueda at faber.kuleuven.be<mailto:Laura.Rueda at faber.kuleuven.be>> wrote:
Dear Kousik,

I checked for NaN and Inf values in powspctrm and crsspctrm of freqAll. There are none. However, I checked for NaN values in grid.leadfield and it has some. I thought that these were NaN values in the points of the grid outside a brain region, but I might be mistaken.


grid =

        xgrid: [-58 -48 -38 -28 -18 -8 2 12 22 32 42 52 62 72 82 92 102]
        ygrid: [-61 -51 -41 -31 -21 -11 -1 9 19 29 39 49 59]
        zgrid: [-13 -3 7 17 27 37 47 57 67 77 87 97 107 117]
          dim: [17 13 14]
          pos: [3094x3 double]
         unit: 'mm'
       inside: [1x1516 double]
      outside: [1x1578 double]
          cfg: [1x1 struct]
    leadfield: {1x3094 cell}

Best regards,

Laura Rueda Delgado

From: fieldtrip-bounces at science.ru.nl<mailto:fieldtrip-bounces at science.ru.nl> [mailto:fieldtrip-bounces at science.ru.nl<mailto:fieldtrip-bounces at science.ru.nl>] On Behalf Of kousik sarathy
Sent: woensdag 28 mei 2014 17:37

To: FieldTrip discussion list
Subject: Re: [FieldTrip] Error in ft_sourceanalysis: DICS

Ah. Interesting. Good that error changes. So that was the problem before.

Now, can you check if your Freq matrices contain any NaN's (isnan(freqAll))?  It can happen sometimes.

--
Regards,
Kousik Sarathy, S


On Wed, May 28, 2014 at 5:31 PM, Laura Rueda Delgado <Laura.Rueda at faber.kuleuven.be<mailto:Laura.Rueda at faber.kuleuven.be>> wrote:
Dear Kousik,

I checked the labels and they were the same, except for whether they were in capital letters. So I added the following before ft_sourceanalysis:

freqAll.label=cellfun(@upper, freqAll.label, 'UniformOutput', 0);
freqAll.labelcmb=cellfun(@upper, freqAll.labelcmb, 'UniformOutput', 0);

This way the labels of the elec structure and freqAll are in capital letters.

And now I get a different error (although still within the function beamformer_dics):

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

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

Error in beamformer_dics (line 339)
        filt = pinv(lf' * invCf * lf) * lf' * invCf;              % Gross eqn. 3, use PINV/SVD to cover rank
        deficient leadfield

Error in ft_sourceanalysis (line 567)
      dip(i) = beamformer_dics(grid, sens, vol, [],  squeeze(Cf(i,:,:)), optarg{:});


What could it be?

Best regards,
Laura

From: fieldtrip-bounces at science.ru.nl<mailto:fieldtrip-bounces at science.ru.nl> [mailto:fieldtrip-bounces at science.ru.nl<mailto:fieldtrip-bounces at science.ru.nl>] On Behalf Of kousik sarathy
Sent: woensdag 28 mei 2014 17:10

To: FieldTrip discussion list
Subject: Re: [FieldTrip] Error in ft_sourceanalysis: DICS

Hey Laura,

I too had the same suggestion as Johanna's.

Another thing to check would be if the labels that you used for the leadfield estimation are the same as the freq data. I guess FT at some point would also check this to extract the indices.

--
Regards,
Kousik Sarathy, S


On Wed, May 28, 2014 at 4:51 PM, Laura Rueda Delgado <Laura.Rueda at faber.kuleuven.be<mailto:Laura.Rueda at faber.kuleuven.be>> wrote:
Dear Johanna,

Thank you for your suggestion.

On step 2 in the code, I select from the elec structure the channels that are included in the frequency data. So the elec structure used for preparing the leadfield has 128 electrodes, the same as the data (data_rs, data 4, and therefore freqAll). I checked this precisely because I read a previous thread discussing that issue.

Best regards,

Laura Rueda Delgado

From: fieldtrip-bounces at science.ru.nl<mailto:fieldtrip-bounces at science.ru.nl> [mailto:fieldtrip-bounces at science.ru.nl<mailto:fieldtrip-bounces at science.ru.nl>] On Behalf Of Johanna Zumer
Sent: woensdag 28 mei 2014 16:42
To: FieldTrip discussion list
Subject: Re: [FieldTrip] Error in ft_sourceanalysis: DICS

Hi Laura,

Does your data have the same channels as the leadfield (as the electrodes that went in to compute the leadfield)?   I often see that error when there is a mismatch of channels in that way.

Best,
Johanna

2014-05-28 15:29 GMT+01:00 Laura Rueda Delgado <Laura.Rueda at faber.kuleuven.be<mailto:Laura.Rueda at faber.kuleuven.be>>:
Dear Fieldtrip users,

I’m following the tutorial of beamformers (Source Analysis: Contrast activity to another interval<http://fieldtrip.fcdonders.nl/tutorial/beamformer>) to estimate oscillatory sources using DICS. I’ve checked the surface created after segmentation and the grid generated from the electrode positions and the headmodel. That seems to work ok. However, at the step of source analysis, I get the following error:

Error using  *
Inner matrix dimensions must agree.

Error in beamformer_dics (line 339)
        filt = pinv(lf' * invCf * lf) * lf' * invCf;              % Gross eqn. 3, use PINV/SVD to cover rank
        deficient leadfield

Error in ft_sourceanalysis (line 567)
      dip(i) = beamformer_dics(grid, sens, vol, [],  squeeze(Cf(i,:,:)), optarg{:});

Does anybody have an idea of what I’m doing wrong?
Thank you in advance for any help or suggestion!

-----------------------------------------------------------------
This is my code:
%% 1 - Preparation of MRI- source space
% Read MRI
mrifile = 'Subject01\Subject01.mri';
mri = ft_read_mri(mrifile);
% Reslice to reorient images
cfg              = [];
cfg.dim          = [256 256 256];
mri              = ft_volumereslice(cfg,mri);
% Segment compartments
cfg           = [];
cfg.output    = {'brain','skull','scalp'};
segmentedmri  = ft_volumesegment(cfg, mri);
% Prepare mesh
cfg=[];
cfg.tissue={'brain', 'skull','scalp'};
cfg.numvertices = [3000 2000 1000];
bnd=ft_prepare_mesh(cfg,segmentedmri);
% Prepare headmodel
cfg        = [];
cfg.method ='bemcp';
vol        = ft_prepare_headmodel(cfg, bnd);
%% 2- Prepare leadfield - Creating grid
load elec_aligned2 % Obtained after adjusting electrodes on scalp surface interactively
% Three fiducial markers were added to the electrode file, and now they're
% removed so that the electrode structure has the same number of channels as the data
elec_aligned2.chanpos = elec_aligned2.chanpos(1:128, :);
elec_aligned2.elecpos = elec_aligned2.elecpos(1:128, :);
elec_aligned2.label = elec_aligned2.label(1:128, :);
cfg =[];
cfg.vol             = vol;
cfg.elec = elec_aligned2;
cfg.grid.resolution = 10;
cfg.grid.unit       = 'mm';
[grid] = ft_prepare_leadfield(cfg);
%% 3- Join rest and task data
% data_rs: resting state data
% data4: data during task
dataAll = ft_appenddata([], data_rs, data4);
cfg = [];
cfg.method    = 'mtmfft';
cfg.output    = 'powandcsd';
cfg.tapsmofrq = 4;
cfg.foilim    = [18 18];
freqAll = ft_freqanalysis(cfg, dataAll);
%----------------------------------
% all seems normal until here
%----------------------------------
%% 4- Estimate source of all data
cfg              = [];
cfg.method       = 'dics';
cfg.frequency    = 18;
cfg.grid         = grid;
cfg.vol          = vol;
cfg.elec        = elec_aligned2;
cfg.dics.projectnoise = 'yes';
cfg.dics.lambda       = '5%';
cfg.dics.keepfilter   = 'yes';
cfg.dics.realfilter   = 'yes';
sourceAll = ft_sourceanalysis(cfg, freqAll);


Cheers,

Laura Rueda Delgado


_______________________________________________
fieldtrip mailing list
fieldtrip at donders.ru.nl<mailto:fieldtrip at donders.ru.nl>
http://mailman.science.ru.nl/mailman/listinfo/fieldtrip


_______________________________________________
fieldtrip mailing list
fieldtrip at donders.ru.nl<mailto:fieldtrip at donders.ru.nl>
http://mailman.science.ru.nl/mailman/listinfo/fieldtrip


_______________________________________________
fieldtrip mailing list
fieldtrip at donders.ru.nl<mailto:fieldtrip at donders.ru.nl>
http://mailman.science.ru.nl/mailman/listinfo/fieldtrip


_______________________________________________
fieldtrip mailing list
fieldtrip at donders.ru.nl<mailto:fieldtrip at donders.ru.nl>
http://mailman.science.ru.nl/mailman/listinfo/fieldtrip


_______________________________________________
fieldtrip mailing list
fieldtrip at donders.ru.nl<mailto:fieldtrip at donders.ru.nl>
http://mailman.science.ru.nl/mailman/listinfo/fieldtrip

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20140603/5161b98a/attachment-0002.html>


More information about the fieldtrip mailing list