[FieldTrip] Inverse-warping a template of MNI coordinates

Schoffelen, J.M. (Jan Mathijs) janmathijs.schoffelen at donders.ru.nl
Mon Oct 21 19:57:30 CEST 2024


Hi Kenneth,

Assuming that the ‘source_placebo’ variable you refer to in the second part of your message has been obtained in a similar way as the ‘source’ variable in the first part of your message, to me it looks that there’s something off with the ‘positions’ that you start out with. Without additional information about those it is difficult to comment.

Besides this, I suggest that you go through your pipeline step-by-step and visualize in more detail the objects that go in and out of the individual function calls.
Specificallly you should pay attention to whether the coordinate systems and geometric units are aligned (FieldTrip might be forgiving with respect to units, but it never hurts to explicitly equalize them across data objects (volume conductor model, source grid, sensor defintion). It goes without saying that FieldTrip is not forgiving with respect to differences in coordinate systems. Those should match across input objects. It’s not often that I have seen an MEG system with the sensors defined in ‘acpc’ coordinates, so I doubt whether the first alignment step to obtain mri_realigned from the original mri image is correct.

Good luck
Jan-Mathijs


On 21 Oct 2024, at 18:58, Kenneth Shinozuka via fieldtrip <fieldtrip at science.ru.nl> wrote:

Hello,

I am currently source-localizing some MEG data in such a way that I am inverse-warping a template of MNI coordinates to each individual's anatomical MRI. I am running the following code:
mri = ft_read_mri(mri_filename);

cfg = []; cfg.method = 'interactive'; cfg.coordsys = 'acpc'; % the desired coordinate systemmri_realigned = ft_volumerealign(cfg, mri); cfg = []; cfg.sourcemodel.pos = positions; template = ft_prepare_sourcemodel(cfg); cfg = []; cfg.method = 'basedonmni'; cfg.template = ft_convert_units(template.sourcemodel, 'mm');cfg.nonlinear = 'yes'; % use non-linear normalizationcfg.mri = mri_realigned;sourcemodel = ft_prepare_sourcemodel(cfg); % Prepare head model using single-shell method cfg = []; cfg.output = 'brain'; segmentedmri = ft_volumesegment(cfg, mri_realigned); cfg = []; cfg.method = 'singleshell';headmodel = ft_prepare_headmodel(cfg, segmentedmri); % Calculate means and covariances for source analysiscfg = []; cfg.covariance = 'yes'; cfg.covariancewindow = 'all'; cfg.channel = 'MEG'; cfg.keeptrial = 'yes'; tlock = ft_timelockanalysis(cfg, data); % data is preprocessed MEG data % Prepare leadfield model cfg = []; cfg.grad = tlock.grad; cfg.headmodel = headmodel; cfg.reducerank = 2; cfg.channel = {'MEG'}; cfg.sourcemodel = sourcemodel; % Inverse-warped templatecfg.normalize = 'yes'; cfg.normalizeparam = 1;[lf] = ft_prepare_leadfield(cfg); % Run source analysis on the subject-specific inverse-warped template positionscfg = []; cfg.method = 'lcmv'; cfg.sourcemodel = lf; cfg.headmodel = headmodel; cfg.lcmv.keepfilter = 'yes'; cfg.lcmv.lambda = '5%'; cfg.lcmv.fixedori = 'yes';source = ft_sourceanalysis(cfg, tlock);
nb_sources = length(source.avg.filter); nb_trials = length(data.trial); nb_samples = size(data.trial{1}, 2);vs = zeros(nb_sources,nb_trials,nb_samples); for i=1:nb_sources flt = source.avg.filter{i}; if isempty(flt) vs(i,:,:) = NaN(nb_trials,nb_samples); % source-reconstructed timeseries else for t=1:nb_trials v = flt*data.trial{t}; vs(i,t,:) = v; end end end vs = squeeze(vs);
I have three questions:

  1.  Is it necessary to run ft_volumerealign before running ft_prepare_sourcemodel? The origin of the anatomical MRI does not appear to be the anterior commissure; see figure 1 below, which was produced through ft_determine_coordsys.
  2.  source.avg.pow contains very small values, on the order of 10^-47, even though the MEG data is on the order of 10^-14.
  3.  When I try to visualize the source activity, it seems totally misaligned with the anatomical MRI. See figure 2 and the code that was used to produce it below.

Figure 1

<Screenshot 2024-10-21 at 20.56.51.png>

Figure 2

<Screenshot 2024-10-21 at 20.41.13.png>

% Interpolate the source onto the MRI for visualization
cfg = [];
cfg.parameter = 'pow';  % Or 'avg.pow' depending on your data
cfg.interpmethod = 'nearest';
source_interp = ft_sourceinterpolate(cfg, source_placebo, mri_realigned);
% Plot the source on the MRI
cfg = [];
cfg.method = 'ortho';
cfg.funparameter = 'pow';
ft_sourceplot(cfg, source_interp);

Many thanks for reading this long email! I look forward to hearing from you.

Best regards,
Kenneth Shinozuka

--
Kenneth Shinozuka
Harvard College '20 | BA in Neuroscience
Oxford University '24 | PhD Candidate in Psychiatry
+1 9493028589 (US, WhatsApp)
+44 07572876618 (UK)
_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
https://doi.org/10.1371/journal.pcbi.1002202

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20241021/c56083b1/attachment.htm>


More information about the fieldtrip mailing list