[FieldTrip] please help, approaching deadline. ft_sourceanalysis line 813

Hassan Aleem ha438 at georgetown.edu
Thu Mar 17 03:47:22 CET 2016


Hi all,

I have a pipeline created where at the ft_prepare_leadfield step, the
grid.label and cfg.channel fields both exist, But when I run the
ft_sourceanalysis, they result as empty matrices--throwing an error.

they are both cells {128x1}, but at ft_sourceanalysis result in [ ]

here is my code for reference. Sorry for the long post, I am very close to
a deadline and would be very grateful for your help. Please scroll below to
see section where the error is thrown.

*%% parameters list* (just for reference)
mrifile='Siemens_AF8-MPRAGE_20141022_1.nii';
mritype='MNI';
realign='realigned';
volumereslicing='volumeresliced';
brainthresh=0.5;
scalpthresh=0.10;
scalpsmooth='scalp_smooth';
scalp_smooth.parameter=9;
scalpvertices=1000;
skullvertices=1000;
brainvertices=1000;
meshmethod='projectmesh';
headmodel_method='bemcp';
subjnum='915';
time='pre';
timetype='simple';
gridtype='template10';
beamformer='lcmv';
identifier='Parameter2';

*%% make headmodel*
switch mritype
    case 'MNI'
        [mri]               = ft_read_mri(mrifile);
        mri.coordsys        ='MNI';
    case 'Analyze'
        [mri]               = ft_read_mri(mrifile);
        mri.coordsys        ='Analyze';
end

*%% realigning*
switch realign
    case 'realigned'
        cfg=[];
        cfg.method='fiducial';
        cfg.fiducial.nas    = [6.60688      6.30230     -2.94229];
        cfg.fiducial.lpa    = [6.04082      7.65872     0.350950];
        cfg.fiducial.rpa    = [4.41106      8.71481      3.50199];
        mri_realigned=ft_volumerealign(cfg,mri);

save(strcat(mrifile,'_',identifier,'_','mri_realigned.mat'),'mri_realigned')
    case 'notrealigned'
        %do nothing
end

*%% volume reslicing*
switch volumereslicing
    case 'volumeresliced'
    cfg = [];
    cfg.resolution = 1;
    mri_resliced = ft_volumereslice(cfg, mri);

save(strcat(mrifile,'_',identifier,'_','mri_resliced.mat'),'mri_resliced')
    case 'notresliced'
        %do nothing
end

*%% segmentation parameters*
switch scalpsmooth
    case 'noscalpsmooth'
        cfg                 = [];
        cfg.brainthreshold  = braintresh;
        cfg.scalpthreshold  = scalpthresh;
        cfg.downsample      = 1; %no downsampling
        cfg.output          = {'brain' 'skull' 'scalp'};
        seg                 = ft_volumesegment(cfg, mri);
    case 'scalp_smooth'
        cfg                 = [];
        cfg.brainthreshold  = brainthresh;
        cfg.scalpthreshold  = scalpthresh;
        cfg.scalpsmooth     = scalp_smooth.parameter;
        cfg.downsample      = 1; %no downsampling
        cfg.output          = {'brain' 'skull' 'scalp'};
        seg                 = ft_volumesegment(cfg, mri);
end

*%%prepare mesh *

cfg                 = [];
cfg.method= meshmethod;
cfg.tissue          = {'scalp', 'skull', 'brain'};
cfg.numvertices     = [scalpvertices skullvertices brainvertices];
bnd                 = ft_prepare_mesh(cfg, seg);
% i enlarged / reduced the boundary mesh a little bit, because they were
causing errors, probably due to overlapping
bnd(1).pnt          = bnd(1).pnt.*1.001;
bnd(2).pnt          = bnd(2).pnt.*1;
bnd(3).pnt          = bnd(3).pnt.*0.999;


*%% prepare headmodel*
switch headmodel_method
    case 'dipoli'
        cfg                 = [];
        cfg.method          = 'dipoli';
    case 'bemcp'
        cfg                 = [];
        cfg.method          = 'bemcp';
end

headmodel           = ft_prepare_headmodel(cfg, bnd);
headmodel           = ft_convert_units(headmodel,'cm');

*%% adding electrodes to headmodel*
elec=ft_read_sens('Hydrocel_GSN_128_1.0_TRIM_mod.sfp');    %load electrode
file
% visualize head surface (scalp)
figure;
ft_plot_mesh(headmodel.bnd(1),
'edgecolor','none','facealpha',0.8,'facecolor',[0.6 0.6 0.8]);
hold on;
% plot electrodes
ft_plot_sens(elec,'style', 'sk')

%most likely they are not aligned, so for aligning electrodes
cfg           = [];
cfg.method    = 'interactive';
cfg.elec      = elec;
cfg.headshape = headmodel.bnd(1);%scalp
elec_aligned  = ft_electroderealign(cfg);%use the gui to manually align the
electrodes
nas=mri_realigned.cfg.fiducial.nas;
lpa=mri_realigned.cfg.fiducial.lpa;
rpa=mri_realigned.cfg.fiducial.rpa;

*%% load EEG data*

i can send these to any ambitiously nice person wanting to try out the
script exactly

*%% timelock data*


elec=ft_read_sens('Hydrocel_GSN_128_1.0_TRIM_mod.sfp');

cfg = [];
    same = dataM0;
    same.trial = [dataM0.trial dataM3W.trial];
    same.time = [dataM0.time dataM3W.time];

    diff = dataM6;
    diff.trial = [dataM3Bb.trial dataM6.trial];
    diff.time = [dataM3Bb.time dataM6.time];

 switch timetype
     case 'simple'
        timelock_m0 = ft_timelockanalysis(cfg, dataM0);
        timelock_m6 = ft_timelockanalysis(cfg, dataM6);
        timelock_m3w = ft_timelockanalysis(cfg, dataM3W);
        timelock_m3b = ft_timelockanalysis(cfg, dataM3Bb);
        timelock_diff = ft_timelockanalysis(cfg, diff);
        timelock_same = ft_timelockanalysis(cfg, same);
     case 'hassan'
       cfg.vartrllength = 2;
       cfg.covariance = 'yes';
       cfg.covariancewindow = [0 .2];
       cfg.keeptrials = 'yes';
       timelock_m0 = ft_timelockanalysis(cfg, dataM0);
       timelock_m6 = ft_timelockanalysis(cfg, dataM6);
       timelock_m3w = ft_timelockanalysis(cfg, dataM3W);
       timelock_m3b = ft_timelockanalysis(cfg, dataM3Bb);
       timelock_diff = ft_timelockanalysis(cfg, diff);
       timelock_same = ft_timelockanalysis(cfg, same);


*%% make sourcemodel*
cfg = [];
cfg.headmodel = headmodel;
cfg.mri=mri;
cfg.grid.warpmni = 'yes';
cfg.grid.template = sourcemodel.cfg.grid;
cfg.grid.nonlinear = 'yes';
cfg.resolution = 10; % resolution of the template grid in mm
cfg.moveinward = 1;
cfg.grid.unit      ='mm';
cfg.inwardshift = 0;
cfg.elec = elec;
% cfg.headshape=('cortex_5124.surf.gii');
mysourcemodel = ft_prepare_sourcemodel(cfg);

*%% make leadfield*
switch gridtype
    case 'individual'
        cfg            = [];
        cfg.elec       = elec;
        cfg.headmodel  = headmodel;
        cfg.grid       =mysourcemodel;
%         cfg.grid.resolution = 2; %gives me Error using
ft_prepare_sourcemodel (line 163)
%You cannot specify cfg.grid.resolution and an explicit cfg.grid.xgrid
simultaneously
        cfg.reducerank= 3;
        cfg.channel = elec.chanpos;
        cfg.grid.unit = 'cm';% same unit as above, i.e. in cm
        [grid] = ft_prepare_leadfield(cfg);
    case 'templatebased'
        load('standard_sourcemodel3d10mm.mat')
        cfg                 = [];
        cfg.elec            = elec;
        cfg.template = sourcemodel.cfg.grid;
        cfg.grid=grid;
        cfg.headmodel             = headmodel;
        cfg.reducerank      = 3; % default is 3 for EEG, 2 for MEG
        cfg.channel  = 'all';
        cfg.grid.unit       = 'cm';
        cfg.grid.tight      = 'yes';
        [grid] = ft_prepare_leadfield(cfg);
    case 'template10'
        load('standard_sourcemodel3d10mm.mat')
        [grid]=sourcemodel.cfg.grid;
end

*%% run beamformer*-* this step is what gives the error, *

switch beamformer
    case 'lcmv'
        cfg = [];
        cfg.method = 'lcmv';
        cfg.elec=elec;
        cfg.lcmv.lambda='5%';
        cfg.grid = grid;
        cfg.headmodel = headmodel;
        cfg.lcmv.keepfilter = 'yes';
        cfg.lcmv.projectnoise='yes';
        cfg.lcmv.fixedori = 'yes'; % project on axis of most variance using
SVD


>>>>>the error is>>>






*Subscript indices must either be real positive integers or logicals.Error
in beamformer_lcmv (line 168)    noise = noise(end);Error in
ft_sourceanalysis (line 841)dip(i) = beamformer_lcmv(grid, sens, headmodel,
squeeze_avg, squeeze(Cy(i,:,:)), optarg{:});*



*I suspect its because in ft_sourceanalysis (line813) [i1, i2] =
match_str(cfg.channel, grid.label)*
*the result is i1=[] and i2=[]. eventhough when I look up cfg.channel and
grid.label in my variables they exist. after running ft_sourceanalysis the
cfg.channel field disappeaers. *

*%%interpolate*
cfg = [];
cfg.interpmethod = 'nearest';
cfg.parameter = 'pow';
sourceinterp_diff = ft_sourceinterpolate(cfg, sourceanalysis_diff,
mri_resliced);
sourceinterp_m0 = ft_sourceinterpolate(cfg, sourceanalysis_m0,
mri_resliced);
sourceinterp_m6 = ft_sourceinterpolate(cfg, sourceanalysis_m6,
mri_resliced);
sourceinterp_m3w = ft_sourceinterpolate(cfg, sourceanalysis_m3w,
mri_resliced);
sourceinterp_m3b = ft_sourceinterpolate(cfg, sourceanalysis_m3b,
mri_resliced);
sourceinterp_same = ft_sourceinterpolate(cfg, sourceanalysis_same,
mri_resliced);

*%%Plot*
cfg = [];
cfg.method            = 'surface';
cfg.funcolormap = 'jet';
% cfg.method        = 'ortho';
cfg.funcolorlim   = 'maxabs';
cfg.funparameter= 'pow';
ft_sourceplot(cfg,sourceinterp_diff);
ft_sourceplot(cfg,sourceinterp_m0);
ft_sourceplot(cfg,sourceinterp_m6);
ft_sourceplot(cfg,sourceinterp_m3w);
ft_sourceplot(cfg,sourceinterp_m3b);
ft_sourceplot(cfg,sourceinterp_same);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20160316/36048a97/attachment-0001.html>


More information about the fieldtrip mailing list