[TUTORIAL UNDER REVISION]


FEM tutorial with MEG/EEG median nerve stimulation (charm)

Authors: Takfarinas Medani, Juan Garcia-Prieto, Wayne Mead, Michael Funke, Francois Tadel

This tutorial introduces the most advanced FEM modeling options available in the Brainstorm environment, applied to MEG+EEG recordings of a median nerve stimulation. The pipeline presented here includes: FEM mesh reconstruction with SimNIBS4/charm, FEM head model including DTI tensors for modeling anisotropic conductivities (using BrainSuite), FEM forward model estimation with DUNEuro. This pipeline requires many third-party programs and very long computation times. For a simpler FEM pipeline, please refer to the tutorial: Realistic head model: FEM with DUNEuro.

Note that the operations used here are not detailed, the goal of this tutorial is not to introduce Brainstorm to new users. For in-depth explanations of the interface and theoretical foundations, please refer to the introduction tutorials.

Dataset description

Experiment

The experiment consists of an unilateral median nerve stimulation conducted in a MEG laboratory with an Elekta Triux (Megin, Finland) scanner.

  • The stimulation signal was a square-wave pulse with 2Hz frequency and duration of 0.2ms.
  • An ISI (inter-stimulus interval) of 500ms with a variation of ±20ms in order to be able to average out time-locked noise to the stimulation, while remaining unnoticeable by the subject.
  • The stimulation was performed on the left hand/wrist, for two minutes, with a Digitimer DS7A stimulator. An electrode was placed on the hand/wrist while current value was tuned to match the motor threshold of the subject on the stimulated hand, with a result of 10~12mA approximately.
  • Recordings were performed with a 1kHz sampling rate. Continuous HPI was disabled during these recordings. High-pass filters were set to DC for MEG channels and 0.03Hz for EEG channels.
  • All MEG files underwent a MaxFilter (version 2.3.13) tsss post-processing.

MRI imaging scanning (Philips Medical Systems):

  • T1w image without contrast: 3T field strength, flip angle 8°, TR 7.9s, dimensions 512 × 512 × 200, and voxel dimensions of 0.469 × 0.469 × 0.939 millimeters
  • T2w spin-echo image: 3T field strength, 78.57% phase FOV, 90° flip angle, SAR 0.327, voxel dimensions 560 × 560 × 55, dimensions of 0.429 × 0.429 × 3 millimeters
  • DWI sequences: voxel dimensions 512 x 512 x 200 and dimensions of 0.469 × 0.469 × 0.939 millimeters, diffusion-sensitizing gradients in 32 non-collinear directions

Files

The dataset we distribute with this tutorial follows the Brain Imaging Data Structure (BIDS) standard for neuroimaging data organization. The files that will be imported in this tutorial are the following:

sample_fem/sub-fem01/: Raw data for subject fem01

  • ses-meg/: Simultaneous recordings of MEG and EEG.

    • sub-fem01_ses-meg_task-mediannerve_run-01_proc-tsss_meg.fif

  • ses-mri/: Imaging exams.

    • anat/sub-fem01_ses-mri_T1w.nii.gz: T1-weighted MRI

    • anat/sub-fem01_ses-mri_T2w.nii.gz: T2-weighted MRI

    • dwi/sub-fem01_ses-mri_dwi.*: Diffusion-Weighted Imaging (DWI)

License

Creative Commons CC0 1.0 Universal. This dataset is distributed in the public domain.

Download and installation

Requirements

Additional programs

You need to install the following programs (listed by order of appearance):

Download the dataset

Import the anatomy

T1 MRI

T2 MRI

Diffusion imaging

The FEM has the ability to incorporate anisotropic conductivity from MRI diffusion imaging, which is particularly interesting for the modeling of the white matter. Brainstorm can load the Diffusion-Weighted Images (DWI), and compute the tensors (DTI) using the BrainSuite Diffusion Pipeline (BDP). This requires BrainSuite to be installed on your computer, with the bdp program available in the system path.

FEM head model

The FEM approach requires a segmentation of the head volume in different tissues, represented as hexahedral or tetrahedral 3D meshes. The methods available within Brainstorm are listed in the tutorial FEM mesh generation. Here we illustrate only the use of SimNIBS 4.x / charm.

FEM mesh with SimNIBS

Running SimNIBS:

At the end of this computation, new files are available in the database:

At the end of the process, make sure that the file "mid_15002V" is selected (downsampled central surface, which will be used for the source estimation). If it is not, double-click on it to select it as the default cortex surface.

simnibs4.gif

Merge tissues

The pipeline SimNIBS4/charm produces a FEM mesh with 12 types of tissues, while SimNIBS3/headreco produces a FEM mesh with only 5 tissues. For making the rest of this tutorial applicable to all versions of SimNIBS, we will now merge some tissues from the SimNIBS4 FEM mesh in order to fall back to the SimNIBS3 case. The forward modeling method used later is not capable of handling all the 12 tissues anyway (yet).

Right-click on the FEM mesh > Merge layers, and configure it as illustrated below.

merge1.gif

Left = 12 tissues; Right = 5 tissues.

merge2.png

Remesh with Iso2mesh

This step is optional, to be considered only when the DUNEuro FEM computation fails. In some cases, the FEM mesh generated with SimNIBS causes issues with the DUNEuro FEM solver, due to the air cavities that are not tesselated. In order to avoid these possible issues in the next steps, we will correct the mesh using the Iso2mesh functions integrated within Brainstorm.

The following figure shows the two model, left is the initial model obtained with SimNibs, right is the second model obtained from the Iso2Mesh remesh: the air cavity in the bottom-right corner is now fully tesselated. Note that you can also use this process to generate FEM models with higher mesh densities.

femMeshSimNibsVSiso2mesh2.jpg

FEM tensors

We can now incorporate the diffusion information into the FEM model, and compute anisotropic conductivity tensors for the tetrahedral elements of the white matter (we consider the other tissues to have isotropic conductivities).

Visualization

Brainstorms include the possibilities to display the FEM head models and the tensors, users can also overlay the display with the MRI as well as with the different surfaces.

overlayModalities.png

Right-click on the FEM mesh > Display FEM tensors: The FEM tensors can be displayed on the mesh or MRI, as arrows on the main eigenvector or as ellipsoids on each FEM element.

dispTensorMenu.png

tensorsOnBrain.jpg

tensorsOnMRI.jpg

To configure the display: right-click on the figure > FEM tensors menu. The keyboard shortcuts for changing the size of the displayed tensors are the Up and Down arrows keys. You can also switch the display mode by using the shortcut "Shift + Space".

Advanced

On the hard drive

The DTI-EIG file as the same structure as any MRI file, with 12 volumes stacked along the 4th dimension. From 1 to 9: components of the three eigenvectors; from 10 to 12: the values of their norm to the eigenvalue.

The FEM mesh contains the following fields:

femDataOnHardDisc.png

BEM head model

For the purpose of comparison between the FEM and the BEM, we will generate also the BEM surfaces for this subject and we will follow the same step as explained in the BEM tutorial.

Access the recordings

Channel file

Pre-processing

Frequency filters

EEG: Average reference

Epoching

In this experiment, the electric stimulation is sent with a frequency of 2Hz, meaning that the inter-stimulus interval is 500ms. We are going to import epochs of 300ms around the stimulation events (-100 to 200ms).

Averaging

Forward model

We are going to use the realistic FEM model previously generated from the MRI. Go to the "Anatomy" view, and make sure that the FEM head model is highlighted in green color (it should be the case if you have only one model). You may also highlight the cortex to use for the computation (select the cortex_15002V).

You can compute the forward model both for EEG and MEG simultaneously, however, using the high mesh resolution model we recommend to compute separately the head model for each modality (EEG and then MEG). The time required for EEG is around one hour for ~70 channels, for the MEG with 306 sensors it can take up to 4 hours or more (with the integrations points).

The EEG/MEG FEM computation depends on the computation of the FEM transfer matrix, which is related to the resolution of the FEM head mesh (number of vertices) and the number of sensors. In most of the case, the number of EEG sensors is lower than the number of MEG sensors. Furthermore, internally the MEG sensors modeling uses the integrations points, which increase the number of computation points (~ multiplied by 4 for the magnetometers and by 8 for the gradiometers). Therefore, the MEG requires more time than the EEG.

To reduce the MEG computation time, there are some tips:

  1. Use only the inners tissues (wm, gm, and CSF) ==> reduce the number of vertices

  2. Do not use the integration points ==> reduce the number of virtual sensors

  3. These parameters can be tuned from the DUNEuro options panel (see the advanced panel)

EEG with DTI tensors

MEG with DTI tensors

EEG with isotropic conductivity

If the DTIs are not available, it is possible to use the isotropic conductivities instead. In this tutorial, we will compute another forward model in order to compare the sources obtained with anisotropic or isotropic conductivities.

MEG with isotropic conductivity

Source estimation

Noise covariance matrix

Inverse model

It is recommended to study separately the two modalities because Brainstorm does not offer any reliable method for combining MEG and EEG source imaging yet. More explanations in the Source estimation tutorial.

Dipole scanning

Comparison: DTI vs isotropic

The following figures (left EEG, right MEG), show the localization of the dipoles on the MRI at the 21ms. The ISO model is colored in green whereas the DTI model is colored in red.

eegMegDipolesSagittal.jpg eegMegDipolesAxial.jpg eegMegDipolesCoronal.jpg

In this experiment, the anisotropy does not show a significant effect on the source localization, whereas it shows a slight difference in the orientation.

Comparison: MEG vs EEG

When we compare between the EEG and the MEG, there is a difference of 20mm between the localization between the MEG and the EEG as well as a difference in the orientation in the coronal view.

If we compare the difference between the EEG and MEG dipoles, the following figures (left anisotropy, right isotropic), show the localization of the dipoles on the MRI at the 21ms. The EEG dipole is colored in green whereas the MEG dipole is colored in red.

eegMegDipolesSagittal2.jpg eegMegDipolesAxial2.jpg eegMegDipolesCoronal2.jpg

Aniso: Eeg [-7.5 -35.7 89.8] vs Meg [-0.2 -33.6 88.6] ==> distance = 7.7mm

Iso: Eeg [-7.5 -35.7 89.8] vs Meg [-0.2 -33.6 88.6] ==> distance = 7.7mm

In both modalities, the dipoles are located exactly in the same positions, and there is 7.7mm between the two dipoles. Furthermore, we notice a difference on the orientation on the coronal and sagittal views

Comparison: FEM vs BEM/OS

We will now compare qualitatively the FEM results with the default methods implemented in Brainstorm: Overlapping spheres for MEG, BEM for EEG.

In the following figures, left is the dipoles computed from the EEG (BEM in red and FEM in green), right are the dipoles computed from the MEG (OS in red and FEM in green)

eegMegDipolesSagittal3.jpg eegMegDipolesAxial3.jpg eegMegDipolesCoronal3.jpg

EEG: fem [-7.5 -35.7 89.8] ; bem [-10.7 -35.0 89.5] ==> 3.3mm

MEG: fem [-0.2 -33.6 88.6] ; os [-10.7 -39.3 83.2] ==> 13.1 mm

As expected, the slight difference on the localization can be explained by the difference on the head shape, the conductivity values as well as the resolution method.

Advanced

Additional documentation

Articles

Scripting

The following script from the Brainstorm distribution reproduces the analysis presented in this tutorial page: brainstorm3/toolbox/script/tutorial_fem_charm.m

1 function tutorial_fem_charm(tutorial_dir) 2 % TUTORIAL_FEM_CHARM: Script that reproduces the online tutorial "FEM tutorial: MEG/EEG Median nerve stimulation (charm)" 3 % 4 % REFERENCE: 5 % https://neuroimage.usc.edu/brainstorm/Tutorials/FemMedianNerveCharm 6 % 7 % INPUTS: 8 % tutorial_dir: Directory where the sample_fem.zip file has been unzipped 9 10 % @============================================================================= 11 % This function is part of the Brainstorm software: 12 % https://neuroimage.usc.edu/brainstorm 13 % 14 % Copyright (c) University of Southern California & McGill University 15 % This software is distributed under the terms of the GNU General Public License 16 % as published by the Free Software Foundation. Further details on the GPLv3 17 % license can be found at http://www.gnu.org/copyleft/gpl.html. 18 % 19 % FOR RESEARCH PURPOSES ONLY. THE SOFTWARE IS PROVIDED "AS IS," AND THE 20 % UNIVERSITY OF SOUTHERN CALIFORNIA AND ITS COLLABORATORS DO NOT MAKE ANY 21 % WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF 22 % MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, NOR DO THEY ASSUME ANY 23 % LIABILITY OR RESPONSIBILITY FOR THE USE OF THIS SOFTWARE. 24 % 25 % For more information type "brainstorm license" at command prompt. 26 % =============================================================================@ 27 % 28 % Author: Francois Tadel, 2021-2023 29 30 31 % ===== FILES TO IMPORT ===== 32 % You have to specify the folder in which the tutorial dataset is unzipped 33 if (nargin == 0) || isempty(tutorial_dir) || ~file_exist(tutorial_dir) 34 error('The first argument must be the full path to the tutorial dataset folder.'); 35 end 36 % Build the path of the files to import 37 T1Nii = fullfile(tutorial_dir, 'sample_fem', 'sub-fem01', 'ses-mri', 'anat', 'sub-fem01_ses-mri_T1w.nii.gz'); 38 T2Nii = fullfile(tutorial_dir, 'sample_fem', 'sub-fem01', 'ses-mri', 'anat', 'sub-fem01_ses-mri_T2w.nii.gz'); 39 DwiNii = fullfile(tutorial_dir, 'sample_fem', 'sub-fem01', 'ses-mri', 'dwi', 'sub-fem01_ses-mri_dwi.nii.gz'); 40 DwiBval = fullfile(tutorial_dir, 'sample_fem', 'sub-fem01', 'ses-mri', 'dwi', 'sub-fem01_ses-mri_dwi.bval'); 41 DwiBvec = fullfile(tutorial_dir, 'sample_fem', 'sub-fem01', 'ses-mri', 'dwi', 'sub-fem01_ses-mri_dwi.bvec'); 42 FifFile = fullfile(tutorial_dir, 'sample_fem', 'sub-fem01', 'ses-meg', 'meg', 'sub-fem01_ses-meg_task-mediannerve_run-01_proc-tsss_meg.fif'); 43 % Check if the folder contains the required files 44 if ~file_exist(T1Nii) || ~file_exist(FifFile) 45 error(['The folder ' tutorial_dir ' does not contain the folder from the file sample_fem.zip.']); 46 end 47 % Subject name 48 SubjectName = 'Subject01'; 49 % Latency of interest 50 Latency = 0.022; 51 52 53 % ===== CHECK SOFTWARE DEPENDENCIES ===== 54 % Start brainstorm without the GUI 55 if ~brainstorm('status') 56 brainstorm nogui 57 end 58 % SimNIBS 4 / charm 59 status = system('charm --version'); 60 if (status ~= 0) 61 error('SimNIBS is not installed or not added to the system path: the command "headreco" could not be found.'); 62 end 63 % BrainSuite 64 if ~file_exist(bst_fullfile(bst_get('BrainSuiteDir'), 'bin')) 65 error('BrainSuite is not configured in the Brainstorm preferences.'); 66 end 67 % Iso2mesh 68 [isInstalled, errMsg] = bst_plugin('Install', 'iso2mesh', 0); 69 if ~isInstalled 70 error(['Could not install plugin: iso2mesh' 10 errMsg]); 71 end 72 73 74 % ===== CREATE PROTOCOL ===== 75 % The protocol name has to be a valid folder name (no spaces, no weird characters...) 76 ProtocolName = 'TutorialFem'; 77 % Delete existing protocol 78 gui_brainstorm('DeleteProtocol', ProtocolName); 79 % Create new protocol 80 gui_brainstorm('CreateProtocol', ProtocolName, 0, 1); 81 % Start a new report 82 bst_report('Start'); 83 84 85 %% ===== IMPORT ANATOMY ===== 86 % ===== IMPORT MRI VOLUMES ===== 87 % Create subject 88 [sSubject, iSubject] = db_add_subject(SubjectName, [], 0, 0); 89 % Import T1 MRI 90 T1File = import_mri(iSubject, T1Nii, 'ALL', 0, 0); 91 % Compute the MNI normalization 92 bst_normalize_mni(T1File); 93 % Import T2 MRI 94 T2File = import_mri(iSubject, T2Nii, 'ALL', 0, 0); 95 % Volumes are not registered: Register with SPM 96 mri_coregister(T2File, T1File, 'spm', 1); 97 % Delete the non-registered T2 98 file_delete(file_fullpath(T2File), 1); 99 db_reload_subjects(iSubject); 100 101 % ===== IMPORT DTI ===== 102 % Process: Convert DWI to DTI (BrainSuite) 103 bst_process('CallProcess', 'process_dwi2dti', [], [], ... 104 'subjectname', SubjectName, ... 105 'dwifile', {DwiNii, 'DWI-NII'}, ... 106 'bvalfile', {DwiBval, 'DWI-BVAL'}, ... 107 'bvecfile', {DwiBvec, 'DWI-BVEC'}); 108 109 % ===== RUN SIMNIBS ===== 110 % Process: Generate FEM mesh 111 bst_process('CallProcess', 'process_fem_mesh', [], [], ... 112 'subjectname', SubjectName, ... 113 'method', 'simnibs4', ... % SimNIBS 4.x:Call SimNIBS/charm to segment and mesh the T1 (and T2) MRI. 114 'nvertices', 15000, ... 115 'iseegcaps', 0, ... 116 'zneck', 0); 117 % Get cortex surface: Central / Low-resolution 118 [sSubject, iSubject, iCortex] = bst_get('SurfaceFile', bst_fullfile(SubjectName, 'tess_cortex_mid_low.mat')); 119 if isempty(sSubject) 120 error('Error while running SimNIBS4.'); 121 end 122 % Select default cortex 123 db_surface_default(iSubject, 'Cortex', iCortex); 124 125 % FEM mesh: Merge 12 tissues into 5 tissues 126 Fem12File = sSubject.Surface(sSubject.iFEM).FileName; 127 Fem5File = panel_femname('Edit', Fem12File, {'white', 'gray', 'csf', 'skull', 'scalp', 'scalp', 'skull', 'skull', 'csf', 'csf', '', ''}); 128 129 % ===== REMESH WITH ISO2MESH ===== 130 % Part skipped because: 131 % 1) Not needed: DUNEuro works with cavities in this case 132 % 2) No process call for: Extract surfaces (import_femlayers) 133 % 3) Remeshing with iso2mesh doesn't work... 134 135 % ===== COMPUTE FEM TENSORS ===== 136 % Process: Compute FEM tensors 137 bst_process('CallProcess', 'process_fem_tensors', [], [], ... 138 'subjectname', SubjectName, ... 139 'femcond', struct(... 140 'FemCond', [0.14, 0.33, 1.79, 0.008, 0.43], ... 141 'isIsotropic', [0, 1, 1, 1, 1], ... 142 'AnisoMethod', 'ema+vc', ... 143 'SimRatio', 10, ... 144 'SimConstrMethod', 'wolters')); 145 146 % ===== COMPUTE BEM SURFACES ===== 147 % Process: Generate BEM surfaces 148 bst_process('CallProcess', 'process_generate_bem', [], [], ... 149 'subjectname', SubjectName, ... 150 'nscalp', 1922, ... 151 'nouter', 1922, ... 152 'ninner', 1922, ... 153 'thickness', 4, ... 154 'method', 'brainstorm'); 155 156 157 %% ===== ACCESS THE RECORDINGS ===== 158 % Process: Create link to raw file 159 sFilesRaw = bst_process('CallProcess', 'process_import_data_raw', [], [], ... 160 'subjectname', SubjectName, ... 161 'datafile', {FifFile, 'FIF'}, ... 162 'channelreplace', 0, ... 163 'channelalign', 1, ... % Automatic registration with digitized head points 164 'evtmode', 'value'); 165 166 % Process: Events: Read from channel 167 sFilesRaw = bst_process('CallProcess', 'process_evt_read', sFilesRaw, [], ... 168 'stimchan', 'STI101', ... 169 'trackmode', 1, ... % Value: detect the changes of channel value 170 'zero', 0); 171 172 % Process: Project electrodes on scalp 173 bst_process('CallProcess', 'process_channel_project', sFilesRaw, []); 174 175 % Process: Snapshot: Sensors/MRI registration 176 bst_process('CallProcess', 'process_snapshot', sFilesRaw, [], ... 177 'target', 1, ... % Sensors/MRI registration 178 'modality', 1, ... % MEG (All) 179 'orient', 1, ... % left 180 'Comment', 'MEG/MRI Registration'); 181 % Process: Snapshot: Sensors/MRI registration 182 bst_process('CallProcess', 'process_snapshot', sFilesRaw, [], ... 183 'target', 1, ... % Sensors/MRI registration 184 'modality', 4, ... % EEG 185 'orient', 1, ... % left 186 'Comment', 'EEG/MRI Registration'); 187 188 189 %% ===== PRE-PROCESSING ===== 190 % Process: Band-pass:20Hz-250Hz 191 sFilesBand = bst_process('CallProcess', 'process_bandpass', sFilesRaw, [], ... 192 'sensortypes', 'MEG, EEG', ... 193 'highpass', 20, ... 194 'lowpass', 250, ... 195 'tranband', 0, ... 196 'attenuation', 'strict', ... % 60dB 197 'ver', '2019', ... % 2019 198 'mirror', 0, ... 199 'read_all', 0); 200 201 % Process: Notch filter: 60Hz 120Hz 180Hz 202 sFilesClean = bst_process('CallProcess', 'process_notch', sFilesBand, [], ... 203 'sensortypes', 'MEG, EEG', ... 204 'freqlist', [60, 120, 180], ... 205 'cutoffW', 2, ... 206 'useold', 0, ... 207 'read_all', 0); 208 209 % Process: Power spectrum density (Welch) 210 sFilesPsd = bst_process('CallProcess', 'process_psd', [sFilesRaw, sFilesClean], [], ... 211 'timewindow', [], ... 212 'win_length', 5, ... 213 'win_overlap', 50, ... 214 'units', 'physical', ... % Physical: U2/Hz 215 'sensortypes', 'MEG, EEG', ... 216 'win_std', 0, ... 217 'edit', struct(... 218 'Comment', 'Power', ... 219 'TimeBands', [], ... 220 'Freqs', [], ... 221 'ClusterFuncTime', 'none', ... 222 'Measure', 'power', ... 223 'Output', 'all', ... 224 'SaveKernel', 0)); 225 226 % Process: Snapshot: Frequency spectrum 227 bst_process('CallProcess', 'process_snapshot', sFilesPsd, [], ... 228 'target', 10, ... % Frequency spectrum 229 'Comment', 'Power spectrum density'); 230 231 % Process: Delete selected files 232 bst_process('CallProcess', 'process_delete', [sFilesRaw, sFilesBand], [], ... 233 'target', 2); % Delete selected folders 234 235 % Process: Re-reference EEG 236 bst_process('CallProcess', 'process_eegref', sFilesClean, [], ... 237 'eegref', 'AVERAGE', ... 238 'sensortypes', 'EEG'); 239 240 241 %% ===== IMPORT RECORDINGS ===== 242 % Process: Import MEG/EEG: Events 243 sFilesEpochs = bst_process('CallProcess', 'process_import_data_event', sFilesClean, [], ... 244 'subjectname', SubjectName, ... 245 'condition', '', ... 246 'eventname', '2', ... 247 'timewindow', [], ... 248 'epochtime', [-0.1, 0.2], ... 249 'createcond', 0, ... 250 'ignoreshort', 1, ... 251 'usectfcomp', 1, ... 252 'usessp', 1, ... 253 'freq', [], ... 254 'baseline', []); 255 256 % Process: Average: By trial group (folder average) 257 sFilesAvg = bst_process('CallProcess', 'process_average', sFilesEpochs, [], ... 258 'avgtype', 5, ... % By trial group (folder average) 259 'avg_func', 1, ... % Arithmetic average: mean(x) 260 'weighted', 0, ... 261 'keepevents', 0); 262 263 % Process: Snapshot: Recordings time series 264 bst_process('CallProcess', 'process_snapshot', sFilesAvg, [], ... 265 'target', 5, ... % Recordings time series 266 'modality', 4, ... % EEG 267 'Comment', 'EEG ERP'); 268 % Process: Snapshot: Recordings topography (contact sheet) 269 bst_process('CallProcess', 'process_snapshot', sFilesAvg, [], ... 270 'target', 6, ... % Recordings topography (ont time) 271 'modality', 4, ... % EEG 272 'time', Latency, ... 273 'Comment', 'EEG ERP'); 274 % Process: Snapshot: Recordings time series 275 bst_process('CallProcess', 'process_snapshot', sFilesAvg, [], ... 276 'target', 5, ... % Recordings time series 277 'modality', 1, ... % MEG (All) 278 'Comment', 'MEG ERF'); 279 % Process: Snapshot: Recordings topography (contact sheet) 280 bst_process('CallProcess', 'process_snapshot', sFilesAvg, [], ... 281 'target', 6, ... % Recordings topography (ont time) 282 'modality', 1, ... % MEG (All) 283 'time', Latency, ... 284 'Comment', 'MEG ERF'); 285 286 287 %% ===== NOISE COVARIANCE ===== 288 % Process: Compute covariance (noise or data) 289 bst_process('CallProcess', 'process_noisecov', sFilesEpochs, [], ... 290 'baseline', [-0.1, -0.01], ... 291 'sensortypes', 'MEG, EEG', ... 292 'target', 1, ... % Noise covariance (covariance over baseline time window) 293 'dcoffset', 1, ... % Block by block, to avoid effects of slow shifts in data 294 'replacefile', 1); % Replace 295 296 % Save and display report 297 ReportFile = bst_report('Save', []); 298 bst_report('Open', ReportFile); 299 300 301 %% ===== FORWARD: FEM EEG DTI ===== 302 % Process: Compute head model 303 bst_process('CallProcess', 'process_headmodel', sFilesAvg, [], ... 304 'Comment', 'DUNEuro FEM EEG DTI', ... 305 'sourcespace', 1, ... % Cortex surface 306 'meg', 1, ... % 307 'eeg', 4, ... % DUNEuro FEM 308 'ecog', 1, ... % 309 'seeg', 1, ... % 310 'duneuro', struct(... 311 'FemCond', [], ... 312 'FemSelect', [1, 1, 1, 1, 1], ... 313 'UseTensor', 1, ... 314 'Isotropic', 1, ... 315 'SrcShrink', 0, ... 316 'SrcForceInGM', 0, ... 317 'FemType', 'fitted', ... 318 'SolverType', 'cg', ... 319 'GeometryAdapted', 0, ... 320 'Tolerance', 1e-08, ... 321 'ElecType', 'normal', ... 322 'MegIntorderadd', 0, ... 323 'MegType', 'physical', ... 324 'SolvSolverType', 'cg', ... 325 'SolvPrecond', 'amg', ... 326 'SolvSmootherType', 'ssor', ... 327 'SolvIntorderadd', 0, ... 328 'DgSmootherType', 'ssor', ... 329 'DgScheme', 'sipg', ... 330 'DgPenalty', 20, ... 331 'DgEdgeNormType', 'houston', ... 332 'DgWeights', 1, ... 333 'DgReduction', 1, ... 334 'SolPostProcess', 1, ... 335 'SolSubstractMean', 0, ... 336 'SolSolverReduction', 1e-10, ... 337 'SrcModel', 'venant', ... 338 'SrcIntorderadd', 0, ... 339 'SrcIntorderadd_lb', 2, ... 340 'SrcNbMoments', 3, ... 341 'SrcRefLen', 20, ... 342 'SrcWeightExp', 1, ... 343 'SrcRelaxFactor', 6, ... 344 'SrcMixedMoments', 1, ... 345 'SrcRestrict', 1, ... 346 'SrcInit', 'closest_vertex', ... 347 'BstSaveTransfer', 0, ... 348 'BstEegTransferFile', 'eeg_transfer.dat', ... 349 'BstMegTransferFile', 'meg_transfer.dat', ... 350 'BstEegLfFile', 'eeg_lf.dat', ... 351 'BstMegLfFile', 'meg_lf.dat', ... 352 'UseIntegrationPoint', 1, ... 353 'EnableCacheMemory', 0, ... 354 'MegPerBlockOfSensor', 0), ... 355 'channelfile', ''); 356 % Process: Compute sources [2018] 357 sSrcEegFemDti = bst_process('CallProcess', 'process_inverse_2018', sFilesAvg, [], ... 358 'output', 1, ... % Kernel only: shared 359 'inverse', struct(... 360 'Comment', 'Dipoles: EEG FEM DTI', ... 361 'InverseMethod', 'gls', ... 362 'InverseMeasure', 'performance', ... 363 'SourceOrient', {{'free'}}, ... 364 'Loose', 0.2, ... 365 'UseDepth', 1, ... 366 'WeightExp', 0.5, ... 367 'WeightLimit', 10, ... 368 'NoiseMethod', 'median', ... 369 'NoiseReg', 0.1, ... 370 'SnrMethod', 'rms', ... 371 'SnrRms', 1e-06, ... 372 'SnrFixed', 3, ... 373 'ComputeKernel', 1, ... 374 'DataTypes', {{'EEG'}})); 375 % Process: Dipole scanning 376 sDipEegFemDti = bst_process('CallProcess', 'process_dipole_scanning', sSrcEegFemDti, [], ... 377 'timewindow', [Latency, Latency], ... 378 'scouts', {}); 379 380 381 %% ===== FORWARD: FEM MEG DTI ===== 382 % Process: Compute head model 383 bst_process('CallProcess', 'process_headmodel', sFilesAvg, [], ... 384 'Comment', 'DUNEuro FEM MEG DTI', ... 385 'sourcespace', 1, ... % Cortex surface 386 'meg', 5, ... % DUNEuro FEM 387 'eeg', 1, ... % 388 'ecog', 1, ... % 389 'seeg', 1, ... % 390 'duneuro', struct(... 391 'FemCond', [], ... 392 'FemSelect', [1, 1, 1, 0, 0], ... 393 'UseTensor', 1, ... 394 'Isotropic', 1, ... 395 'SrcShrink', 0, ... 396 'SrcForceInGM', 0, ... 397 'FemType', 'fitted', ... 398 'SolverType', 'cg', ... 399 'GeometryAdapted', 0, ... 400 'Tolerance', 1e-08, ... 401 'ElecType', 'normal', ... 402 'MegIntorderadd', 0, ... 403 'MegType', 'physical', ... 404 'SolvSolverType', 'cg', ... 405 'SolvPrecond', 'amg', ... 406 'SolvSmootherType', 'ssor', ... 407 'SolvIntorderadd', 0, ... 408 'DgSmootherType', 'ssor', ... 409 'DgScheme', 'sipg', ... 410 'DgPenalty', 20, ... 411 'DgEdgeNormType', 'houston', ... 412 'DgWeights', 1, ... 413 'DgReduction', 1, ... 414 'SolPostProcess', 1, ... 415 'SolSubstractMean', 0, ... 416 'SolSolverReduction', 1e-10, ... 417 'SrcModel', 'venant', ... 418 'SrcIntorderadd', 0, ... 419 'SrcIntorderadd_lb', 2, ... 420 'SrcNbMoments', 3, ... 421 'SrcRefLen', 20, ... 422 'SrcWeightExp', 1, ... 423 'SrcRelaxFactor', 6, ... 424 'SrcMixedMoments', 1, ... 425 'SrcRestrict', 1, ... 426 'SrcInit', 'closest_vertex', ... 427 'BstSaveTransfer', 0, ... 428 'BstEegTransferFile', 'eeg_transfer.dat', ... 429 'BstMegTransferFile', 'meg_transfer.dat', ... 430 'BstEegLfFile', 'eeg_lf.dat', ... 431 'BstMegLfFile', 'meg_lf.dat', ... 432 'UseIntegrationPoint', 1, ... 433 'EnableCacheMemory', 0, ... 434 'MegPerBlockOfSensor', 0), ... 435 'channelfile', ''); 436 % Process: Compute sources [2018] 437 sSrcMegFemDti = bst_process('CallProcess', 'process_inverse_2018', sFilesAvg, [], ... 438 'output', 1, ... % Kernel only: shared 439 'inverse', struct(... 440 'Comment', 'Dipoles: MEG FEM DTI', ... 441 'InverseMethod', 'gls', ... 442 'InverseMeasure', 'performance', ... 443 'SourceOrient', {{'free'}}, ... 444 'Loose', 0.2, ... 445 'UseDepth', 1, ... 446 'WeightExp', 0.5, ... 447 'WeightLimit', 10, ... 448 'NoiseMethod', 'median', ... 449 'NoiseReg', 0.1, ... 450 'SnrMethod', 'rms', ... 451 'SnrRms', 1e-06, ... 452 'SnrFixed', 3, ... 453 'ComputeKernel', 1, ... 454 'DataTypes', {{'MEG GRAD', 'MEG MAG'}})); 455 % Process: Dipole scanning 456 sDipMegFemDti = bst_process('CallProcess', 'process_dipole_scanning', sSrcMegFemDti, [], ... 457 'timewindow', [Latency, Latency], ... 458 'scouts', {}); 459 460 461 %% ===== FORWARD: FEM EEG ISO ===== 462 % Get updated subject structure 463 sSubject = bst_get('Subject', iSubject); 464 % Get FEM file 465 FemFile = file_fullpath(sSubject.Surface(sSubject.iFEM).FileName); 466 % Remove tensors 467 process_fem_tensors('ClearTensors', FemFile); 468 % Process: Compute head model 469 bst_process('CallProcess', 'process_headmodel', sFilesAvg, [], ... 470 'Comment', 'DUNEuro FEM EEG ISO', ... 471 'sourcespace', 1, ... % Cortex surface 472 'meg', 1, ... % 473 'eeg', 4, ... % DUNEuro FEM 474 'ecog', 1, ... % 475 'seeg', 1, ... % 476 'duneuro', struct(... 477 'FemCond', [0.14, 0.33, 1.79, 0.008, 0.43], ... 478 'FemSelect', [1, 1, 1, 1, 1], ... 479 'UseTensor', 0, ... 480 'Isotropic', 1, ... 481 'SrcShrink', 0, ... 482 'SrcForceInGM', 0, ... 483 'FemType', 'fitted', ... 484 'SolverType', 'cg', ... 485 'GeometryAdapted', 0, ... 486 'Tolerance', 1e-08, ... 487 'ElecType', 'normal', ... 488 'MegIntorderadd', 0, ... 489 'MegType', 'physical', ... 490 'SolvSolverType', 'cg', ... 491 'SolvPrecond', 'amg', ... 492 'SolvSmootherType', 'ssor', ... 493 'SolvIntorderadd', 0, ... 494 'DgSmootherType', 'ssor', ... 495 'DgScheme', 'sipg', ... 496 'DgPenalty', 20, ... 497 'DgEdgeNormType', 'houston', ... 498 'DgWeights', 1, ... 499 'DgReduction', 1, ... 500 'SolPostProcess', 1, ... 501 'SolSubstractMean', 0, ... 502 'SolSolverReduction', 1e-10, ... 503 'SrcModel', 'venant', ... 504 'SrcIntorderadd', 0, ... 505 'SrcIntorderadd_lb', 2, ... 506 'SrcNbMoments', 3, ... 507 'SrcRefLen', 20, ... 508 'SrcWeightExp', 1, ... 509 'SrcRelaxFactor', 6, ... 510 'SrcMixedMoments', 1, ... 511 'SrcRestrict', 1, ... 512 'SrcInit', 'closest_vertex', ... 513 'BstSaveTransfer', 0, ... 514 'BstEegTransferFile', 'eeg_transfer.dat', ... 515 'BstMegTransferFile', 'meg_transfer.dat', ... 516 'BstEegLfFile', 'eeg_lf.dat', ... 517 'BstMegLfFile', 'meg_lf.dat', ... 518 'UseIntegrationPoint', 1, ... 519 'EnableCacheMemory', 0, ... 520 'MegPerBlockOfSensor', 0), ... 521 'channelfile', ''); 522 % Process: Compute sources [2018] 523 sSrcEegFemIso = bst_process('CallProcess', 'process_inverse_2018', sFilesAvg, [], ... 524 'output', 1, ... % Kernel only: shared 525 'inverse', struct(... 526 'Comment', 'Dipoles: EEG FEM ISO', ... 527 'InverseMethod', 'gls', ... 528 'InverseMeasure', 'performance', ... 529 'SourceOrient', {{'free'}}, ... 530 'Loose', 0.2, ... 531 'UseDepth', 1, ... 532 'WeightExp', 0.5, ... 533 'WeightLimit', 10, ... 534 'NoiseMethod', 'median', ... 535 'NoiseReg', 0.1, ... 536 'SnrMethod', 'rms', ... 537 'SnrRms', 1e-06, ... 538 'SnrFixed', 3, ... 539 'ComputeKernel', 1, ... 540 'DataTypes', {{'EEG'}})); 541 % Process: Dipole scanning 542 sDipEegFemIso = bst_process('CallProcess', 'process_dipole_scanning', sSrcEegFemIso, [], ... 543 'timewindow', [Latency, Latency], ... 544 'scouts', {}); 545 546 547 %% ===== FORWARD: FEM MEG ISO ===== 548 % Process: Compute head model 549 bst_process('CallProcess', 'process_headmodel', sFilesAvg, [], ... 550 'Comment', 'DUNEuro FEM MEG ISO', ... 551 'sourcespace', 1, ... % Cortex surface 552 'meg', 5, ... % DUNEuro FEM 553 'eeg', 1, ... % 554 'ecog', 1, ... % 555 'seeg', 1, ... % 556 'duneuro', struct(... 557 'FemCond', [0.14, 0.33, 1.79, 0.008, 0.43], ... 558 'FemSelect', [1, 1, 1, 0, 0], ... 559 'UseTensor', 0, ... 560 'Isotropic', 1, ... 561 'SrcShrink', 0, ... 562 'SrcForceInGM', 0, ... 563 'FemType', 'fitted', ... 564 'SolverType', 'cg', ... 565 'GeometryAdapted', 0, ... 566 'Tolerance', 1e-08, ... 567 'ElecType', 'normal', ... 568 'MegIntorderadd', 0, ... 569 'MegType', 'physical', ... 570 'SolvSolverType', 'cg', ... 571 'SolvPrecond', 'amg', ... 572 'SolvSmootherType', 'ssor', ... 573 'SolvIntorderadd', 0, ... 574 'DgSmootherType', 'ssor', ... 575 'DgScheme', 'sipg', ... 576 'DgPenalty', 20, ... 577 'DgEdgeNormType', 'houston', ... 578 'DgWeights', 1, ... 579 'DgReduction', 1, ... 580 'SolPostProcess', 1, ... 581 'SolSubstractMean', 0, ... 582 'SolSolverReduction', 1e-10, ... 583 'SrcModel', 'venant', ... 584 'SrcIntorderadd', 0, ... 585 'SrcIntorderadd_lb', 2, ... 586 'SrcNbMoments', 3, ... 587 'SrcRefLen', 20, ... 588 'SrcWeightExp', 1, ... 589 'SrcRelaxFactor', 6, ... 590 'SrcMixedMoments', 1, ... 591 'SrcRestrict', 1, ... 592 'SrcInit', 'closest_vertex', ... 593 'BstSaveTransfer', 0, ... 594 'BstEegTransferFile', 'eeg_transfer.dat', ... 595 'BstMegTransferFile', 'meg_transfer.dat', ... 596 'BstEegLfFile', 'eeg_lf.dat', ... 597 'BstMegLfFile', 'meg_lf.dat', ... 598 'UseIntegrationPoint', 1, ... 599 'EnableCacheMemory', 0, ... 600 'MegPerBlockOfSensor', 0), ... 601 'channelfile', ''); 602 % Process: Compute sources [2018] 603 sSrcMegFemIso = bst_process('CallProcess', 'process_inverse_2018', sFilesAvg, [], ... 604 'output', 1, ... % Kernel only: shared 605 'inverse', struct(... 606 'Comment', 'Dipoles: MEG FEM ISO', ... 607 'InverseMethod', 'gls', ... 608 'InverseMeasure', 'performance', ... 609 'SourceOrient', {{'free'}}, ... 610 'Loose', 0.2, ... 611 'UseDepth', 1, ... 612 'WeightExp', 0.5, ... 613 'WeightLimit', 10, ... 614 'NoiseMethod', 'median', ... 615 'NoiseReg', 0.1, ... 616 'SnrMethod', 'rms', ... 617 'SnrRms', 1e-06, ... 618 'SnrFixed', 3, ... 619 'ComputeKernel', 1, ... 620 'DataTypes', {{'MEG GRAD', 'MEG MAG'}})); 621 % Process: Dipole scanning 622 sDipMegFemIso = bst_process('CallProcess', 'process_dipole_scanning', sSrcMegFemIso, [], ... 623 'timewindow', [Latency, Latency], ... 624 'scouts', {}); 625 626 627 %% ===== FORWARD: BEM EEG ===== 628 % Process: Compute head model 629 bst_process('CallProcess', 'process_headmodel', sFilesAvg, [], ... 630 'Comment', 'OpenMEEG BEM EEG', ... 631 'sourcespace', 1, ... % Cortex surface 632 'meg', 1, ... % 633 'eeg', 3, ... % OpenMEEG BEM 634 'ecog', 1, ... % 635 'seeg', 1, ... % 636 'openmeeg', struct(... 637 'BemSelect', [1, 1, 1], ... 638 'BemCond', [1, 0.0125, 1], ... 639 'BemNames', {{'Scalp', 'Skull', 'Brain'}}, ... 640 'BemFiles', {{}}, ... 641 'isAdjoint', 0, ... 642 'isAdaptative', 1, ... 643 'isSplit', 0, ... 644 'SplitLength', 4000), ... 645 'channelfile', ''); 646 % Process: Compute sources [2018] 647 sSrcEegBem = bst_process('CallProcess', 'process_inverse_2018', sFilesAvg, [], ... 648 'output', 1, ... % Kernel only: shared 649 'inverse', struct(... 650 'Comment', 'Dipoles: EEG BEM', ... 651 'InverseMethod', 'gls', ... 652 'InverseMeasure', 'performance', ... 653 'SourceOrient', {{'free'}}, ... 654 'Loose', 0.2, ... 655 'UseDepth', 1, ... 656 'WeightExp', 0.5, ... 657 'WeightLimit', 10, ... 658 'NoiseMethod', 'median', ... 659 'NoiseReg', 0.1, ... 660 'SnrMethod', 'rms', ... 661 'SnrRms', 1e-06, ... 662 'SnrFixed', 3, ... 663 'ComputeKernel', 1, ... 664 'DataTypes', {{'EEG'}})); 665 % Process: Dipole scanning 666 sDipEegBem = bst_process('CallProcess', 'process_dipole_scanning', sSrcEegBem, [], ... 667 'timewindow', [Latency, Latency], ... 668 'scouts', {}); 669 670 671 %% ===== FORWARD: OS MEG ===== 672 % Process: Compute head model 673 bst_process('CallProcess', 'process_headmodel', sFilesAvg, [], ... 674 'Comment', 'OS MEG', ... 675 'sourcespace', 1, ... % Cortex surface 676 'meg', 3, ... % Overlapping spheres 677 'eeg', 1, ... % 678 'ecog', 1, ... % 679 'seeg', 1, ... % 680 'channelfile', ''); 681 % Process: Compute sources [2018] 682 sSrcMegOs = bst_process('CallProcess', 'process_inverse_2018', sFilesAvg, [], ... 683 'output', 1, ... % Kernel only: shared 684 'inverse', struct(... 685 'Comment', 'Dipoles: MEG OS', ... 686 'InverseMethod', 'gls', ... 687 'InverseMeasure', 'performance', ... 688 'SourceOrient', {{'free'}}, ... 689 'Loose', 0.2, ... 690 'UseDepth', 1, ... 691 'WeightExp', 0.5, ... 692 'WeightLimit', 10, ... 693 'NoiseMethod', 'median', ... 694 'NoiseReg', 0.1, ... 695 'SnrMethod', 'rms', ... 696 'SnrRms', 1e-06, ... 697 'SnrFixed', 3, ... 698 'ComputeKernel', 1, ... 699 'DataTypes', {{'MEG GRAD', 'MEG MAG'}})); 700 % Process: Dipole scanning 701 sDipMegOs = bst_process('CallProcess', 'process_dipole_scanning', sSrcMegOs, [], ... 702 'timewindow', [Latency, Latency], ... 703 'scouts', {}); 704 705 706 %% ===== MERGE DIPOLES ===== 707 % sDipEegFemDti, sDipMegFemDti, sDipEegFemIso, sDipMegFemIso, sDipEegBem, sDipMegOs 708 % FEM DTI: EEG vs MEG 709 % sDipFemDti = dipoles_merge({sDipEegFemDti.FileName, sDipMegFemDti.FileName}); 710 711 712 % Save and display report 713 ReportFile = bst_report('Save', []); 714 bst_report('Open', ReportFile); 715 716 717





Feedback: Comments, bug reports, suggestions, questions
Email address (if you expect an answer):


Tutorials/FemMedianNerveCharm (last edited 2023-03-01 11:33:59 by FrancoisTadel)