ECoG/sEEG tutorial

Authors: Francois Tadel, Marcel Heers, Raymundo Cassani.

This tutorial introduces some concepts that are specific to the management of intracranial, ECoG/sEEG recordings in the Brainstorm environment. It is based on a clinical case from the Epilepsy Center at the University Hospital of Freiburg, Germany.

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.

NOT FOR CLINICAL USE:
The performance characteristics of the methods and software implentation presented in this tutorial have not been certified as medical devices and should be used for research purposes only.

Dataset description

License

This tutorial dataset (EEG and MRI data) remains proprietary of the Epilepsy Centre, University Hospital Freiburg, Germany. Its use and transfer outside the Brainstorm tutorial, e.g. for research purposes, is prohibited without written consent from the Epilepsy Centre in Freiburg. For questions please contact A. Schulze-Bonhage, MD, PhD: andreas.schulze-bonhage@uniklinik-freiburg.de

Acknowledgements

We would like to thank the patient for providing his dataset for this tutorial, the clinical team of the Epilepsy Center Freiburg for the aquisition of the dataset and Verena Schulte for her help in preparing the dataset for the tutorial.

Clinical description

The patient is a 38yr male who suffered from drug resistant focal epilepsy since his 13th year of age with two different types of focal aware seizures that rarely evolved at nighttime to bilateral tonic-clonic seizures. Seizure type I consisted of daily aware focal seizures with myoclonic or clonic jerks of the right leg that occasionally led to falls. Type II consisted of formication paraesthesias that propagated from the right calf to the hip region. It could be provoked by stress or hot weather and occurred 2-3 times a week. In the presurgical 3T epilepsy MRI no structural abnormality was detected.

Implantation scheme

After non-invasive telemetry intracranial recordings were performed. It was decided to implant a 64 channels Ad-Tech subdural grid with 8x8 contacts (stainless steel, 10mm between centers of contacts, 2.3mm diameter exposure) over the left fronto-centro-parietal convexity covering the central region. The most inferior lateral row of contacts of the grid electrode is named A and the row of contacts next to the midline is named H. The contacts of the grid have numbers between 1-8 with the most posterior contacts of each row starting with number 1.

Additionally, 3 interhemispheric Ad-Tech strip electrodes with 4 contacts each named from posterior to anterior with IHA being the most posterior followed by IHB and IHC being the most anterior strip electrode. The numbering convention is that the deepest contact is named contact "1": and the most superficial contact of each electrode has the highest number.

In addition, 2 Ad-Tech sEEG electrodes were implanted in the right parietal lobe facing to the insula (TA & TB, distance between centers of contacts: 10mm, diameter: 0.86mm). Both sEEG electrodes have 10 electrode contacts each. The contacts are counted from anterior to posterior starting with contact number 1 at the tip of each sEEG electrode.

The figure illustrating the electrode positions was created as reported by Kovalev et al. 2005.

epos_scheme_1.gif epos_scheme_2.gif epos_scheme_3.gif

Recordings

The EEG data distributed here was recorded at 1024Hz, using a Neurofile NT digital video-EEG system with 128 channels and a 16-bit A/D converter. The signal was filtered in the recording system with a high-pass filter with a time constant of 1 second (cut-off frequency ~ 0.16Hz) and a low-pass filter with a cut-off frequency of 344 Hz.

Clinical evaluation

Interictal findings:

  • Repetitive sharp waves and interictal fast epileptic activity in the gamma frequency band (FEA; for advanced spectral analysis of FEA see also (Heers et al., 2018)) was almost continuously recorded in contacts G5-6 extending towards H5-6 or F5-6 and less frequently expanding to H3-4 & 7, IHA1-3, IHB1-3

Ictal findings:

  • Seizure onset pattern: Repetitive gamma bursts interrupted by sharp slow waves in G5-6, H3-4 and IHA1-3
  • Semiology: Myoclonic and clonic movements of the right leg intermingled with not clearly localizing habitual formication paraesthesias of the right leg

Electrical stimulation:

  • Stimulation of contacts G5: habitual myoclonic seizures
  • Stimulation of contact G6: habitual paraesthesias of the right leg
  • Detailed function mapping was performed, which is not reported in detail here.

Resection, histopathology and postsurgical outcome:

  • Resection of the posterior part of the superior frontal gyrus anterior of the precentral gyrus including the cingulate gyrus was performed. Because there was overlap between the primary motor cortex (confirmed by functional mapping) at contact H3 position H3, which was also involved in the seizure onset zone this brain area was spared and only multiple subpial transections were added here.
  • Histological examination revealed focal cortical dysplasia type Ib (Palmini et al., 2004). After surgery the patient developed a severe SMA syndrome with diminished activity, problems in movement initiation and speech production from which he recovered completely after rehabilitation.
  • After surgery the patient remained completely seizure free (Engel IA outcome, follow up 10 years).

sub-ecog01_ses-postimp_acq-render01_photo.png sub-ecog01_ses-postimp_acq-render02_photo.png

References

Heers M, Helias M, Hedrich T, Dümpelmann M, Schulze-Bonhage A, Ball T (2018): Spectral bandwidth of interictal fast epileptic activity characterizes the seizure onset zone. NeuroImage Clin 17.

Kovalev D, Spreer J, Honegger J, Zentner J, Schulze‐Bonhage A, Huppertz HJ (2005): Rapid and fully automated visualization of subdural electrodes in the presurgical evaluation of epilepsy patients. AJNR Am J Neuroradiol 26:1078–1083.

Palmini A, Najm I, Avanzini G, Babb T, Guerrini R, Foldvary-Schaefer N, Jackson G, Luders HO, Prayson R, Spreafico R, Vinters H V (2004): Terminology and classification of the cortical dysplasias. Neurology 62:S2-8.

Files

The dataset we distribute with this tutorial follows the Brain Imaging Data Structure (BIDS) standard for neuroimaging data organization. This specification was first established for MRI and fMRI (Gorgolewski, 2016) and then refined with an extension dedicated to iEEG (Holdgraf, 2019). The files that will be imported in this tutorial are the following:

sample_ecog/

  • derivatives/: Everything that cannot be considered as raw data

    • freesurfer/sub-ecog01_ses-preimp/: Result of the FreeSurfer 7.1.1 segmentation for subject ecog01 (T1 pre-implantation)

  • sub-ecog01/: Raw data for subject ecog01

    • ses-preimp/: Imaging exams performed before the implantation of the ECoG/sEEG.

      • anat/sub-ecog01_ses-preimp_T1w.nii.gz: T1-weighted MRI pre-implantation

    • ses-postimp/: Exams performed with the sEEG/ECoG devices implanted.

      • anat/sub-ecog01_ses-postimp_T1w.nii.gz: T1-weighted MRI post-implantation

      • ieeg/..._task-seizure_run-01_ieeg.eeg: 1 hour ECoG+sEEG recordings with 3 seizures (saved using the BrainVision file format, with the header files .vhdr and .vmrk)

      • ieeg/..._space-IXI549Space_electrodes.tsv: Position of the contacts in MNI space (SPM12 Segment non-linear normalization)

      • ieeg/..._space-other_electrodes.tsv: Position of the contacts in world coordinates

  • All the anatomical images have been de-identified with mri_deface from FreeSurfer 6.

Download and installation

Import the anatomy

The entire dataset, anatomy and recordings, is organized following the BIDS specification. It could be loaded automatically with the menu Import BIDS dataset, as illustrated in the Resting/OMEGA tutorial. However, in this tutorial we will detail the step-by-step instructions to load the anatomy and ECoG recordings manually.

Pre-implantation MRI

The pre-implantation T1 MRI is available as a .nii file (sample_ecog/sub-ecog01/ses-postimp/anat). This volume was processed with FreeSurfer 7.1.1, and the output segmentation is available in the derivatives folder (sample_ecog/derivatives/freesurfer/sub-ecog01_ses-preimp). We don't need to import both to the Brainstorm database: in order to minimize the number of operations, we will import only the FreeSurfer folder.

Post-implantation MRI

Generate skull surfaces

Access the recordings

Edit the channel types

At the previous step, we explicitly defined that we were importing ECoG recordings. However, this file contains both sEEG and ECoG recordings, therefore we need to modify manually the type of some channels.

Edit the contacts positions

For 3D mapping and to generate epileptogenicity maps, we need accurate 3D positions for the contacts of the grids and sEEG electrodes. Placing the contacts requires a good understanding of the implantation scheme reported by the neurosurgeon, and some skills in reading MRI scans. This tutorial will now explain how to do this manual marking with the MRI Viewer from the post-implantation MRI, which shows clear hyposignal artifacts around the ECoG and sEEG contacts. We prefer using the non-resliced volume because it offers a clearer view of these artifacts.

If you have no interest in this or if you want to skip faster to the analysis of the signals, you can load the 3D positions from the BIDS dataset: read the advanced section Read BIDS electrodes.tsv.

ECoG grid: G

ECoG strips: IHA, IHB, IHC

IHA

IHB

IHC

sEEG electrodes: TA, TB

TA

TB

3D display

Project on brain surface

You probably noticed that many the contacts of the ECoG grid appear under the surface of the cortex in these 3D figures. This is mostly due to the brain shift between the volumes we used to mark the contacts (post-implantation MRI) and the volume from which the cortex surface was reconstructed (pre-implantation MRI). One solution to compensate for this brain shift and produce more readable figures is to project the contacts on the pre-implantation surfaces.

Advanced

Alternative: Read BIDS electrodes.tsv

A BIDS dataset may contain information about the localization of the iEEG contacts in different systems of coordinates. These files are documented in the in BIDS specification. In this dataset, we can find the following files in the folder sample_ecog/sub-ecog01/ses-postimp/ieeg. Files

The tag space- indicates how the coordinates should be interpreted (list of possible values):

For the subject space (space-ScanRAS), the contents of the json file is the following:

 "iEEGCoordinateSystem": "ScanRAS",
 "iEEGCoordinateUnits": "mm",
 "iEEGCoordinateSystemDescription": "Scanner RAS coordinates of post-implantation T1 MRI",
 "iEEGCoordinateProcessingDescription": "Contacts placed with Brainstorm on post-imp MRI",
 "iEEGCoordinateProcessingReference": "https://neuroimage.usc.edu/brainstorm/Tutorials/ECoG",
 "IntendedFor": "sub-ecog01/ses-postimp/anat/sub-ecog01_ses-postimp_T1w.nii.gz"

The field IntendedFor points at the file sub-ecog01_ses-postimp_T1w.nii.gz. This means that the coordinates in the files sub-ecog01_ses-postimp_space-ScanRAS_electrodes.tsv refer to the post-implantation T1 MRI.

To add the coordinates in subject space (be careful: if you already marked the contacts manually, you would lose all your work - if you want to try this, duplicate the subject first):

Note that the electrodes.tsv file does not include all the information we defined manually in the previous section (ECOG vs. ECOG-mid, contact diameter...), therefore for optimal display you might need to go through the configuration of each implanted device in the iEEG tab and edit the values as previously.

Advanced

Display the recordings

ECoG/sEEG time series

2D/3D topography

With the menus 2DLayout, 2D Electrodes and 3D Electrodes you can visualize the ECoG/sEEG values at the current time point. Move the time cursor and it will update the values represented on the contacts.

review_topo.gif

Interpolate on the anatomy

From the same ECOG+SEEG display menu, you can also project the recordings on the MRI or the cortex. You can edit the colormap for the displayed values like any other colormap.

MRI volume: All the voxels in the neighborhood of a contact are attributed the value associated with this contact. In the figure below, both "MIP: functional" and "MIP: anatomy" options are selected (maximum intensity projection along each axis = "glass brain" view).

Cortex surface: The values of the vertices are interpolated from the nearest ECOG/SEEG contacts (the magnitude decreases with the distance to the contact). To adjust the maximum distance between a contact and a painted vertex, right-click on the figure > Channel > Edit interpolation distance.

review_interp.gif

Power spectrum

We recommend you always start your data analysis with a spectral evalution of the recordings, it may help you identify bad channels. This is described in tutorials Power spectrum and EEG and epilepsy.

Import epochs of interest

At this point of the analysis, we are still looking at the original files, no data was copied to the database. The montages are saved in the Brainstorm preferences, the bad channels and new events are saved in the links of the database but not reported to the original files. If you delete your protocol at this point, you would only lose the event marking and bad channel selection.

We are now going to import a segment a recordings around each of the three seizures marked in this file (10s before and 20s after the onset). This will make real copies of the data in the database, so we can run additional processes on them.

Anatomical labelling

As illustrated in the introduction tutorial Explore the anatomy, all the anatomical atlases available in the subject (e.g. DKT, Desikan-Killiany, Destrieux) are available in the MRI Viewer. Select the current atlas from the figure popup menu, and the anatomical label under the cursor is displayed at the top-right corner. You can overlay all the labels on the MRI with the menu Show atlas.

volatlas.gif

We can use these anatomical parcellations, and also the surface parcellations of the cortex available as scouts, in order to label automatically all the ECOG/SEEG contacts.

If accurate MNI coordinates are expected, it is recommended to use a non-linear MNI normalization instead of the initial linear registration computed at the beginning of this tutorial, as illustrated in the SEEG epileptogenicity tutorial. In the anatomy view, right-click on the pre-implantation MRI (first file in the subject anatomy) > MNI normalization > Segment. This requires SPM12.

Switch to the functional view. Right-click on the channel file > iEEG atlas labels > Select all the available options: XYZ coordinates in various coordinate systems, volume parcellations, surface parcellations.

labelling1.gif

When using surface atlases, select preferencially the high-resolution surfaces (~300000V): a higher density of labelled points on the surface will increase the chances to label correctly the contacts. Selecting the type of surface ("white", "mid" or "cortex") depends on multiple factors, and we don't have enough experience yet to give clear recommendations. To help you decide, here is what these labels mean:

labelling2.gif

labelling3.gif

More options and details in the tutorial SEEG epileptogenicity maps.

Scripting

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

1 function tutorial_ecog(tutorial_dir, reports_dir) 2 % TUTORIAL_ECOG: Script that runs ECoG/sEEG tutorial 3 % https://neuroimage.usc.edu/brainstorm/Tutorials/ECoG 4 % 5 % INPUTS: 6 % - tutorial_dir : Directory where the sample_ecog.zip file has been unzipped 7 % - reports_dir : Directory where to save the execution report (instead of displaying it) 8 9 % @============================================================================= 10 % This function is part of the Brainstorm software: 11 % https://neuroimage.usc.edu/brainstorm 12 % 13 % Copyright (c) University of Southern California & McGill University 14 % This software is distributed under the terms of the GNU General Public License 15 % as published by the Free Software Foundation. Further details on the GPLv3 16 % license can be found at http://www.gnu.org/copyleft/gpl.html. 17 % 18 % FOR RESEARCH PURPOSES ONLY. THE SOFTWARE IS PROVIDED "AS IS," AND THE 19 % UNIVERSITY OF SOUTHERN CALIFORNIA AND ITS COLLABORATORS DO NOT MAKE ANY 20 % WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF 21 % MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, NOR DO THEY ASSUME ANY 22 % LIABILITY OR RESPONSIBILITY FOR THE USE OF THIS SOFTWARE. 23 % 24 % For more information type "brainstorm license" at command prompt. 25 % =============================================================================@ 26 % 27 % Author: Raymundo Cassani, 2025 28 29 30 % Output folder for reports 31 if (nargin < 2) || isempty(reports_dir) || ~isdir(reports_dir) 32 reports_dir = []; 33 end 34 % You have to specify the folder in which the tutorial dataset is unzipped 35 if (nargin == 0) || isempty(tutorial_dir) || ~file_exist(tutorial_dir) 36 error('The first argument must be the full path to the dataset folder.'); 37 end 38 39 %% ===== FILES TO IMPORT ===== 40 % Subject name 41 SubjectName = 'ecog01'; 42 % Build the path of the files to import 43 AnatDir = fullfile(tutorial_dir, 'sample_ecog', 'derivatives', 'freesurfer', 'sub-ecog01_ses-preimp'); 44 PostMri = fullfile(tutorial_dir, 'sample_ecog', 'sub-ecog01', 'ses-postimp', 'anat', 'sub-ecog01_ses-postimp_T1w.nii.gz'); 45 EegRawFile = fullfile(tutorial_dir, 'sample_ecog', 'sub-ecog01', 'ses-postimp', 'ieeg', 'sub-ecog01_ses-postimp_task-seizure_run-01_ieeg.eeg'); 46 EegLocFile = fullfile(tutorial_dir, 'sample_ecog', 'sub-ecog01', 'ses-postimp', 'ieeg', 'sub-ecog01_ses-postimp_space-ScanRAS_electrodes.tsv'); 47 % Check if the folder contains the required files 48 if ~file_exist(EegRawFile) 49 error(['The folder ' tutorial_dir ' does not contain the folder from the file sample_ecog.zip.']); 50 end 51 52 53 %% ===== 01: CREATE PROTOCOL =================================================== 54 % ============================================================================= 55 disp([10 'DEMO> 01: Create protocol' 10]); 56 % The protocol name has to be a valid folder name (no spaces, no weird characters...) 57 ProtocolName = 'TutorialEcog'; 58 % Start brainstorm with GUI 59 if ~brainstorm('status') 60 brainstorm 61 end 62 % Delete existing protocol 63 gui_brainstorm('DeleteProtocol', ProtocolName); 64 % Create new protocol 65 gui_brainstorm('CreateProtocol', ProtocolName, 0, 0); 66 % Start a new report 67 bst_report('Start'); 68 % Reset colormaps 69 bst_colormaps('RestoreDefaults', 'eeg'); 70 71 72 %% ===== 02: IMPORT ANATOMY ==================================================== 73 % ============================================================================= 74 disp([10 'DEMO> 02: Import anatomy' 10]); 75 76 % === Pre-implantation MRI === 77 % Process: Import FreeSurfer folder 78 bst_process('CallProcess', 'process_import_anatomy', [], [], ... 79 'subjectname', SubjectName, ... 80 'mrifile', {AnatDir, 'FreeSurfer'}, ... 81 'nvertices', 15000); 82 % Rename reference MRI 83 [sSubject, iSubject] = bst_get('Subject', SubjectName); 84 file_update(file_fullpath(sSubject.Anatomy(sSubject.iAnatomy).FileName), 'Field', 'Comment', 'T1pre'); 85 db_reload_subjects(iSubject); 86 87 % === Post-implantation MRI === 88 % Process: Import MRI 89 bst_process('CallProcess', 'process_import_mri', [], [], ... 90 'subjectname', SubjectName, ... 91 'mrifile', {PostMri, 'Nifti1'}); 92 sSubject = bst_get('Subject', SubjectName); 93 iAnatPost = length(sSubject.Anatomy); 94 file_update(file_fullpath(sSubject.Anatomy(iAnatPost).FileName), 'Field', 'Comment', 'T1post'); 95 db_reload_subjects(iSubject); 96 97 % === Coregister and reslice post-implantation with pre-implantation === 98 % Coregister (without reslicing) 99 MriPostReg = mri_coregister(sSubject.Anatomy(iAnatPost).FileName, [], 'SPM', 0); 100 % Delete post-implantation (without coregistration) 101 file_delete(file_fullpath(sSubject.Anatomy(iAnatPost).FileName), 1); 102 db_reload_subjects(iSubject); 103 sSubject = bst_get('Subject', SubjectName); 104 % Reslice coregisted post-implantation MRI with world coordinates 105 iAnatPostReg = find(strcmp(MriPostReg, {sSubject.Anatomy.FileName})); 106 MriPostRegReslice = mri_reslice(sSubject.Anatomy(iAnatPostReg).FileName, [], 'vox2ras', 'vox2ras'); 107 % Figure: Overlay T1post_spm_reslice on T1pre 108 hFig = view_mri(sSubject.Anatomy(sSubject.iAnatomy).FileName, MriPostRegReslice); 109 % Amplitude to 20% 110 panel_surface('SetDataThreshold', hFig, 1, 0.2); 111 bst_report('Snapshot', hFig, '', 'Coregistration T1pre on T1post_spm_reslice'); 112 pause(0.5); 113 close(hFig); 114 115 % === Generate BEM surfaces === 116 % Process: Generate BEM surfaces 117 bst_process('CallProcess', 'process_generate_bem', [], [], ... 118 'subjectname', SubjectName, ... 119 'nscalp', 1922, ... 120 'nouter', 1922, ... 121 'ninner', 1922, ... 122 'thickness', 4, ... 123 'method', 'brainstorm'); % Brainstorm 124 % Set default head surface and update Subject node 125 [sSubject, iSubject] = bst_get('Subject', SubjectName); 126 iScalp = find(strcmp('head mask (10000,0,2,18)', {sSubject.Surface.Comment})); 127 db_surface_default(iSubject, 'Scalp', iScalp, 1); 128 panel_protocols('UpdateNode', 'Subject', iSubject); 129 % Figure: BEM surfaces 130 hFig = view_surface(sSubject.Surface(sSubject.iScalp).FileName); 131 view_surface(sSubject.Surface(sSubject.iOuterSkull).FileName); 132 view_surface(sSubject.Surface(sSubject.iInnerSkull).FileName); 133 view_surface(sSubject.Surface(sSubject.iCortex).FileName); 134 iTess = 3; % InnerSkull 135 panel_surface('SetShowSulci', hFig, iTess, 1); 136 panel_surface('SetSurfaceColor', hFig, iTess, [1 0 0]); 137 figure_3d('SetStandardView', hFig, 'left'); 138 pause(0.5); 139 bst_report('Snapshot', hFig, '', 'BEM surfaces and Cortex'); 140 close(hFig); 141 142 143 %% ===== 03: ACCESS THE RECORDINGS ============================================== 144 % ============================================================================= 145 disp([10 'DEMO> 03: Access the recordings' 10]); 146 % === Link the recordings === 147 % Process: Create link to raw files 148 sFileRaw = bst_process('CallProcess', 'process_import_data_raw', [], [], ... 149 'subjectname', SubjectName, ... 150 'datafile', {EegRawFile, 'ECOG-ALL'}); 151 152 % === Edit channel and intracranial electrodes in channel file === 153 sChannelMat = in_bst_channel(sFileRaw.ChannelFile); 154 % ECOG grid 'G' 155 iIntraElec = find(strcmp('G', {sChannelMat.IntraElectrodes.Name})); 156 sChannelMat.IntraElectrodes(iIntraElec).Type = 'ECOG'; 157 sChannelMat.IntraElectrodes(iIntraElec).ContactNumber = [8 8]; 158 sChannelMat.IntraElectrodes(iIntraElec).ContactSpacing = 0.01; % 10 mm 159 sChannelMat.IntraElectrodes(iIntraElec).ContactLength = 0.001; % 1 mm 160 sChannelMat.IntraElectrodes(iIntraElec).ContactDiameter = 0.004; % 4 mm 161 % ECOG strips 'IHA', 'IHB' and 'IHC' 162 [~, iIntraElec] = ismember({'IHA', 'IHB', 'IHC'}, {sChannelMat.IntraElectrodes.Name}); 163 [sChannelMat.IntraElectrodes(iIntraElec).Type] = deal('ECOG-mid'); 164 [sChannelMat.IntraElectrodes(iIntraElec).ContactNumber] = deal(4); 165 [sChannelMat.IntraElectrodes(iIntraElec).ContactSpacing] = deal(0.01); % 10 mm 166 [sChannelMat.IntraElectrodes(iIntraElec).ContactLength] = deal(0.001); % 1 mm 167 [sChannelMat.IntraElectrodes(iIntraElec).ContactDiameter] = deal(0.004); % 4 mm 168 % SEEG electrodes 'TA' and 'TB' 169 % Change groups TA and TB to be type SEEG 170 iChSeeg = find(strcmp('TA', {sChannelMat.Channel.Group}) | strcmp('TB', {sChannelMat.Channel.Group})); 171 [sChannelMat.Channel(iChSeeg).Type] = deal('SEEG'); 172 [~, iIntraElec] = ismember({'TA', 'TB'}, {sChannelMat.IntraElectrodes.Name}); 173 [sChannelMat.IntraElectrodes(iIntraElec).Type] = deal('SEEG'); 174 [sChannelMat.IntraElectrodes(iIntraElec).ContactNumber] = deal(10); 175 [sChannelMat.IntraElectrodes(iIntraElec).ContactSpacing] = deal(0.01); % 10.0 mm 176 [sChannelMat.IntraElectrodes(iIntraElec).ContactLength] = deal(0.0025); % 2.5 mm 177 [sChannelMat.IntraElectrodes(iIntraElec).ContactDiameter] = deal(0.001); % 1.0 mm 178 [sChannelMat.IntraElectrodes(iIntraElec).ElecDiameter] = deal(0.0009); % 0.9 mm 179 [sChannelMat.IntraElectrodes(iIntraElec).ElecLength] = deal(0.120); % 120.0 mm 180 % Save modified channel file 181 bst_save(file_fullpath(sFileRaw.ChannelFile), sChannelMat); 182 % === Edit the contacts positions === 183 % Process: Add EEG positions 184 bst_process('CallProcess', 'process_channel_addloc', sFileRaw, [], ... 185 'channelfile', {EegLocFile, 'BIDS-SCANRAS-MM'}, ... 186 'usedefault', '', ... 187 'fixunits', 1, ... 188 'vox2ras', 1, ... 189 'mrifile', {MriPostReg, 'BST'}, ... 190 'fiducials', []); 191 % Plot electrodes and open iEEG panel 192 [hFig, iDS, iFig] = view_channels_3d(sFileRaw.ChannelFile, 'ECOG+SEEG', 'cortex', 1); 193 bst_report('Snapshot', hFig, sFileRaw.ChannelFile, 'Before projecting ECOG grid on innerskull: ECOG'); 194 % Project ECOG grid 'G' on innerskull surface 195 panel_ieeg('SetSelectedElectrodes', 'G'); 196 panel_ieeg('ProjectContacts', iDS, iFig, 'innerskull'); 197 bst_report('Snapshot', hFig, sFileRaw.ChannelFile, 'After projecting ECOG grid on innerskull: ECOG'); 198 bst_memory('SaveChannelFile', iDS); 199 bst_memory('UnloadAll', 'Forced'); 200 201 202 %% ===== 04: DISPLAY THE RECORDINGS ============================================ 203 % ============================================================================= 204 disp([10 'DEMO> 04: Display the recordings' 10]); 205 % ECoG/sEEG time series 206 hFig = view_timeseries(sFileRaw.FileName, 'ECOG+SEEG'); 207 % Set the current display mode to 'column' 208 bst_set('TSDisplayMode', 'column'); 209 panel_record('SetTimeLength', 20); 210 panel_record('SetStartTime', 888); 211 panel_montage('SetCurrentMontage', hFig, 'ecog01: ECOG_SEEG (bipolar 1)[tmp]'); 212 pause(0.5); 213 bst_report('Snapshot', hFig, sFileRaw.FileName, 'Time series: ECOG+SEEG'); 214 close(hFig); 215 216 % 2D Layout 217 hFig2dL = view_topography(sFileRaw.FileName, 'ECOG+SEEG', '2DLayout'); 218 panel_record('SetTimeLength', 2); 219 panel_record('SetStartTime', 888); 220 panel_time('SetCurrentTime', 889.6); 221 222 % 2D electrodes 223 hFig2dE = view_topography(sFileRaw.FileName, 'ECOG+SEEG', '2DElectrodes'); 224 225 % 3D electrodes (MRI) 226 hFig3dE = view_topography(sFileRaw.FileName, 'ECOG+SEEG', '3DElectrodes-MRI'); 227 228 % Project activity on cortex 229 sSubject = bst_get('Subject', SubjectName); 230 hFigCtx = view_surface_data(sSubject.Surface(sSubject.iCortex).FileName, sFileRaw.FileName, 'ECOG+SEEG'); 231 % Project activity on MRI 232 % Set Maximum intensity projection (MIP) for projected data) 233 MriOptions = bst_get('MriOptions'); 234 MriOptions.isMipFunctional = 1; 235 bst_set('MriOptions', MriOptions); 236 hFigMri = view_mri(sSubject.Anatomy(sSubject.iAnatomy).FileName, sFileRaw.FileName, 'ECOG+SEEG'); 237 238 % Set colormap max to 'local' and range [-max,max] 239 ColormapInfo = getappdata(hFigCtx, 'Colormap'); 240 bst_colormaps('SetMaxMode', ColormapInfo.Type, 'local', []); 241 bst_colormaps('SetColormapRealMin', ColormapInfo.Type, 0); 242 243 pause(0.5); 244 bst_report('Snapshot', hFig2dL, sFileRaw.FileName, '2D Layout: ECOG+SEEG'); 245 bst_report('Snapshot', hFig2dE, sFileRaw.FileName, '2D Electrodes: ECOG+SEEG'); 246 bst_report('Snapshot', hFig3dE, sFileRaw.FileName, '3D Electrodes: ECOG+SEEG'); 247 bst_report('Snapshot', hFigCtx, sFileRaw.FileName, 'Interpolate on cortex: ECOG+SEEG'); 248 bst_report('Snapshot', hFigMri, sFileRaw.FileName, 'Interpolate on MRI: ECOG+SEEG'); 249 close([hFig2dL, hFig2dE, hFig3dE, hFigCtx, hFigMri]); 250 MriOptions.isMipFunctional = 0; 251 bst_set('MriOptions', MriOptions); 252 253 % Process: Power spectrum density (Welch) 254 sFilePsd = bst_process('CallProcess', 'process_psd', sFileRaw, [], ... 255 'timewindow', [], ... 256 'win_length', 10, ... 257 'win_overlap', 50, ... 258 'units', 'physical', ... % Physical: U2/Hz 259 'sensortypes', 'ECOG, SEEG', ... 260 'win_std', 0, ... 261 'edit', struct(... 262 'Comment', 'Power', ... 263 'TimeBands', [], ... 264 'Freqs', [], ... 265 'ClusterFuncTime', 'none', ... 266 'Measure', 'power', ... 267 'Output', 'all', ... 268 'SaveKernel', 0)); 269 % Spectrum figure 270 hFig = view_spectrum(sFilePsd.FileName); 271 sOptions = panel_display('GetDisplayOptions'); 272 sOptions.Function = 'log'; 273 panel_display('SetDisplayOptions', sOptions); 274 xlim(gca, [0, 40]); 275 pause(0.5); 276 bst_report('Snapshot', hFig, sFilePsd.FileName, 'Power spectrum (log): ECOG+SEEG'); 277 close(hFig); 278 279 280 %% ===== 05: IMPORT EPOCHS ===================================================== 281 % ============================================================================= 282 disp([10 'DEMO> 05: Import epochs' 10]); 283 % Process: Import MEG/EEG: Events 284 sFilesEpochs = bst_process('CallProcess', 'process_import_data_event', sFileRaw, [], ... 285 'subjectname', SubjectName, ... 286 'condition', '', ... 287 'eventname', 'seizure', ... 288 'timewindow', [], ... 289 'epochtime', [-10, 20], ... 290 'createcond', 0, ... 291 'ignoreshort', 1, ... 292 'usectfcomp', 1, ... 293 'usessp', 1, ... 294 'freq', [], ... 295 'baseline', []); 296 % TB SEEG electrode time series 297 hFig = view_timeseries(sFilesEpochs(1).FileName, 'ECOG+SEEG'); 298 % Set the current display mode to 'column' 299 bst_set('TSDisplayMode', 'column'); 300 panel_montage('SetCurrentMontage', hFig, 'ecog01: TB (bipolar 2)[tmp]'); 301 pause(0.5); 302 bst_report('Snapshot', hFig, sFileRaw.FileName, 'Time series: electrode TB'); 303 close(hFig); 304 305 306 %% ===== 06: ANATOMICAL LABELLING ============================================== 307 % ============================================================================= 308 disp([10 'DEMO> 06: Anatomical labelling' 10]); 309 TsvFile = bst_fullfile(fileparts(file_fullpath(sFileRaw.FileName)), 'anatomical_labelling.tsv'); 310 export_channel_atlas(sFileRaw.ChannelFile, 'ECOG+SEEG', TsvFile, 3, 1, 0); 311 % View TSV file 312 T = readtable(TsvFile, 'FileType', 'text', 'Delimiter', '\t', 'ReadVariableNames', true); 313 jFrame = view_table(table2cell(T), T.Properties.VariableNames, 'sFileRaw.ChannelFile'); 314 bst_report('Snapshot', jFrame, sFileRaw.ChannelFile, 'Anatomical labelling: ECOG+SEEG'); 315 jFrame.dispose(); 316 317 318 %% ===== SAVE REPORT ===== 319 % Save and display report 320 ReportFile = bst_report('Save', []); 321 if ~isempty(reports_dir) && ~isempty(ReportFile) 322 bst_report('Export', ReportFile, reports_dir); 323 else 324 bst_report('Open', ReportFile); 325 end 326 disp([10 'DEMO> Done.' 10]); 327





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


Advanced

Additional documentation

Forum

Tutorials/ECoG (last edited 2025-08-05 17:12:08 by RaymundoCassani)