Brainstorm
  • Comments
  • Menu
    • Attachments
    • Versions
    • Raw Text
    • Print View
  • Login

Software

  • Introduction

  • Gallery

  • Download

  • Installation

Users

  • Tutorials

  • Forum

  • Courses

  • Community

  • Publications

Development

  • What's new

  • What's next

  • About us

  • Contact us

  • Contribute

Revision 5 as of 2023-02-23 11:08:50
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

[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.

Contents

  1. Dataset description
  2. Download and installation
  3. Import the anatomy
    1. T1 MRI
    2. T2 MRI
    3. Diffusion imaging
  4. FEM head model
    1. FEM mesh with SimNIBS
    2. Remesh with Iso2mesh
    3. FEM tensors
    4. Visualization
    5. On the hard drive
    6. BEM head model
  5. Access the recordings
    1. Link the recordings
    2. Channel file
    3. Pre-processing
    4. Frequency filters
    5. EEG: Average reference
    6. Epoching
    7. Averaging
  6. Forward model
    1. EEG with DTI tensors
    2. MEG with DTI tensors
    3. EEG with isotropic conductivity
    4. MEG with isotropic conductivity
  7. Source estimation
    1. Noise covariance matrix
    2. Inverse model
    3. Dipole scanning
    4. Comparison: DTI vs isotropic
    5. Comparison: MEG vs EEG
    6. Comparison: FEM vs BEM/OS
  8. Additional documentation
  9. Scripting

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

  • You have already followed all the introduction tutorials.
  • You have a working copy of Brainstorm installed on your computer.

Additional programs

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

  • SimNIBS 4.x: See tutorial: FEM mesh generation

  • BrainSuite: See tutorial: FEM tensors estimation

  • MATLAB Runtime: Follow the instructions on the BrainSuite download page

  • Iso2mesh: Install as Brainstorm plugins

  • DUNEuro: See tutorial: Realistic head model: FEM with DUNEuro

Download the dataset

  • Go to the Download page and get the file: sample_fem.zip

  • Unzip it outside of any of the Brainstorm folders (program folder or database folder).
  • Start Brainstorm (Matlab scripts or stand-alone version)
  • Select the menu File > Create new protocol. Name it "TutorialFem" and select:

    • No, use individual anatomy
    • No, use one channel file per condition

Import the anatomy

T1 MRI

  • Switch to the "anatomical data" view, the left button in the toolbar above the database explorer.
  • Right-click on the TutorialFem folder > New subject > Subject01

    • Keep the default options you set for the protocol.
  • Right-click on the subject node > Import MRI:

    • Set the file format: All MRI files (subject space)

    • Select the T1 file: sub-fem01/ses-mri/anat/sub-fem01_ses-mri_T1w.nii.gz

  • Click on the link "Click here to compute MNI normalization": option "maff8".
    This estimates an affine transformation to the MNI space and sets default positions for the anatomical fiducials. Because we will use the digitized head shape of the subject to refine the MRI/MEG registration, we don't need the position of the fiducials to be very accurate.

    importT1.gif

T2 MRI

  • Right-click on the subject node > Import MRI:

    • Set the file format: All MRI files (subject space)

    • Select the T2 file: sub-fem01/ses-mri/anat/sub-fem01_ses-mri_T2w.nii.gz

  • Brainstorm asks about registering the new T2 with the reference T1 image:
    • Select the option: SPM

    • Reslice the volume: Yes

  • This process will take few minutes, just be patient.

    importT2.gif

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.

  • Right-click on Subject01 > Convert DWI to DTI

  • Select the DWI file: sub-fem01/ses-mri/dwi/sub-fem01_ses-mri_dwi.nii.gz

  • The associated files *dwi.bvec and *dwi.bval must be in the same folder.
  • The process can take up to 30min. At the end, a new file DTI-EIG appears in the database. This file contains 12 volumes, ie. 12 values for each voxel. From 1 to 9: components of the three eigenvectors; from 10 to 12: the values of their norm to the eigenvalue.

    importDTI.gif

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:

  • Select both the T1 and the T2 MRIs, using the mouse and the SHIFT or CTRL keys.
  • Right-click on the selected files > MRI segmentation > Generate FEM mesh > SimNIBS4. Keep the default options.

  • This process can take 2-5 hours.
  • The output of SimNIBS is saved in the temporary folder $HOME/.brainstorm/tmp/simnibs, and then imported into the Brainstorm database.

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

  • tissues: Segmentation of the head volume in 6 different tissues

  • head mask: Outer surface of the scalp

  • cortex_280000V: Pial surface generated by CAT12 within the SimNIBS process

  • cortex_15002V: Low-resolution version of the pial surface

  • cortex_fem: Outer surface mesh of the gray matter, extracted from the FEM mesh

  • FEM 70000V: Tetrahedral FEM mesh with 5 layers (gm, wm, CSF, skull, scalp).

At the end of the process, make sure that the file "cortex_15002V" is selected (downsampled pial 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

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.

  • Right-click on the FEM mesh > Extract surfaces.

  • Hold the CTRL key to select all the extracted surfaces (white, gray, csf, skull, scalp).
  • Right-click > Generate FEM mesh > Iso2mesh-2021 > MergeMesh > Max volume = 0.001, Percentage kept = 100. Note that the higher the resolution leads to higher accuracy but also higher memory requirements and longer computation times.

    remeshHeadIso2mesh.jpg

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).

  • Right-click on the FEM mesh > Compute FEM tensors. Select the options as illustrated below, and refer to the tutorial FEM tensors for more information.

    computeTensors.gif

  • This process can take up to 5min, depending on the resolution of the FEM mesh.

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.

  • Right-click on Subject01 > MRI segmentation > Generate BEM surfaces > Brainstorm.
    Keep the default options: 1922 vertices for all the layers, skull thickness = 4m.

  • Three new files appear in the database explorer: bem_head_1922V, bem_outerskull_1922V, and bem_innerskull_1922V. These surfaces will be used for the BEM forward computation.
  • Now we have two head geometry available for this subject, BEM and FEM fem&bemModels.jpg

Access the recordings

Link the recordings

  • Switch to the "functional data" view, the middle button in the toolbar above the database explorer.
  • The folder "eeg_positions" which contains default 10-10 EEG electrodes positions, was generated by the SimNIBS process. We will not use it in this tutorial: delete this folder.

  • Right-click on the subject folder > Review raw file:

    • Select file type: MEG/EEG: Electa-Neuromag(*.fif)
    • Select file: sub-fem01/ses-meg/meg/sub-fem01_ses-meg_task-mediannerve_run-01_proc-tsss_meg.fif

    • FIF event file: Select Event Channel, this will read the events markers

    • Refine registration? YES

  • A figure is opened to show the registration MRI/MEG.

    registration.gif

  • The new file "Link to raw file" lets you access directly the contents of the MEG/EEG recordings. The "Neuromag channels (374)" contains the name of the channels and the position of the corresponding sensors (MEG/EEG).

Channel file

  • The recordings contain signals coming from different types of electrodes:
    • 306 MEG channels (102 magnetometers and 204 gradiometers )
    • 64 EEG channels
    • 2 EOG channels: EO1 and EO2
    • 1 Stim channel that contain the stimulation signals
  • Right-click on the channel file > MRI registration > Edit... (EEG)

  • The white points are the electrodes, the green points are the additional digitized head points. To display the label of the electrodes, click on the [LABEL] button in the toolbar. To see what the other buttons in the toolbar are doing and how to use them, leave your mouse over them for a few seconds and read the description.
  • The automatic registration based on the head points is already good, therefore we won't apply any additional rotation+translation to the MEG+EEG sensors.
  • Click on the button "Project electrodes on scalp surface", it will help for the source modeling later. The green points (digitized) stay in place, the white points (electrodes) are now projected on the skin of the subject.

  • If you feel like you didn't do this correctly, close the figure and cancel the modifications, then try again.
  • Click on [OK] when done. Answer YES to save the modifications.

Pre-processing

  • Drag and drop the "Link to raw file" into the Process1 list.
  • Select the process "Frequency > Power spectrum density", configure it as in the figure

  • After the computation, double-click on the new PSD file to display it.

    [ATTACH]

  • The lines on the top represent the EEG electrodes, the lines at the bottom the MEG sensors(MAG and GRAD). If you want to get clearer plots, you can calculate separately the spectrum for the two types of sensors separately, by running twice the process "Power spectrum density", once with sensor types = "MEG" and once with "EEG", instead of running in on both at the same time as we did.
  • Observations (below 250Hz):
    • Peak around 10Hz: Alpha waves from the subject's brain
    • Peaks at 60Hz, 120Hz, 180Hz, 240Hz on EEG + MEG: Power lines (60Hz+harmonics)
    • Most of the signal looks clean and no bad channel is observed
  • If we review quickly the EEG and EOG signals, we notice that they are quite clean and no artifacts are observed. The experiment is well designed and the subject was not moving the eyes (blinks and slow movements), maybe because there was a fixation cross for this experiment. However, we will apply at least a high-pass filter to make the signals easier to process (we are not interested in very low frequencies in this experiment).

Frequency filters

  • In Process1, select the "Link to raw file".
  • Select process Pre-process > Band-pass filter: Frequency=[20, 250]Hz, Sensors=MEG,EEG

  • Add process Pre-process > Notch filter: Frequencies=[60 120 180]Hz, Sensors=MEG,EEG

    [ATTACH]

  • In Process1, select the filtered file "Raw | Band | Notch".
  • Run the process "Frequency > Power spectrum density", with the same options as before. And compare with the previous figure. You may find that the power line frequency and its harmonics are removed and the data is filtered between 20 and 250Hz.

    spectreClean.jpg

  • To keep the interface clean and easy to follow: keep only the last continuous file (Raw|Band|Notch). Delete the link to the original file (which will not delete the original .fif file), and delete the "Raw|Band" file.

EEG: Average reference

  • Right-click on the filtered file "Raw|band|notch" > EEG > Display time series.

  • In the Record tab, menu Artifacts > Re-reference EEG > "AVERAGE".

    avgRef.jpg

  • At the end, the window "Select active projectors" is open to show the new re-referencing projector. Just close this window. To get it back, use the menu Artifacts > Select active projectors.

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).

  • Right-click on the filtered file "Raw|band|notch" > Import in database:

  • Check "Use events" and select "2", this is the name that brainstorm assigns for the stimulus onset, it may have different name on your computer. Set epoch time: [-100, 200] ms and Apply SSP/ICA in order to apply the average reference.

    importEpochs.jpg

  • At the end, you are asked whether you want to ignore one epoch that is shorter than the others. This happens because the acquisition of the MEG signals was stopped less than 300ms after the last stimulus trigger was sent. Therefore, the last epoch cannot have the full [-100,200]ms time definition. This shorter epoch would prevent us from averaging all the trials easily. As we already have enough repetitions in this experiment (240), we can just ignore it. The total number of epochs is then 239.

Averaging

  • Drag and drop all the Trigger01 trials to the Process1 tab.
  • Run the process Average > Average files: By trial group (folder average)

    [ATTACH]

  • Review the average for the MEG and EEG as a topography plot: Right-click on the averaged signal > EEG > 2D disc, repeat for MEG.

    megEegTopography.jpg

  • At the selected time (21ms), an ERP is visible with a nice dipolar pattern on the sensors, both for the EEG and MEG.

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

  • Go back to the "Functional data" view
  • Right-click on the channel file (folder with imported epochs) > Compute head model

  • Select EEG only > DUNEuro FEM, and set the comment to "DUNEuro FEM EEG DTI tensors"

  • On the DUNEuro options panel: click on "Show details" and set the options as illustrated below
  • Click OK. Depending on the performance of your computer, the FEM EEG head modeling can last between 30min to 3hrs. Once the computation is done, a new node with the name "DUNEuro FEM EEG DTI tensors" appears in the Brainstorm database navigator, which can be used for the source localization process.

    eegDuneuroPanels.jpg

MEG with DTI tensors

  • Right-click on the channel file > Compute head model

  • Select MEG only > DUNEuro FEM, and set the comment to "DUNEuro FEM MEG DTI tensors"

  • On the DUNEuro options panel: click on "Show details" and set the options as illustrated below. To reduce the computation time, we select only the inner layers (white, gray and CSF).
  • Click OK. Depending on the performance of your computer, the FEM MEG head modeling can last between 1hr to 4hrs. Once the computation is done, a new node with the name "DUNEuro FEM MEG DTI tensors" appears in the Brainstorm database navigator, which can be used for the source localization process.

    megDuneuroPanelsDTI.jpg

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.

  • First you need to make sure that the tensors are not computed. If you have the tensors already computed, you need to clear these values. Go to the "Anatomy" view, right-click on the FEM mesh > Clear FEM tensors.

  • Go back to "Functional data", right-click on channel file > Compute head model. In this case, you can change the isotropic conductivity for each tissue. Set the options as in the figure below.

    eegDuneuroPanelsIso.jpg

MEG with isotropic conductivity

  • Same as before, first you need to make sure that the tensors are not computed.
  • Right-click on the channel file > Compute head model, and set the value as in the figure below. In this example keep only the inner tissues (white, gray and CSF).

    megDuneuroPanelsIso.jpg

Source estimation

Noise covariance matrix

  • We will use the baseline of the single epochs to calculate the noise covariance matrix.
  • Right-click on the epochs group > Noise covariance > Compute from recordings. Enter the same baseline interval we used for removing the DC offset: [-100, -10] ms

    noiseCovariance.jpg

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.

  • Repeat the same step for each of the four forward models (EEG/MEG, DTI/isotropic):
  • Right-click on the head model > Compute sources > Dipole modeling.

  • Edit the comment to be able to identify the source maps easily: EEG FEM DTI, EEG FEM ISO, MEG FEM DTI, MEG FEM ISO.

    computeDipolesInverseAll.jpg

  • For each forward model, this operation creates a shared inversion kernel and one source link for each block of recordings in the folder.

    [ATTACH]

Dipole scanning

  • Drag and drop the source links for the average in the Process1 tab.
  • Run the process: Sources > Dipole Scanning > 40ms-60ms. See the Dipole scanning tutorial.

    dipoleScanningProcess.jpg

  • Select and merge the MEG ISO and the MEG DTI dipoles. Repeat for the EEG dipoles.
  • Rename the merged dipoles with a clearer comment, as illustrated below.

    dipolesMergeEEG&MEG.jpg

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.

  • Right-click on the channel file > Compute head model > MEG: Overlapping spheres

  • Right-click on the channel file > Compute head model > EEG: OpenMEEG BEM

  • Repeat the same source localization procedure: Compute sources and Dipole scanning.

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

Related tutorials

  • Realistic head model: FEM with DUNEuro

  • FEM mesh generation

  • FEM tensors estimation

Articles

  • Medani T, Garcia-Prieto J, Tadel F, Schrader S, Joshi A, Engwer C, Wolters CH, Mosher JC, Leahy RM, Realistic head modeling of electromagnetic brain activity: An integrated Brainstorm pipeline from MRI data to the FEM solution (preprint), SPIE Medical Imaging, Feb 2021

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):


  • MoinMoin Powered
  • Python Powered
  • GPL licensed
  • Valid HTML 4.01