<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">
Hi Kenneth,
<div><br>
</div>
<div>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.</div>
<div><br>
</div>
<div>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.</div>
<div>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.</div>
<div><br>
</div>
<div>Good luck</div>
<div>Jan-Mathijs</div>
<div><br id="lineBreakAtBeginningOfMessage">
<div><br>
<blockquote type="cite">
<div>On 21 Oct 2024, at 18:58, Kenneth Shinozuka via fieldtrip <fieldtrip@science.ru.nl> wrote:</div>
<br class="Apple-interchange-newline">
<div>
<div dir="ltr">Hello,
<div><br>
</div>
<div>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:</div>
<div><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px"></span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">mri = ft_read_mri(mri_filename);</span></div>
<div><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px"><br>
</span></div>
<div><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">cfg = [];
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">cfg.method =
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px;color:rgb(167,9,245)">'interactive';
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">cfg.coordsys =
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px;color:rgb(167,9,245)">'acpc'</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">;
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px;color:rgb(0,128,19)">% the desired coordinate system</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">mri_realigned
= ft_volumerealign(cfg, mri); </span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">cfg = [];
</span>cfg.sourcemodel.pos<span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px"> = positions;
</span><font face="Menlo, Monaco, Consolas, Courier New, monospace"><span style="white-space:pre">template = ft_prepare_sourcemodel(cfg);
</span></font><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace">cfg = [];
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">cfg.method =
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px;color:rgb(167,9,245)">'basedonmni'</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">;
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">cfg.template = ft_convert_units(</span>template.sourcemodel<span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">,
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px;color:rgb(167,9,245)">'mm'</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">);</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">cfg.nonlinear
= </span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px;color:rgb(167,9,245)">'yes'</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">;
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px;color:rgb(0,128,19)">% use non-linear normalization</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">cfg.mri
= mri_realigned;</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">sourcemodel = ft_prepare_sourcemodel(cfg);</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px"><font color="#008013">% Prepare head model using single-shell method
</font></span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">cfg = [];
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">cfg.output =
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px;color:rgb(167,9,245)">'brain'</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">;
</span>segmentedmri<span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px"> = ft_volumesegment(cfg, mri_realigned);
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">cfg = [];
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">cfg.method =
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px;color:rgb(167,9,245)">'singleshell'</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">;</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">headmodel
= ft_prepare_headmodel(cfg, segmentedmri); </span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px"><font color="#008013">% Calculate means and covariances for source analysis</font></span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">cfg
= []; </span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">cfg.covariance =
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px;color:rgb(167,9,245)">'yes'</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">;
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">cfg.covariancewindow =
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px;color:rgb(167,9,245)">'all'</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">;
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">cfg.channel =
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px;color:rgb(167,9,245)">'MEG'</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">;
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">cfg.keeptrial =
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px;color:rgb(167,9,245)">'yes'</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">;
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">tlock = ft_timelockanalysis(cfg, data); % data is preprocessed MEG data
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px"><font color="#008013">% Prepare leadfield model
</font></span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">cfg = [];
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">cfg.grad = tlock.grad;
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">cfg.headmodel = headmodel;
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">cfg.reducerank = 2;
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">cfg.channel = {</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px;color:rgb(167,9,245)">'MEG'</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">};
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">cfg.sourcemodel = sourcemodel;
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px;color:rgb(0,128,19)">% Inverse-warped template</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">cfg.normalize
= </span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px;color:rgb(167,9,245)">'yes'</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">;
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">cfg.normalizeparam = 1;</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">[lf] = ft_prepare_leadfield(cfg);
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px"><font color="#008013">% Run source analysis on the subject-specific inverse-warped template positions</font></span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">cfg
= []; </span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">cfg.method =
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px;color:rgb(167,9,245)">'lcmv'</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">;
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">cfg.sourcemodel = lf;
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">cfg.headmodel = headmodel;
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">cfg.lcmv.keepfilter =
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px;color:rgb(167,9,245)">'yes'</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">;
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">cfg.lcmv.lambda =
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px;color:rgb(167,9,245)">'5%'</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">;
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">cfg.lcmv.fixedori =
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px;color:rgb(167,9,245)">'yes'</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">;</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">source
= ft_sourceanalysis(cfg, tlock);</span></div>
<div><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">nb_sources = length(source.avg.filter);
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">nb_trials = length(data.trial);
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">nb_samples = size(data.trial{1}, 2);</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">vs
= zeros(nb_sources,nb_trials,nb_samples); </span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px"><font color="#0e00ff">for
</font></span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">i=1:nb_sources
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">flt = source.avg.filter{i};
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px;color:rgb(14,0,255)">if
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">isempty(flt)
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">vs(i,:,:) = NaN(nb_trials,nb_samples); % source-reconstructed timeseries
</span><span style="color:rgb(14,0,255);white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">else
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px;color:rgb(14,0,255)">for
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">t=1:nb_trials
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">v = flt*data.trial{t};
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">vs(i,t,:) = v;
</span><span style="color:rgb(14,0,255);white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">end
</span><span style="color:rgb(14,0,255);white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px">end
</span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px"><font color="#0e00ff">end
</font></span><span style="white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px"><font color="#0e00ff"></font>vs = squeeze(vs);</span><span style="color:rgb(14,0,255);white-space:pre;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;font-size:13px"><br>
</span><span style="white-space:pre;font-size:13px"><font face="Menlo, Monaco, Consolas, Courier New, monospace"></font><font face="arial, sans-serif"><b>I have three questions:
</b>
<ol>
<li><b>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.</b></li><li><b>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.</b></li><li><b>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.</b></li></ol>
</font></span><font face="Menlo, Monaco, Consolas, Courier New, monospace"><span style="white-space:pre"><b>Figure 1</b></span></font></div>
<div><font face="Menlo, Monaco, Consolas, Courier New, monospace"><span style="white-space:pre"><br>
</span></font><span id="cid:ii_m2j9e9f81"><Screenshot 2024-10-21 at 20.56.51.png></span><br>
<br>
<b>Figure 2</b><br>
<br>
</div>
<div><span id="cid:ii_m2j8u6jb0"><Screenshot 2024-10-21 at 20.41.13.png></span><br>
<div><br>
</div>
<span class="gmail_signature_prefix"><font face="monospace">% Interpolate the source onto the MRI for visualization<br>
cfg = [];<br>
cfg.parameter = 'pow'; % Or 'avg.pow' depending on your data<br>
cfg.interpmethod = 'nearest';<br>
source_interp = ft_sourceinterpolate(cfg, source_placebo, mri_realigned);<br>
% Plot the source on the MRI<br>
cfg = [];<br>
cfg.method = 'ortho';<br>
cfg.funparameter = 'pow';<br>
ft_sourceplot(cfg, source_interp);<br>
</font><br>
Many thanks for reading this long email! I look forward to hearing from you.</span></div>
<div><span class="gmail_signature_prefix"><br>
</span></div>
<div><span class="gmail_signature_prefix">Best regards,</span></div>
<div><span class="gmail_signature_prefix">Kenneth Shinozuka<br>
<br>
-- </span><br>
<div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">
<div dir="ltr">
<div>
<div dir="ltr">
<div>Kenneth Shinozuka</div>
<div>Harvard College '20 | BA in Neuroscience</div>
<div>Oxford University '24 | PhD Candidate in Psychiatry</div>
<div>+1 9493028589 (US, WhatsApp)</div>
<div>+44 07572876618 (UK)</div>
</div>
</div>
</div>
</div>
</div>
</div>
_______________________________________________<br>
fieldtrip mailing list<br>
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip<br>
https://doi.org/10.1371/journal.pcbi.1002202<br>
</div>
</blockquote>
</div>
<br>
</div>
</body>
</html>