[FieldTrip] Source analysis of EEG oscillatory activity/ NaN values in the leadfield matrices

Tyler Grummett tyler.grummett at flinders.edu.au
Mon Jul 28 03:40:16 CEST 2014


Hello Diego,

Im still having trouble, particularly with ft_prepare_headmodel.

After running the code that you used, I ran the following code:

cfg = [];
cfg.method = 'bemcp'; %openmeeg bemcp
vol = ft_prepare_headmodel(cfg, segmentedmri);

vol.mat is full of NaNs though, so the leadfield creates NaNs ect.

I tried running the following code to fix it:

% prepare mesh
cfg = [];
cfg.method = 'iso2mesh';
cfg.numvertices = 10000;
bnd = ft_prepare_mesh( cfg, segmentedmri);

% fix mesh
[ bnd( 1).pnt, bnd( 1).tri] = meshresample( bnd( 1).pnt, bnd( 1).tri, 1000/size( bnd( 1).pnt, 1));
[ bnd( 2).pnt, bnd( 2).tri] = meshresample( bnd( 2).pnt, bnd( 2).tri, 2000/size( bnd( 2).pnt, 1));
[ bnd( 3).pnt, bnd( 3).tri] = meshresample( bnd( 3).pnt, bnd( 3).tri, 3000/size( bnd( 3).pnt, 1));
for ii = 1:size( bnd),
    [ bnd( ii).pnt, bnd( ii).tri] = meshcheckrepair( bnd( ii).pnt, bnd( ii).tri, 'dup');
    [ bnd( ii).pnt, bnd( ii).tri] = meshcheckrepair( bnd( ii).pnt, bnd( ii).tri, 'isolated');
    [ bnd( ii).pnt, bnd( ii).tri] = meshcheckrepair( bnd( ii).pnt, bnd( ii).tri, 'deep');
    [ bnd( ii).pnt, bnd( ii).tri] = meshcheckrepair( bnd( ii).pnt, bnd( ii).tri, 'meshfix');
end

However it crashes with the following message:

Error using surface_nesting (line 26)
the compartment nesting cannot be determined

Error in ft_headmodel_bemcp (line 66)
order = surface_nesting(vol.bnd, 'insidefirst');

Error in ft_prepare_headmodel (line 262)
      vol = ft_headmodel_bemcp(geometry, 'conductivity', cfg.conductivity);


I dont have enough experience with this code to work out why this isnt working,
previously I had been working with the template MRI inside the template folder
'standard_mri', and this process had worked for me. However I was getting really
strange results after beamforming (the cerebellum would light up for every task).

So I have been using the methods expressed in your email but it hasnt been working
for me, can you see if you get the same result?

Tyler

*************************

Tyler Grummett ( BBSc, BSc(Hons I))
PhD Candidate
Brain Signals Laboratory
Flinders University
Rm 5A301
Ext 66124

________________________________________
From: fieldtrip-bounces at science.ru.nl <fieldtrip-bounces at science.ru.nl> on behalf of Lozano Soldevilla, D. (Diego) <d.lozanosoldevilla at fcdonders.ru.nl>
Sent: Friday, 25 July 2014 9:01 PM
To: FieldTrip discussion list
Subject: Re: [FieldTrip] Source analysis of EEG oscillatory activity/ NaN values in the leadfield matrices

Hi Azadeh,

The problem is originated during the segmentation processing. Basically the default cfg values that you applied to template/anatomy/single_subj_T1.nii gave you the attached segmentation: the scalp is poorly defined as you can see. Then you end up with the wrong headmodel.

I noticed that the single_subj_T1.nii has very low resolution. I used the single_subj_T1_1mm.nii instead with the following cfg parameters (by trial and error...) and they gave me sensitive binary representations:

mri = ft_read_mri('/home/common/matlab/fieldtrip/template/anatomy/single_subj_T1_1mm.nii');
mri.coordsys = 'spm';

cfg                = [];
cfg.brainsmooth    = 5%(default = 5)
cfg.scalpsmooth    = 5%(default = 5)
cfg.brainthreshold = 0.25%(default = 0.5)
cfg.scalpthreshold = 0.25%(default = 0.1)

cfg.output    = {'brain','skull','scalp'};
seg  = ft_volumesegment(cfg, mri);

cfg              = [];
cfg.funparameter = 'scalp';
ft_sourceplot(cfg,seg);


The ft_volumesegment documentation mentions the fieldtrip/external/spm8/templates/T1.nii Unfortunately I'm not sure what this T1 is (MNI152 might be?) and its advantages or disadvantatges. If you use the T1.nii with the following cfg, you'll get a segmentation that makes sense to me:

mri = ft_read_mri('/home/common/matlab/fieldtrip/external/spm8/templates/T1.nii');
mri.coordsys = 'spm';

cfg                = [];
cfg.brainsmooth    = 2%(default = 5)
cfg.scalpsmooth    = 2%(default = 5)
cfg.brainthreshold = 0.25%(default = 0.5)
cfg.scalpthreshold = 0.15%(default = 0.1)

cfg.output    = {'brain','skull','scalp'};
seg  = ft_volumesegment(cfg, mri);

cfg              = [];
cfg.funparameter = 'scalp';%check the brain and skull too
ft_sourceplot(cfg,seg);


My source modeling experience is restricted to MEG using individual T1s (not a template). I'm sure a lot of people in the list have experience in the EEG/source modeling business using template anatomical scans. Could somedoby provide us a bit of advice?:

Which anatomical template should one use (T1.nii, single_subj_T1_1mm.nii other?) and which cfg parameters make sense for the segmentation? It would be very nice if we could establish a kind of default and share them in the fieldtrip wiki ;) (I could do it if somebody share his/her knowledge/experience)

Thanks in advance,

Diego


----- Original Message -----
> From azadehh at uvic.ca Sat Jul 19 00:26:06 2014
> From: azadehh at uvic.ca (Azadeh Hajihosseini)
> Date: Fri, 18 Jul 2014 15:26:06 -0700
> Subject: [FieldTrip] Source analysis of EEG oscillatory activity/ NaN
> values
> in the leadfield matrices
> Message-ID:
> <CA+AyeFcNNontNAxpRDYU6_TxCTNrCQ8KpE-QFtwOyKVEvfBF_Q at mail.gmail.com>
>
> Hello FieldTrip members,
>
> I am trying to source localize EEG oscillatory activity and have a few
> problems in constructing the forward model and eventually running the
> source analysis. I think the problems are related to each other. Here
> is
> what happens:
>
> 1- When I run the source analysis, I get this error message:
>
> *??? Error using ==> svd*
> *Input to SVD must not contain NaN or Inf.*
>
> *Error in ==> beamformer_dics>pinv at 650*
> * [U,S,V] = svd(A,0);*
>
> *Error in ==> beamformer_dics at 339*
> * filt = pinv(lf' * invCf * lf) * lf' * invCf; % Gross
> eqn. 3, use PINV/SVD to cover rank*
> * deficient leadfield*
>
> *Error in ==> ft_sourceanalysis at 572*
> * dip(i) = beamformer_dics(grid, sens, vol, [], squeeze(Cf(i,:,:)),
> optarg{:});*
>
> *Error in ==> test_sourceanalysis at 12*
> *sourceTF = ft_sourceanalysis(cfg, data_TF);*
>
>
> 2- Checking the leadfiled matrices, I see there are a lot of NaN
> values.
> 3- When I visualize the head model I have created, the plots don't
> look
> right. The third field, *vol.bnd(3),* which is supposed to be the
> brain
> tissue, looks like a cube.
>
> And here are my code lines:
>
> *% CONSTRUCT A HEAD MODEL from the template mri in FT's
> template/anatomy*
> *mri = ft_read_mri('template\anatomy\single_subj_T1.nii');*
> *mri.coordsys = 'spm';*
>
> *%SEGMENTATION:*
> *cfg = [];*
> *cfg.output = {'brain','skull','scalp'};*
> *segmentedmri_template = ft_volumesegment(cfg, mri); % Using NOT
> resliced
> data*
> *save segmentedmri_template segmentedmri_template*
>
>
> *%CREATE THE HEAD MODEL (VOLUME CONDUCTION MODEL)*
> *cfg = [];*
> *cfg.method ='bemcp';*
> *cfg.tissue ={'brain','skull','scalp'};*
> *% cfg.outputfile = 'template_';*
> *vol = ft_prepare_headmodel(cfg, segmentedmri_template);*
> *save vol vol*
>
> *%Visualization of the head model*
> *figure;*
> *ft_plot_mesh(vol.bnd(1),'facecolor','none'); %scalp *
> *figure;*
> *ft_plot_mesh(vol.bnd(2),'facecolor','none'); %skull*
> *figure;*
> *ft_plot_mesh(vol.bnd(3),'facecolor','none'); %brain This one looks
> like a
> cube*
>
> *% Align electrodes *
> *elec = ft_read_sens('template\electrode\standard_1020.elc'); *
> *% load volume conduction model*
> *% load vol; *
>
> *%interactive allignment*
> *cfg = [];*
> *cfg.method = 'interactive';*
> *cfg.elec = elec;*
> *cfg.headshape = vol.bnd(1);*
> *elec_aligned = ft_electroderealign(cfg);*
>
> *save elec_aligned elec_aligned*
>
> *% Prepare leadfield*
> *load data_TF*
> *cfg=[];*
> *cfg.vol = vol; %structure with volume conduction model*
> *cfg.elec = elec_aligned;%structure with electrode positions*
> *[grid] = ft_prepare_leadfield(cfg, data_TF);*
>
> *% Find source*
> *cfg = []; *
> *cfg.method = 'dics';*
> *cfg.frequency = 25; *
> *cfg.grid = grid; *
> *cfg.vol = vol;*
> *cfg.latency = .4;%single number in seconds, for time-frequency
> analysis*
> *cfg.dics.projectnoise = 'yes';*
> *cfg.dics.lambda = 0;*
> *cfg.elec = elec_aligned;%structure with electrode positions*
>
> *sourceTF = ft_sourceanalysis(cfg, data_TF);*
>
>
> I am using *wavelet *with a *fourier* output for the time-frequency
> analysis (*data_TF)*. Do you have any idea what might be wrong here?
>
> I also have a more general question. What type of time-frequency data
> can
> be input to source analysis? *ft_freqanalysis* provides power, power
> and
> cross-spectra, and complex fourier outputs. But is source-localization
> based on only power data correct? I couldn't find any explanations
> regarding this issue in the tutorial.
>
> I look forward to hearing from anyone who might have ideas about any
> of
> these issues!
>
> Many thanks,
>
> --
> Azadeh HajiHosseini

--
PhD Student
Neuronal Oscillations Group
Donders Institute for Brain, Cognition and Behaviour
Centre for Cognitive Neuroimaging
Radboud University Nijmegen
NL-6525 EN Nijmegen
The Netherlands
http://www.ru.nl/people/donders/lozano-soldevilla-d/



More information about the fieldtrip mailing list