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 2 as of 2023-02-23 09:55:30
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 SimNIBS/CAT12, 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: See tutorial: FEM mesh generation

  • BrainSuite: See tutorial: FEM tensors estimation

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

  • SPM12: Install as Brainstorm plugins

  • CAT12: Install as Brainstorm plugins

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

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 > SimNIBS. 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 mes

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

simnibs.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.m

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





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


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