High Gamma Filter

Below is a code sample for extracting high gamma power from a raw data file

from ieeg.navigate import channel_outlier_marker, trial_ieeg
from ieeg.io import raw_from_layout
from ieeg.calc.scaling import rescale
from ieeg.timefreq.utils import crop_pad
from ieeg.timefreq import gamma
from bids import BIDSLayout
import mne

Load Data

bids_root = mne.datasets.epilepsy_ecog.data_path()
layout = BIDSLayout(bids_root)
raw = raw_from_layout(layout,
                      subject="pt1",
                      preload=True,
                      extension=".vhdr")
Extracting parameters from /home/docs/mne_data/MNE-epilepsy-ecog-data/sub-pt1/ses-presurgery/ieeg/sub-pt1_ses-presurgery_task-ictal_ieeg.vhdr...
Setting channel info structure...
Reading events from /home/docs/mne_data/MNE-epilepsy-ecog-data/sub-pt1/ses-presurgery/ieeg/sub-pt1_ses-presurgery_task-ictal_events.tsv.
Reading channel info from /home/docs/mne_data/MNE-epilepsy-ecog-data/sub-pt1/ses-presurgery/ieeg/sub-pt1_ses-presurgery_task-ictal_channels.tsv.
Reading electrode coords from /home/docs/mne_data/MNE-epilepsy-ecog-data/sub-pt1/ses-presurgery/ieeg/sub-pt1_ses-presurgery_space-fsaverage_electrodes.tsv.
/home/docs/checkouts/readthedocs.org/user_builds/ieeg-pipelines/checkouts/latest/ieeg/io.py:283: RuntimeWarning: DigMontage is only a subset of info. There are 3 channel positions not present in the DigMontage. The channels missing from the montage are:

['RQ1', 'RQ2', 'N/A'].

Consider using inst.rename_channels to match the montage nomenclature, or inst.set_channel_types if these are not EEG channels, or use the on_missing parameter if the channel positions are allowed to be unknown in your analyses.
  whole_raw = read_raw_bids(bids_path=BIDS_path, verbose=verbose)
/home/docs/checkouts/readthedocs.org/user_builds/ieeg-pipelines/checkouts/latest/ieeg/io.py:283: RuntimeWarning: Unable to map the following column(s) to to MNE:
outcome: S
engel_score: 1.0
ilae_score: 2.0
date_follow_up: n/a
ethnicity: 0.0
years_follow_up: 3.0
site: NIH
clinical_complexity: 1.0
  whole_raw = read_raw_bids(bids_path=BIDS_path, verbose=verbose)
Reading 0 ... 269079  =      0.000 ...   269.079 secs...

Preprocessing

# Mark channel outliers as bad
channel_outlier_marker(raw, 5)

# Exclude bad channels
raw.drop_channels(raw.info['bads'])
good = raw.copy()
good.load_data()

# Remove intermediates for memory efficiency
del raw

# CAR (common average reference)
good.set_eeg_reference()
outlier round 1 channels: ['N/A']
outlier round 2 channels: ['N/A', 'RQ2']
outlier round 3 channels: ['N/A', 'RQ2', 'AST2']
outlier round 4 channels: ['N/A', 'RQ2', 'AST2', 'AD3']
outlier round 5 channels: ['N/A', 'RQ2', 'AST2', 'AD3', 'PD4']
outlier round 6 channels: ['N/A', 'RQ2', 'AST2', 'AD3', 'PD4', 'G32']
ECoG channel type selected for re-referencing
Applying average reference.
Applying a custom ('ECoG',) reference.
General
Filename(s) sub-pt1_ses-presurgery_task-ictal_ieeg.eeg
MNE object type RawBrainVision
Measurement date 1920-07-24 at 19:35:19 UTC
Participant sub-pt1
Experimenter mne_anonymize
Acquisition
Duration 00:04:30 (HH:MM:SS)
Sampling frequency 1000.00 Hz
Time points 269,080
Channels
misc
ECoG
Head & sensor digitization 86 points
Filters
Highpass 0.00 Hz
Lowpass 500.00 Hz


High Gamma Filter

Extract the epochs of interest

ev1 = trial_ieeg(good,
                 event="AD1-4, ATT1,2",
                 times=(-1, 2),
                 preload=True)
base = trial_ieeg(good,
                  event="onset",
                  times=(-1, 0.5),
                  preload=True)

# extract high gamma power
gamma.extract(ev1,
              copy=False,
              n_jobs=1)
gamma.extract(base,
              copy=False,
              n_jobs=1)

# trim 0.5 seconds on the beginning and end of the data (edge artifacts)
crop_pad(ev1, "500ms")
crop_pad(base, "500ms")
Used Annotations descriptions: [np.str_('AD1-4, ATT1,2'), np.str_('AST1,3'), np.str_('G16'), np.str_('PD'), np.str_('SLT1-3'), np.str_('offset'), np.str_('onset')]
Not setting metadata
1 matching events found
No baseline correction applied
0 projection items activated
Using data from preloaded Raw for 1 events and 3001 original time points ...
0 bad epochs dropped
Used Annotations descriptions: [np.str_('AD1-4, ATT1,2'), np.str_('AST1,3'), np.str_('G16'), np.str_('PD'), np.str_('SLT1-3'), np.str_('offset'), np.str_('onset')]
Not setting metadata
1 matching events found
No baseline correction applied
0 projection items activated
Using data from preloaded Raw for 1 events and 1501 original time points ...
0 bad epochs dropped

  0%|          | 0/1 [00:00<?, ?it/s]
100%|██████████| 1/1 [00:00<00:00, 18.16it/s]

  0%|          | 0/1 [00:00<?, ?it/s]
100%|██████████| 1/1 [00:00<00:00, 40.17it/s]
General
MNE object type Epochs
Measurement date 1920-07-24 at 19:35:19 UTC
Participant sub-pt1
Experimenter mne_anonymize
Acquisition
Total number of events 1
Events counts onset: 1
Time range -0.500 – 0.000 s
Baseline off
Sampling frequency 1000.00 Hz
Time points 501
Metadata No metadata set
Channels
misc
ECoG
Head & sensor digitization 86 points
Filters
Highpass 0.00 Hz
Lowpass 500.00 Hz


Baseline Normalization

Z-score normalize ev1 in-place to save memory

rescale(ev1, base,
        mode='zscore',
        copy=False)
Applying baseline correction (mode: zscore)
General
MNE object type Epochs
Measurement date 1920-07-24 at 19:35:19 UTC
Participant sub-pt1
Experimenter mne_anonymize
Acquisition
Total number of events 1
Events counts AD1-4, ATT1,2: 1
Time range -0.500 – 1.500 s
Baseline off
Sampling frequency 1000.00 Hz
Time points 2,001
Metadata No metadata set
Channels
ECoG
Head & sensor digitization 86 points
Filters
Highpass 0.00 Hz
Lowpass 500.00 Hz


Plotting

ECoG (84 channels)
<Figure size 640x300 with 2 Axes>

Total running time of the script: (0 minutes 3.706 seconds)

Estimated memory usage: 1320 MB

Related examples

PCA-LDA Decoding

PCA-LDA Decoding

Morlet Wavelet spectrogram plot

Morlet Wavelet spectrogram plot

Joint pca decoding

Joint pca decoding

Gallery generated by Sphinx-Gallery