Back to the main page.

Bug 2265 - cm or mm in ft_prepare_leadfield

Reported 2013-08-23 14:45:00 +0200
Modified 2014-02-24 10:56:32 +0100
Product: FieldTrip
Component: forward
Version: unspecified
Hardware: PC
Operating System: Windows
Importance: P3 normal
Assigned to: Robert Oostenveld
Depends on: 1794
See also:

Behnam - 2013-08-23 14:45:05 +0200

Hi If I create a dipole and a leadfield model, the source will be found correctly if the unit is set to 'cm'. If everything is set to 'mm', the source will not found correctly. I guess, one of the methods does not work properly with 'mm'. Thanks, Behnam Molaee Here is my code: (OK with 'cm' but not functional with 'mm') load('E:\InstalledMatlabTools\FieldTrip\fieldtrip-20130818\template\headmodel\standard_bem.mat') % loads 'vol' load('E:\InstalledMatlabTools\FieldTrip\fieldtrip-20130818\template\headmodel\standard_mri.mat'); %loads 'mri' %CMMM = 'mm'; ; scale=10; % prepare_leadfield, or another method does not work with mm (a bugg) CMMM = 'cm'; ; scale=1; vol = ft_convert_units(vol, CMMM); % Convert the vol to cm, or mm close all % construct the dipole grid in the template brain coordinates % the source units are in cm % the negative inwardshift means an outward shift of the brain surface for inside/outside detection cfg = []; cfg.grid.xgrid = scale*[-20:1:20]; cfg.grid.ygrid = scale*[-20:1:20]; cfg.grid.zgrid = scale*[-20:1:20]; cfg.grid.unit = CMMM; cfg.grid.tight = 'yes'; cfg.inwardshift = -scale*0; cfg.vol = vol; template_grid = ft_prepare_sourcemodel(cfg); %%% make a figure with the template head model and dipole grid figure hold on ft_plot_vol(vol, 'facecolor', 'cortex', 'edgecolor', 'none');alpha 0.5; camlight; ft_plot_mesh(template_grid.pos(template_grid.inside,:)); elecs = ft_read_sens('E:\InstalledMatlabTools\FieldTrip\fieldtrip-20130818\template\electrode\standard_1020.elc'); elecs = ft_convert_units(elecs, CMMM); [vol, elecs] = ft_prepare_vol_sens(vol, elecs) ft_plot_mesh(elecs.elecpos,'vertexcolor',[1 .3 .3]); data = []; cfg.grid = template_grid; cfg.vol = vol; cfg.elec = elecs; cfg.unit = CMMM; [grid] = ft_prepare_leadfield(cfg, data); grid = ft_convert_units(grid, CMMM); %% does not really functional!! %%% Dipole simulation % note that beamformer scanning will be done with a 1cm grid, so you should % not put the dipole on a position that will not be covered by a grid % location later cfg = []; cfg.vol = vol; cfg.elec = elecs; cfg.dip.pos = scale*[ 3 -3 6 % dipole 1 ]; = [ 1 0 0 ]'; cfg.dip.frequency = [10]*1; cfg.dip.phase=pi/4*[1]; cfg.dip.amplitude=[10]; cfg.relnoise = .1; cfg.ntrials = 20; data = ft_dipolesimulation(cfg); % compute the data covariance matrix, which will capture the activity of % the simulated dipole cfg = []; cfg.covariance = 'yes'; cfg.covariancewindow = [data.time{1}(1) data.time{1}(end)]; timelock = ft_timelockanalysis(cfg, data); %%% source analysis cfg = []; METHOD = 'lcmv'; % 'lcmv' 'rv' 'mne' cfg.method = METHOD; cfg.grid = grid; cfg.vol = vol; cfg.elec = elecs; cfg.snr = 10; source = ft_sourceanalysis(cfg, timelock); cfg = []; cfg.downsample = 2; if strcmp(METHOD,'lcmv') cfg.parameter = 'avg.pow'; elseif strcmp(METHOD,'rv') cfg.parameter = 'avg.rv'; else cfg.parameter = 'avg.pow'; end source = ft_sourceinterpolate(cfg, source , mri); %Note: this function crashes if mne method is used cfg = []; if strcmp(METHOD,'lcmv') try, source=rmfield(source,'time'); end cfg.funparameter = 'avg.pow'; elseif strcmp(METHOD,'rv') try, source=rmfield(source,'time'); end cfg.funparameter = 'avg.rv'; else cfg.funparameter = 'avg.pow'; end cfg.method = 'ortho'; ft_sourceplot(cfg, source);

Johanna - 2013-08-25 07:57:16 +0200

Thank you for reporting this. Please see this same issue in bug 1794. You may add yourself to the 'cc List' on that bug.

Robert Oostenveld - 2013-11-18 14:50:14 +0100

What I see on calling ... template_grid = ft_prepare_sourcemodel(cfg); is creating dipole grid based on user specified 3D grid using headmodel specified in the configuration 2020 dipoles inside, 66901 dipoles outside brain <===== !!! not good !!! making tight grid 2020 dipoles inside, 2030 dipoles outside brain whereas all inputs to ft_prepare_sourcemodel are consistently in cm. It creating a grid with so many dipoles outside the source compartment of the volume conductor is not what I'd expect. I will look further into this and use your code as a test script.

Robert Oostenveld - 2013-11-19 13:48:38 +0100

(In reply to comment #2) although I mentioned above that it is not good to see "2020 dipoles inside, 66901 dipoles outside", it is explained by the very spatious grid specification (from -200 to 200 mm, i.e. a 400 mm box). So this is actually not the problem.

Robert Oostenveld - 2013-11-19 13:54:27 +0100

Created attachment 560 screenshot of results, looks fine? I made a test script out of your script. mac001> svn commit test_bug2265.m Adding test_bug2265.m Transmitting file data . Committed revision 8815. Attached is a screenshot of the output, which looks fine to me. Please see and try out that test script on your computer. It may be that it was a short-lived bug that has already been addressed in the last few days.

Robert Oostenveld - 2013-12-02 11:34:44 +0100

I guess it has been resolved, so I want to close this bug. If you disagree, please reopen it and explain what is still wrong.

Robert Oostenveld - 2014-02-24 10:56:32 +0100

I closed several bugs at once that all have been resolved for some time. If you disagree, please reopen.