[FieldTrip] plotting interpolated sources with ft_sourceplot

"Jörn M. Horschig" jm.horschig at donders.ru.nl
Mon Mar 31 17:12:24 CEST 2014


just to clarify and be precise
> The pos-matrix has to be a regular 3D grid, i.e. be representable as a 
> 3x3x3 matrix. 
it actually does not have to be as you can also beam individual grid 
points, but if you have a .dim field, then is has to be like above. But 
that does not affect the rest of the mail I wrote ;)


> I am not quite sure how the sourceinterpolate function is handeling 
> the fact that you do not have that .dim field. Apparently, it is also 
> confused ;)
>
> Do you want to reconstruct only some voxels? From your code it seems 
> that you want to cover the whole brain with a 1cm resolution. If the 
> latter is the case, maybe restart with creating your forward model by 
> following the tutorial that I posted in my previous mail. There are 
> some sanity checks that can help you figuring out if you are doing the 
> correct thing. If the former one is the case, please explain again 
> what exactly you want to achieve and how you are building your forward 
> model.
>
> Best,
> Jörn
>
> btw, there's nothing wrong with being a PhD student, it's just a 
> matter of experience in practice and theory as in all domains in life ;)
>
>
> On 3/31/2014 3:15 PM, Tyler Grummett wrote:
>> Hey Jorn,
>>
>> Yes I am definitely confused haha, this stuff is way out of my league 
>> as a PhD student.
>> Anyway, I feel we are getting somewhere.
>>
>> timelock =
>>
>>         avg: [121x19767 double]
>>         var: [121x19767 double]
>>        time: [1x19767 double]
>>         dof: [121x19767 double]
>>       label: {1x121 cell}
>>      dimord: 'chan_time'
>>         cov: [121x121 double]
>>        elec: [1x1 struct]
>>         cfg: [1x1 struct]
>>
>> source =
>>
>>         time: [1x19767 double]
>>          pos: [642x3 double]
>>       inside: [642x1 double]
>>      outside: []
>>       method: 'average'
>>          avg: [1x1 struct]
>>          cfg: [1x1 struct]
>>
>> sourceInt =
>>
>>          time: [1x19767 double]
>>           avg: [1x1 struct]
>>           pos: [16777216x3 double]
>>           dim: [256 256 256]
>>        inside: [1x16777216 double]
>>       outside: [1x0 double]
>>      coordsys: 'ctf'
>>          unit: 'mm'
>>           cfg: [1x1 struct]
>>
>> Given what I said last time, I might not comment on the differences. 
>> I hope you can see something wrong.
>>
>> One thing I should mention is that the data is continuous, around 30 
>> seconds. Therefore there is only one trial,
>> is that an issue?
>>
>> 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 "Jörn M. Horschig" 
>> <jm.horschig at donders.ru.nl>
>> Sent: Monday, 31 March 2014 10:24 PM
>> To: FieldTrip discussion list
>> Subject: Re: [FieldTrip] plotting interpolated sources with 
>> ft_sourceplot
>>
>> Hi Tyler,
>>
>> there is not much inherently different between time- and
>> freuqency-domain beamformer, at least in terms of computing the forward
>> and the inverse solution. But I see that you are obviously confused, so
>> let me try to help you out and shed some light on what you are actually
>> doing ;)
>>
>>
>>> I had a look at my variables.
>>>
>>> source.avg =
>>>
>>>          pow: [642x1 double]
>>>       filter: {642x1 cell}
>>>
>>> sourceInt.avg =
>>>
>>>       pow: [16777216x1 double]
>>>
>>> So clearly, as both variables are completely different. Something 
>>> has gone wrong.
>> No, that is actually how it should be. From below you can see that your
>> MRI has 3-dimensions, each with 256 elements, that is 256*256*256 =
>> 16777216 elements. In line with source.avg.pow, you should see that your
>> 'grid' consists of 642 elements, so you were computing your source
>> activity on a grid of in total 642 elements. Then you used the original
>> MRI to interpolate from 642 to these 16 million grid points. Actually,
>> since you specific cfg.downsample = 2, it should have been only 8
>> million points, so that's where things already get a bit weird.
>>
>> So let's go into some sanity checks:
>> 1. are you using the latest version (or a recent, i.e. from this year)
>> of FielTrip?
>> 2. sourceInt should look something like this, does it?
>>
>> source_diff_int =
>>          inside: [46x55x46 logical]
>>             avg: [1x1 struct]
>>             dim: [46 55 46]
>>       transform: [4x4 double]
>>         anatomy: [46x55x46 double]
>>            unit: 'mm'
>>             cfg: [1x1 struct]
>>
>>
>>
>> 3. source should look something like this:
>>
>> source =
>>             dim: [20 25 22]
>>            freq: 54.8287
>>       cumtapcnt: [338x1 double]
>>             pos: [11000x3 double]
>>          inside: [1x5798 double]
>>         outside: [1x5202 double]
>>          method: 'average'
>>             avg: [1x1 struct]
>>       trialinfo: [338x1 double]
>>             cfg: [1x1 struct]
>>
>> 4. also check your grid, should be something like this:
>>
>> sourcemodel =
>>
>>           pos: [11000x3 double]
>>           dim: [20 25 22]
>>          unit: 'cm'
>>        inside: [1x5798 double]
>>       outside: [1x5202 double]
>>        params: [1x1 struct]
>>       initial: [4x4 double]
>>           cfg: [1x1 struct]
>>
>>
>> Of course, it should all look a bit different, because you are using
>> LCMV, but essentially it should be the same. Lastly, you can check other
>> source plotting methods, like 'ortho' or try to plot the source
>> structure rather than the sourceInt structure. In the end, the error
>> must be somewhere in your grid, be it in .pos or .inside, because
>> FieldTrip thinks that there is only one voxel to be plotted. There are
>> other things that may be the issue, but I am not sure about these. So, I
>> would suggest that you play a bit around and see where the error might
>> come from (e.g. follow this tutorial:
>> http://fieldtrip.fcdonders.nl/tutorial/beamformingextended and adapt the
>> steps that you need for LCMV, maybe also check out:
>> http://fieldtrip.fcdonders.nl/tutorial/connectivity#connectivity_between_meg_virtual_channel_and_emg 
>>
>> there, LCMV is used, but on one voxel only)
>>
>> Best,
>> Jörn
>>
>>> The next part of my code is the following:
>>>
>>>             % interpolate sources
>>>               mri = ft_read_mri('Subject01.mri');
>>>               mri = ft_volumereslice([], mri);
>>>
>>>               cfg            = [];
>>>               cfg.downsample = 2;
>>>               cfg.parameter = 'avg.pow';
>>>               sourceInt  = ft_sourceinterpolate( cfg, source, mri);
>>>               sourceInt = rmfield( sourceInt,'time'); % The avg.pow 
>>> parameter
>>>               % does not vary over time, therefore the time 
>>> dimension is not needed.
>>>
>>> mri =
>>>
>>>         anatomy: [256x256x256 double]
>>>             dim: [256 256 256]
>>>       transform: [4x4 double]
>>>        coordsys: 'ctf'
>>>            unit: 'mm'
>>>             cfg: [1x1 struct]
>>>
>>> I cant really see if the data works in the tutorial because it 
>>> doesnt appear as though fieldtrip has a tutorial on lcmv 
>>> beamformers, they seem to stick to frequency domain beamformers.
>>>
>>> Ive been wrong before though,
>>>
>>> thanks for your help.
>>>
>>> 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 "Jörn M. Horschig" 
>>> <jm.horschig at donders.ru.nl>
>>> Sent: Monday, 31 March 2014 7:13 PM
>>> To: FieldTrip discussion list
>>> Subject: Re: [FieldTrip] plotting interpolated sources with 
>>> ft_sourceplot
>>>
>>> Hi Tyler,
>>>
>>> hm, okay, it could be that the issue with the leadfield and with the
>>> plot are related, but it could also be that they are separate issues. I
>>> just saw that you posted the same 'problem' on bugzilla and included a
>>> picture. Maybe for next time, include a picture on the mailinglist and
>>> just create a bug on bugzilla if you are sure it is a bug in Fieldtrip
>>> and not if you are not sure. That saves us a lot of time in separating
>>> code issues from user problems ;)
>>>
>>> So, back to you problem. It seems that your reconstruction results in
>>> one voxel only. Are you sure that your grid consistents of more than
>>> just one position? So, for example check the size of the matrices in
>>> source.avg, source- and headmodel, etc.
>>>
>>> Also, you can check in Matlab the respective fields of source and
>>> sourceInt and see whether that makes sense.
>>>
>>> Lastly, a neat way to check is always to use your code on data from the
>>> tutorial, and vice versa, use code from the tutorial on your data and
>>> see whether that works. Both should give sensible results, and if one
>>> does not, you know where to start looking for a solution ;)
>>>
>>> Best,
>>> Jörn
>>>
>>>
>>> On 3/31/2014 9:41 AM, Tyler Grummett wrote:
>>>> Hey Jorn,
>>>>
>>>> Previously I have let ft_sourceanalysis do a lead field because if 
>>>> I use the following code:
>>>>
>>>>     % compute lead field ( apparently source analysis computes
>>>>                % lead field anyway
>>>>                cfg                 = [];
>>>>                cfg.elec            = timelock.elec;
>>>>                cfg.vol             = vol;
>>>>                cfg.reducerank      = 3;
>>>>                cfg.grid.resolution = 1;   % use a 3-D grid with a 1 
>>>> cm resolution
>>>>                cfg.grid.unit       = 'cm';
>>>>                cfg.normalize       = 'yes'; % if you are not 
>>>> contrasting the activity of interest again another condition or 
>>>> baseline time-window
>>>>                grid = ft_prepare_leadfield( cfg); %% THIS IS WHERE 
>>>> I AM UP TO
>>>>
>>>> and then calculate the source analysis:
>>>>
>>>> % Source Analysis: without contrasting condition
>>>>                cfg              = [];
>>>>                cfg.method       = 'lcmv';
>>>>                cfg.grid         = grid;
>>>>                cfg.vol          = vol;
>>>> %             cfg.grid.pos = maxpos;
>>>>                cfg.keepfilter = 'yes';
>>>>                cfg.dics.projectnoise = 'yes';
>>>> %             cfg.dics.lambda       = 0;
>>>>                source = ft_sourceanalysis( cfg, timelock);
>>>>
>>>> then I get an error than says:
>>>>
>>>> Error using  *
>>>> Inner matrix dimensions must agree.
>>>>
>>>> Error in beamformer_lcmv (line 268)
>>>>        filt = pinv(lf' * invCy * lf) * lf' *
>>>>        invCy;              % van Veen eqn. 23, use
>>>>        PINV/SVD to cover rank deficient leadfield
>>>>
>>>> Error in ft_sourceanalysis (line 794)
>>>>          dip(i) = beamformer_lcmv(grid, sens, vol,
>>>>          squeeze_avg, squeeze(Cy(i,:,:)),
>>>>          optarg{:});
>>>>
>>>> I just removed the leadfield code and it successfully ran. I could 
>>>> also interpolate it later.
>>>> Is this the correct approach.
>>>>
>>>> Thankyou in advance!
>>>>
>>>> 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 "Jörn M. Horschig" 
>>>> <jm.horschig at donders.ru.nl>
>>>> Sent: Monday, 31 March 2014 5:30 PM
>>>> To: FieldTrip discussion list
>>>> Subject: Re: [FieldTrip] plotting interpolated sources with 
>>>> ft_sourceplot
>>>>
>>>> Hi Tyler,
>>>>
>>>> what you are describing sounds to me like the center bias of the
>>>> beamformer. Did you contrast the activity with anything, or did you
>>>> normalize your leadfield?
>>>> Check this out:
>>>> http://fieldtrip.fcdonders.nl/tutorial/beamformer#source_analysiswithout_contrasting_condition 
>>>>
>>>>
>>>> Best,
>>>> Jörn
>>>>
>>>> On 3/31/2014 5:46 AM, Tyler Grummett wrote:
>>>>> I have been trying to plot my interpolated source data using the 
>>>>> code:
>>>>>
>>>>>                % interpolate sources
>>>>>                mri = ft_read_mri('Subject01.mri');
>>>>>                mri = ft_volumereslice([], mri);
>>>>>                cfg            = [];
>>>>>                cfg.downsample = 2;
>>>>>                cfg.parameter = 'avg.pow';
>>>>>                sourceInt  = ft_sourceinterpolate( cfg, source, mri);
>>>>>                sourceInt = rmfield( sourceInt,'time'); % The avg.pow
>>>>> parameter
>>>>>                % does not vary over time, therefore the time  
>>>>> dimension
>>>>> is not              needed.
>>>>>
>>>>>                % Plot interpolated data
>>>>>                cfg              = []; %#ok<UNRCH>
>>>>>                cfg.method       = 'ortho'; % spline
>>>>>                cfg.funparameter = 'avg.pow';
>>>>>                ft_sourceplot( cfg, sourceInt);
>>>>>
>>>>> However the figure that comes up just had orange squares in the 
>>>>> subplots.
>>>>>
>>>>> I dont know where Ive gone wrong.
>>>>>
>>>>>
>>>>> Tyler
>>>>>
>>>>>
>>>>> *************************
>>>>>
>>>>> /Tyler Grummett ( BBSc, BSc(Hons I))/
>>>>> /PhD Candidate/
>>>>> /Brain Signals Laboratory/
>>>>> /Flinders University/
>>>>> /Rm 5A301/
>>>>> /Ext 66124/
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> 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
>>>> _______________________________________________
>>>> 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
>>> _______________________________________________
>>> 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
>> _______________________________________________
>> 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




More information about the fieldtrip mailing list