<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
Hi Jack,
<div class=""><br class="">
<div class="">
<div>
<blockquote type="cite" class="">
<div class="">
<div class="">1. "It is a bit unclear to me what the relevance of the atlas is in all this."<br class="">
<br class="">
Ultimately, I am looking to explore EEG connectivity between brainnetome ROIs. Specifically, in my full pipeline I am:<br class="">
a) Creating Brainnetome atlas aligned template grid<br class="">
b) Using the template grid for source reconstruction across all EEG trials (i.e. epochs)<br class="">
c) Muliplying the spatial filter with the individual EEG epochs to get trial-level source data<br class="">
d) Projecting the dipole moments to their max in each trial<br class="">
e) Using ft_volumelookup to select and then average the dipole mom for each brainnetome ROI to create a 'virtual channel' timecourse<br class="">
f) Running ft_freqanalysis and ft_connectivity analysis on the virtual channel data<br class="">
</div>
</div>
</blockquote>
<div><br class="">
</div>
<div>Gotcha. I already assumed that overall this would be your goal. However, I would recommend a slightly different sequence of steps (involving some other functions):</div>
<div><br class="">
</div>
<div>a) interpolate the Brainnetome atlas to the template grid, using ft_sourceinterpolate. This requires the grid to be in the same coordinate system as the atlas, which is most likely the case if you use one of the standard_sourcemodel3d<some-number>mm.mat.
 This approach is slightly different from the recipe you used so far, which I realize comes from here: <a href="https://www.fieldtriptoolbox.org/example/create_single-subject_grids_in_individual_head_space_that_are_all_aligned_in_brain_atlas_based_mni_space/" class="">https://www.fieldtriptoolbox.org/example/create_single-subject_grids_in_individual_head_space_that_are_all_aligned_in_brain_atlas_based_mni_space/</a>.
 This piece of documentation is a bit outdated in my opinion. It should be possible to do something like this: </div>
<div><br class="">
</div>
<div>atlas_grid = ft_sourceinterpolate(cfg, atlas, template_grid), using cfg.interpmethod = ’nearest’ (or ‘mode’)</div>
<div><br class="">
</div>
<div>b) good, don’t forget to use cfg.<method>.keepfilter = ‘yes’;</div>
<div><br class="">
</div>
<div>c),d),e) this triplet of steps is somewhat outdated. You should be able to wrap these steps into a single function call to ft_virtualchannel:</div>
<div><br class="">
</div>
<div>vcdata = ft_virtualchannel(cfg, data, source, atlas_grid); % please consult the documentation and the code of the function about how best to use this.</div>
<div><br class="">
</div>
<div>f) all good.</div>
<div><br class="">
</div>
<div><br class="">
</div>
<blockquote type="cite" class="">
<div class="">
<div class="">2. "The atlas should not be used a priori to define the ‘inside’ compartment. You can map the dipoles onto the anatomical parcels after you performed the source reconstruction."<br class="">
<br class="">
Is this still the case if I am using a standard BEM model? I decided to create a template grid pre-aligned to the Brainnetome atlas to make it simple to compare subject source-level data and interpret the outcomes relative to specific ROIs in the brainnetome
 atlas. Is this a poor approach? <br class="">
</div>
</div>
</blockquote>
<div><br class="">
</div>
<div>No, this is in principle a good approach. Note that you use a template for the volume conduction model, so I’d assume that the subject-specific grids are not different across subjects either.</div>
<br class="">
<blockquote type="cite" class="">
<div class="">
<div class=""><br class="">
I did first try the typical 'source reconstruction -> interpolation to atlas -> source parcellate' pipeline but I ran into a lot of problems trying to interpolate my source reconstruction onto the Brainnetome atlas. Further digging led me to the current approach
 as a possible solution.<br class="">
</div>
</div>
</blockquote>
<div><br class="">
</div>
<div>As per what I wrote above I’d recommend to go the other way around: interpolate the atlas onto the lower resolution dipole grid. This makes life much easier.</div>
<br class="">
<blockquote type="cite" class="">
<div class="">
<div class="">3. "Following up on my previous message: I didn’t think of the fact that you are using EEG, with a BEM volume conduction model. In this case the inwardshift is probably not going to work."<br class="">
<br class="">
You are right there, as far I can figure. I played a lot with various inwardshift, resolution, and other settings when I was preparing the template_grid (sourcemodel), and I also mucked around with ft_sourceplot projection methods. In some cases, certain options
 did look like they improved the surface plot but I think they were only hiding some of the problem. Inward shift only appeared to cover the surface when I had shifted many gridpoints 'outside' the brain volume; although, regardless, as soon as I align the
 template grid to the brainnetome atlas the problem returns.<br class="">
</div>
</div>
</blockquote>
<div><br class="">
</div>
OK, let’s forget about this then.</div>
<div><br class="">
<blockquote type="cite" class="">
<div class="">
<div class="">4. "Is there a particular reason why you’d want to visualize your results on the surface?"<br class="">
<br class="">
Self-gratification, perhaps. Really, I was hoping to plot the outcomes on a surface because it is a nice and simple way to display results, both for checking that things 'look sensible' and for potential publications where we might use this atlas. Is</div>
</div>
</blockquote>
<blockquote type="cite" class="">
<div class="">
<div class="">it the data type that makes this tricky? I am wondering if my pipeline is ok, but perhaps I need to give up on the surface plot, or create one specifically to represent data at ROIs of the Brainnetome atlas. </div>
</div>
</blockquote>
<blockquote type="cite" class="">
<div class="">
<div class=""><br class="">
In case it is helpful for you, or for other interested readers, my full code for steps a-e is below. Thanks again for your thoughts!<br class="">
<br class="">
</div>
</div>
</blockquote>
<div><br class="">
</div>
<div>I hope the above pointers are helpful in getting you on the road again.</div>
<div><br class="">
</div>
<div>Best wishes,</div>
<div>Jan-Mathijs</div>
<div><br class="">
</div>
<div><br class="">
</div>
<br class="">
<blockquote type="cite" class="">
<div class="">
<div class="">Best,<br class="">
Jack<br class="">
<br class="">
<br class="">
<br class="">
%% Fieldtrip: eLORETA ROI timecourses<br class="">
% <a href="https://urldefense.com/v3/__https://www.fieldtriptoolbox.org/example/create_single-subject_grids_in_individual_head_space_that_are_all_aligned_in_brain_atlas_based_mni_space/__;!!HJOPV4FYYWzcc1jazlU!q8K-aqjtprbNX-bLhVdFRIr1lKXtT8VKw6LQhGjxl13kWaxe7G9gYp1JvXT18OEIpcZlnTLVcH9McUU$" class="">
https://urldefense.com/v3/__https://www.fieldtriptoolbox.org/example/create_single-subject_grids_in_individual_head_space_that_are_all_aligned_in_brain_atlas_based_mni_space/__;!!HJOPV4FYYWzcc1jazlU!q8K-aqjtprbNX-bLhVdFRIr1lKXtT8VKw6LQhGjxl13kWaxe7G9gYp1JvXT18OEIpcZlnTLVcH9McUU$</a>
<br class="">
% <a href="https://urldefense.com/v3/__https://www.fieldtriptoolbox.org/tutorial/salzburg/*reconstruct-the-time-course-of-activity-at-a-particular-brain-location__;Iw!!HJOPV4FYYWzcc1jazlU!q8K-aqjtprbNX-bLhVdFRIr1lKXtT8VKw6LQhGjxl13kWaxe7G9gYp1JvXT18OEIpcZlnTLVl8J_GVQ$" class="">
https://urldefense.com/v3/__https://www.fieldtriptoolbox.org/tutorial/salzburg/*reconstruct-the-time-course-of-activity-at-a-particular-brain-location__;Iw!!HJOPV4FYYWzcc1jazlU!q8K-aqjtprbNX-bLhVdFRIr1lKXtT8VKw6LQhGjxl13kWaxe7G9gYp1JvXT18OEIpcZlnTLVl8J_GVQ$</a>
<br class="">
<br class="">
   ft_defaults<br class="">
   [ftver, ftpath] = ft_version;<br class="">
<br class="">
   % Load the Headmodel<br class="">
   load(fullfile(ftpath, 'template/headmodel/standard_bem.mat')); % Colin27<br class="">
<br class="">
   % Prepare the template grid 'standard sourcemodel'<br class="">
   cfg = [];<br class="">
   cfg.xgrid  = 'auto';<br class="">
   cfg.ygrid  = 'auto';<br class="">
   cfg.zgrid  = 'auto';<br class="">
   cfg.unit   = 'mm';<br class="">
   cfg.tight  = 'yes';<br class="">
   cfg.resolution  = 7; % What does this result in regard to the final resolution for reporting?<br class="">
   cfg.headmodel   = vol;<br class="">
   template_grid   = ft_prepare_sourcemodel(cfg);<br class="">
<br class="">
   % Check alignment of the template grid and headmodel<br class="">
   figure;<br class="">
   hold on<br class="">
   ft_plot_mesh(template_grid.pos(template_grid.inside,:));<br class="">
   ft_plot_headmodel(vol,  'facecolor', 'cortex', 'edgecolor', 'none');<br class="">
   ft_plot_axes(vol);<br class="">
   alpha 0.5<br class="">
   camlight<br class="">
<br class="">
   % Read in Brainnetome Atlas; ensure its units are consistent with template<br class="">
   atlas = ft_read_atlas(fullfile(ftpath, 'template/atlas/brainnetome/BNA_MPM_thr25_1.25mm.nii'));<br class="">
<br class="">
   % Ensure units are consistent between atlas and sourcemodel<br class="">
   atlas = ft_convert_units(atlas,'mm');<br class="">
   template_grid = ft_convert_units(template_grid,'mm');<br class="">
<br class="">
   % Check the coordsys field exists in sourcemodel<br class="">
   if ~isfield(template_grid, 'coordsys');<br class="">
       template_grid.coordsys = 'mni';<br class="">
   end<br class="">
<br class="">
   % Create binary mask for all grid points inside the Brainnetome atlas locations<br class="">
   cfg = [];<br class="">
   cfg.atlas      = atlas;<br class="">
   cfg.roi        = atlas.tissuelabel;  % here you can also specify a single label, i.e. single ROI<br class="">
   cfg.inputcoord = 'mni';<br class="">
   mask           = ft_volumelookup(cfg, template_grid);<br class="">
   template_grid.inside = false(template_grid.dim);<br class="">
   template_grid.inside(mask == 1) = true;<br class="">
<br class="">
   % Check grid points inside the Brainnetome atlas<br class="">
   figure;<br class="">
   ft_plot_mesh(template_grid.pos(template_grid.inside,:),'vertexcolor','black','vertexalpha',0.5);<br class="">
<br class="">
   clearvars -except atlas template_grid vol<br class="">
<br class="">
   %% Prep EEG source analysis<br class="">
<br class="">
   setenv('PATH', 'C:\Program Files\OpenMEEG\bin');<br class="">
   setenv('LD_LIBRARY_PATH', 'C:\Program Files\OpenMEEG\lib'); <br class="">
<br class="">
   % Load preprocessed EEG data<br class="">
   load('C:\Users\jf752\Desktop\Processing\source_analysis\test_data');<br class="">
<br class="">
   % Realign electrodes<br class="">
   cfg = [];<br class="">
   cfg.method = 'interactive';<br class="">
   cfg.headshape = vol.bnd(1);<br class="">
   cfg.elec = cln_data.elec;<br class="">
   elec_aligned = ft_electroderealign(cfg);<br class="">
<br class="">
   cln_data.elec = elec_aligned;<br class="">
<br class="">
   % Convert time for each trial so that they are equivalent (for rawtimelock)<br class="">
   for i = 1:length(cln_data.time);<br class="">
       cln_data.time{1,i} = 0:0.002:1.998;<br class="">
   end<br class="">
<br class="">
   clear i elec_aligned cfg<br class="">
<br class="">
   % Compute sensor-level time-locked data<br class="">
   cfg = [];<br class="">
   cfg.trials = 'all';<br class="">
   cfg.keeptrials = 'yes';<br class="">
   cfg.covariance = 'yes';<br class="">
<br class="">
   timlock = ft_timelockanalysis(cfg,cln_data);<br class="">
<br class="">
   % Prepare the leadfield<br class="">
   cfg = [];<br class="">
   cfg.elec      = cln_data.elec;            <br class="">
   cfg.channel   = cln_data.label;<br class="">
   cfg.headmodel = vol; % volume conduction model   <br class="">
   cfg.sourcemodel.pos    = template_grid.pos; % number of voxels<br class="">
<br class="">
   leadfield = ft_prepare_leadfield(cfg);<br class="">
<br class="">
   clear cfg<br class="">
<br class="">
   %% Run source localisation and calculate single-trial ROI timecourses<br class="">
<br class="">
   % Compute eLORETA time-course based on the total data<br class="">
   cfg = [];<br class="">
   cfg.method       = 'eloreta';<br class="">
   cfg.elec         = timlock.elec;<br class="">
   cfg.sourcemodel  = leadfield;<br class="">
   cfg.headmodel    = vol;<br class="">
   cfg.projectnoise = 'yes';<br class="">
   cfg.keepmom      = 'yes';<br class="">
   cfg.keepfilter   = 'yes';<br class="">
<br class="">
   source = ft_sourceanalysis(cfg, timlock);<br class="">
<br class="">
   % Calculate 3D trial moms based on Michael Glassen's FTMailing Request<br class="">
   % <a href="https://mailman.science.ru.nl/pipermail/fieldtrip/2020-May/039989.html" class="">
https://mailman.science.ru.nl/pipermail/fieldtrip/2020-May/039989.html</a><br class="">
   for f = 1:length(source.avg.filter);<br class="">
       for t = 1:length(cln_data.trial);<br class="">
           if isempty(source.avg.filter{f});<br class="">
               x = [];<br class="">
           else<br class="">
               x = source.avg.filter{f}*cln_data.trial{t};<br class="">
           end<br class="">
       trial_source.trial(t).mom{f} = x;<br class="">
       end<br class="">
   end<br class="">
<br class="">
   % Mimic Source.avg config to project trial dipole moments in direction of maximal power<br class="">
   tmp = source;<br class="">
<br class="">
   for t = 1:length(cln_data.trial);<br class="">
       tmp.avg.mom = trial_source.trial(t).mom;<br class="">
<br class="">
       cfg = [];<br class="">
       cfg.projectmom = 'yes';<br class="">
       tmp = ft_sourcedescriptives(cfg, tmp);<br class="">
<br class="">
       trial_source.trial(t).mom = tmp.avg.mom;<br class="">
       trial_source.trial(t).pow = tmp.avg.pow;<br class="">
       trial_source.trial(t).ori = tmp.avg.ori;<br class="">
       trial_source.trial(t).label = tmp.avg.label;<br class="">
       trial_source.trial(t).filterdimord = tmp.avg.filterdimord;        <br class="">
   end<br class="">
<br class="">
   clear f t x tmp ans cfg<br class="">
<br class="">
   % Calculate the average signal in each ROI<br class="">
   for t = 1:length(cln_data.trial);<br class="">
       for r = 1:length(atlas.tissuelabel);<br class="">
           cfg = [];<br class="">
           cfg.atlas      = atlas;<br class="">
           cfg.roi        = atlas.tissuelabel{1,r};  % here you can also specify a single label, i.e. single ROI<br class="">
           cfg.inputcoord = 'mni';<br class="">
           mask           = ft_volumelookup(cfg, template_grid);<br class="">
<br class="">
           mask_idx = find(mask);<br class="">
<br class="">
           for m = 1:length(mask_idx);<br class="">
               if isempty(trial_source.trial(t).mom{mask_idx(m)});<br class="">
                  tmp(m,:) = nan(1,length(cln_data.trial{1}));<br class="">
               else<br class="">
                  tmp(m,:) = trial_source.trial(t).mom{mask_idx(m)};<br class="">
               end<br class="">
           end<br class="">
<br class="">
           roi(r,:) = nanmean(tmp);<br class="">
           clear tmp mask mask_idx ans m<br class="">
       end<br class="">
       roi_trial_dat{t} = roi;<br class="">
       clear roi r<br class="">
   end<br class="">
<br class="">
_______________________________________________<br class="">
fieldtrip mailing list<br class="">
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" class="">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br class="">
https://urldefense.com/v3/__https://doi.org/10.1371/journal.pcbi.1002202__;!!HJOPV4FYYWzcc1jazlU!q8K-aqjtprbNX-bLhVdFRIr1lKXtT8VKw6LQhGjxl13kWaxe7G9gYp1JvXT18OEIpcZlnTLVNDcHIOs$
<br class="">
</div>
</div>
</blockquote>
</div>
<br class="">
</div>
</div>
</body>
</html>