[FieldTrip] possible bug in tutorial code for creating sourcemodel
Juan
juangpc at gmail.com
Fri Dec 11 13:55:57 CET 2015
Hi Jan-Mathijs,
Thanks for your quick response, H2H. I've actually learned about precooked
models with your answer. Many thanks.
In the same page, in the part "Make the individual subjects' grid", there
seems to be a unit-related problem. One can find this code
% read the single subject anatomical MRI
mri = ft_read_mri('Subject01.mri');
% segment the anatomical MRI
cfg = [];
cfg.output = 'brain';
seg = ft_volumesegment(cfg, mri);
% construct the volume conductor model (i.e. head model) for each
subject% this is optional, and for the purpose of this tutorial only
required for% plotting, later on
cfg = [];
cfg.method = 'singleshell';
headmodel = ft_prepare_headmodel(cfg, seg);
% create the subject specific grid, using the template grid that has
just been created
cfg = [];
cfg.grid <http://www.mathworks.com/access/helpdesk/help/techdoc/ref/grid.html>.warpmni
= 'yes';
cfg.grid <http://www.mathworks.com/access/helpdesk/help/techdoc/ref/grid.html>.template
= template_grid;
cfg.grid <http://www.mathworks.com/access/helpdesk/help/techdoc/ref/grid.html>.nonlinear
= 'yes'; % use non-linear normalization
cfg.mri = mri;grid
<http://www.mathworks.com/access/helpdesk/help/techdoc/ref/grid.html>
= ft_prepare_sourcemodel(cfg);
% make a figure of the single subject headmodel, and grid
positionsfigure
<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(headmodel, 'edgecolor', 'none', 'facealpha', 0.4);
ft_plot_mesh(grid
<http://www.mathworks.com/access/helpdesk/help/techdoc/ref/grid.html>.pos(grid
<http://www.mathworks.com/access/helpdesk/help/techdoc/ref/grid.html>.inside,:));
When executing it, there seems to be a problem with dimensions. "headmodel"
struct is in mm and "grid" struct is in cm. So unfortunately the resulting
figure ends up being something like
[image: Inline image 1]
I've tested to specify 'mm' units in the configuration struct before
calling ft_prepare_sourcemodel: cfg.grid.unit='mm';
Or by calling ft_convert_units right after ft_prepare_sourcemodel.
grid=ft_convert_units(grid,'mm');
Both solutions work fine, producing a figure very similar to the one in the
tutorial. I've included the first solution in the wiki.
I hope this is ok.
Best,
Juan
On Fri, Dec 11, 2015 at 1:19 PM, Schoffelen, J.M. (Jan Mathijs) <
jan.schoffelen at donders.ru.nl> wrote:
> 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> 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 gridfigure <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
> http://mailman.science.ru.nl/mailman/listinfo/fieldtrip
>
>
>
> _______________________________________________
> fieldtrip mailing list
> 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/ad848448/attachment-0002.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 8130 bytes
Desc: not available
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20151211/ad848448/attachment-0002.png>
More information about the fieldtrip
mailing list