[FieldTrip] Error in ft_sourceanalysis: DICS

Laura Rueda Delgado Laura.Rueda at faber.kuleuven.be
Mon Jun 9 16:44:29 CEST 2014


Dear Jörn,

Thank you for your suggestion. 

I used the template BEM model with the corresponding MRI template and the code works fine. In the end, the problem was the capital letters on the labels of the electrodes on  the different structures. So at least for the sanity check, everything seems fine with the algorithm and the EEG data. 

Now I'm using an individual MRI from one of my subjects. I realigned according to the fiducials. I tried to reslice after this with a resolution of 1mm, and keeping the original dimensions, because the voxel size of my images is 1x1.1x1 mm, but this resulted in the head not being in the center of the box and the head tilted downwards, so I skipped this step to move on a bit (although I would kindly request some tip in this regard as well). Then I segmented the brain compartments (brain, skull and scalp) with tissue probability maps first, and I adjusted the size of the 3D shape used for dilating the brainmask (on strel_bol) to obtain the skull mask because the default value assigned points to the skull on the scalp, and they were clearly intersecting. 

After doing this, I checked the segmented compartments and the meshes. At least visually, these looked fine. When running ft_prepare_headmodel, I get a warning and the vol.mat is filled with NaNs. The warning is this one:

Matrix is singular, close to singular or badly scaled. Results may be inaccurate. RCOND = NaN. 
> In ft_headmodel_bemcp at 184
  In ft_prepare_headmodel at 253 

I read in another thread that visual inspection does not guarantee the creation of a head model. So, I wonder, is there other way of checking that the meshes are correctly formed?

Best regards,

Laura Rueda
________________________________________
From: fieldtrip-bounces at science.ru.nl [fieldtrip-bounces at science.ru.nl] on behalf of "Jörn M. Horschig" [jm.horschig at donders.ru.nl]
Sent: 03 June 2014 16:15
To: FieldTrip discussion list
Subject: Re: [FieldTrip] Error in ft_sourceanalysis: DICS

Hi Laura,

the problem could be in the segmentation - you have to have closed
boundaries of all tissues for the BEM model, otherwise the computation
can result in only nans. It requires a bit more work to check for this,
so I would first start with using the standard BEM model that is in the
FieldTrip/template/headmodel directory to check whether (a) your code
runs smoothly then and (b) your results make sense. Even though results
are less optimal than when using individual MRs, you can get a first
glimpse and it's a good sanity check for everything you are doing. If
these two things work well, then I can help you with checking your
segmentation (also on this mailinglist). Note though that that would be
more hacking than real fieldtrippin'... ;)

Best,
Jörn

On 6/3/2014 3:30 PM, Laura Rueda Delgado wrote:
>
> 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
>
>
>
> _______________________________________________
> fieldtrip mailing list
> fieldtrip at donders.ru.nl
> http://mailman.science.ru.nl/mailman/listinfo/fieldtrip


--
Jörn M. Horschig
PhD Student
Donders Institute for Brain, Cognition and Behaviour
Centre for Cognitive Neuroimaging
Radboud University Nijmegen
Neuronal Oscillations Group
FieldTrip Development Team

P.O. Box 9101
NL-6500 HB Nijmegen
The Netherlands

Contact:
E-Mail: jm.horschig at donders.ru.nl
Tel:    +31-(0)24-36-68493
Web: http://www.ru.nl/donders

Visiting address:
Trigon, room 2.30
Kapittelweg 29
NL-6525 EN Nijmegen
The Netherlands

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




More information about the fieldtrip mailing list