[FieldTrip] possible bug in tutorial code for creating sourcemodel

Schoffelen, J.M. (Jan Mathijs) jan.schoffelen at donders.ru.nl
Fri Dec 11 13:19:39 CET 2015


Hi Juan,

I could reproduce your issue, and have done 2 things:
- I updated the wiki to make it clear that it would be easier to use a pre-cooked grid.
- I adjusted ft_prepare_sourcemodel so that it also works when only providing the template_headmodel, as per the example code.
The new version of ft_prepare_sourcemodel will become available in tonight’s release on the ftp-server.

Best wishes, and thanks for noticing.
Jan-Mathijs


On Dec 11, 2015, at 11:43 AM, Juan <juangpc at gmail.com<mailto:juangpc at gmail.com>> wrote:

Dear Community,

My name is Juan Garcia-Prieto and I am working in Madrid's MEG Lab. Currently I am learning to do beamforming source analysis using Fieldtrip.

While following the tutorial: "Creating a sourcemodel for source-reconstruction of MEG or EEG data<http://goog_2124598831/>
​<http:/>"
​​

​ ​when I reach "
Subject-specific grids that are equivalent across subjects in normalized space
​" procedure , there is an example code. This code throws an error when I execute it with a version of Fieldtrip I downloaded yesterday. I think I have downloaded correctly all the required info (Subject01.zip).

​Code:


% NOTE: the path to the template file is user-specific
template = ft_read_mri('~/matlab/fieldtrip/external/spm8/templates/T1.nii');
template.coordsys = 'spm'; % so that FieldTrip knows how to interpret the coordinate system

% segment the template brain and construct a volume conduction model (i.e. head model):
% this is needed to describe the boundary that define which dipole locations are 'inside' the brain.
cfg          = [];
template_seg = ft_volumesegment(cfg, template);

cfg          = [];
cfg.method   = 'singleshell';
template_headmodel = ft_prepare_headmodel(cfg, template_seg);
template_headmodel = ft_convert_units(template_headmodel, 'cm'); % Convert the vol to cm, because the CTF convenction is to express everything in cm.

% construct the dipole grid in the template brain coordinates
% the negative inwardshift means an outward shift of the brain surface for inside/outside detection
cfg = [];
cfg.grid<http://www.mathworks.com/access/helpdesk/help/techdoc/ref/grid.html>.resolution = 1;
cfg.grid<http://www.mathworks.com/access/helpdesk/help/techdoc/ref/grid.html>.tight  = 'yes';
cfg.inwardshift = -1.5;

​​
cfg.headmodel   = template_headmodel;


The problem occurs when I execute ​this line:


​
​
​
​
template_grid   = ft_prepare_sourcemodel(cfg);

Matlab's output:
​
>> template_grid   = ft_prepare_sourcemodel(cfg);
creating dipole grid based on automatic 3D grid with specified resolution
Error using ft_prepare_sourcemodel (line 317)
creating a 3D-grid sourcemodel this way requires sensor position information to estimate the extent of the brain
​


I have managed to look around and found that you can specify the required "sensor position information" by executing this code just before (considering the folder with the information downloaded for this subject is located just there:


​cfg.gradfile='Subject01\Subject01.ds\Subject01.res4';



Then the rest of the sample code in the tutorial can be executed with no issues.


template_grid   = ft_prepare_sourcemodel(cfg);

% make a figure with the template head model and dipole grid
figure<http://www.mathworks.com/access/helpdesk/help/techdoc/ref/figure.html>
hold<http://www.mathworks.com/access/helpdesk/help/techdoc/ref/hold.html> on
ft_plot_vol(template_vol, 'facecolor', 'cortex', 'edgecolor', 'none');alpha 0.5; camlight<http://www.mathworks.com/access/helpdesk/help/techdoc/ref/camlight.html>;
ft_plot_mesh(template_grid.pos(template_grid.inside,:));

My questions:

​Is there a better solution for this problem? Maybe I can learn a little bit more about the toolbox with your answers.

I didn't want to correct the wiki because​ my solution depends on where one is placing the downloaded subject's data, and it is platform dependent. Should I add something to the tutorial anyway?
​ I figure this can be interesting to other people.​
​
​

Best,


Juan

_______________________________________________
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/20151211/b58ac750/attachment-0002.html>


More information about the fieldtrip mailing list