Skip to main content

A package to read and pre-process Intracranial Electroencephalography (iEEG) data that is structured according to the Brain Imaging Data Structure (BIDS)

Project description

IeegPrep

IeegPrep is a python library to read, pre-process and epoch Intracranial Electroencephalography (iEEG) data that is structured according to the Brain Imaging Data Structure (BIDS)

Install

pip install ieegprep

Usage

After installing, the library can be used directly to:

Read EDF, BrainVision or MEF3 data

from ieegprep import IeegDataReader

# initialize a reader for a specific dataset
reader = IeegDataReader('/bids_data_root/subj-01/ieeg/sub-01_run-06_ieeg.vhdr', preload_data=False)

# print metadata
print(reader.sampling_rate)
print(reader.channel_names)

# retrieve all the data from single channel
channel_data      = reader.retrieve_channel_data('CH05')

# retrieve a range of sample-data from all, a single or multiple channels
range_data_all    = reader.retrieve_sample_range_data(sample_start=1000, sample_end=2000)
range_data_single = reader.retrieve_sample_range_data(sample_start=1000, sample_end=2000, channels='CH01')
range_data_multi  = reader.retrieve_sample_range_data(sample_start=1000, sample_end=2000, channels=('CH01', 'CH05'))

# optionally, close the reader and release the memory
reader.close()

Read BIDS sidecar metadata files

from ieegprep import load_event_info, load_channel_info

channels = load_channel_info('/bids_data_root/subj-01/ieeg/sub-01_run-06_channels.tsv')
events   = load_event_info('/bids_data_root/subj-01/ieeg/sub-01_run-06_events.tsv')

Load, pre-process and epoched data as a matrix

from ieegprep import load_data_epochs

# retrieve epoched data
[srate, epochs] = load_data_epochs( '/bids_data_root/subj-01/ieeg/sub-01_run-06_ieeg.vhdr',
                                    retrieve_channels = channels['name'],
                                    onsets            = events['onset'])
data_ch0_trial13 = epochs[1, 13, :]

# retrieve epoched data specifying the epoch window and baseline normalization
[srate, epochs] = load_data_epochs( '/bids_data_root/subj-01/ieeg/sub-01_run-06_ieeg.vhdr',
                                    retrieve_channels = channels['name'],
                                    onsets            = events['onset'],
                                    trial_epoch       = (-1, 2),                         #  -1s < onset < 2s  
                                    baseline_norm     = 'Median',
                                    baseline_epoch    = (-1, -0.1))
                            
# retrieve epoched data with pre-processing (high-pass filtering, CAR re-referencing and 50Hz line-noise removal)
from ieegprep import RerefStruct
[srate, epochs] = load_data_epochs( '/bids_data_root/subj-01/ieeg/sub-01_run-06_ieeg.vhdr',
                                    retrieve_channels  = channels['name'],
                                    onsets             = events['onset'],
                                    high_pass          = True,
                                    early_reref        = RerefStruct.generate_car(channels['name'].tolist()),
                                    line_noise_removal = 50)

Load, epoch and get the average of each stimulated electrode pair (minimizing memory usage)

from ieegprep import load_data_epochs_averages, load_elec_stim_events

# load the events file and retrieve the different stimulated electrode-pairs (e.g. Ch01-Ch02...) as conditions
_, _, conditions_onsets, _ = load_elec_stim_events('/bids_data_root/subj-01/ieeg/sub-01_run-06_events.tsv')

# retrieve epoch data averaged over conditions
[srate, epochs, _] =  load_data_epochs_averages('/bids_data_root/subj-01/ieeg/sub-01_run-06_ieeg.vhdr',
                                                retrieve_channels = channels['name'],
                                                conditions_onsets = conditions_onsets)
data_respCh01_stimCh02_03 = epochs[1, 4, :]

Acknowledgements

  • Written by Max van den Boom (Multimodal Neuroimaging Lab, Mayo Clinic, Rochester MN)

  • Dependencies:

  • The new EDF and BrainVision readers are in part adaptations of the Fieldtrip code (by Robert Robert Oostenveld) and replicate some of the header logic from the MNE package (by Teon Brooks, Stefan Appelhoff and others)

  • This project was funded by the National Institute Of Mental Health of the National Institutes of Health Award Number R01MH122258 to Dora Hermes

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ieegprep-1.6.0.tar.gz (89.5 kB view details)

Uploaded Source

Built Distribution

ieegprep-1.6.0-py3-none-any.whl (81.8 kB view details)

Uploaded Python 3

File details

Details for the file ieegprep-1.6.0.tar.gz.

File metadata

  • Download URL: ieegprep-1.6.0.tar.gz
  • Upload date:
  • Size: 89.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for ieegprep-1.6.0.tar.gz
Algorithm Hash digest
SHA256 4a7576e3ee1a61ef4d66265d1b51fd30dd6cf8b0291728a9917fdb1134be6c20
MD5 bea2cf97164d571755ad196ab3da5da4
BLAKE2b-256 7a844f6444c957b4b65274fd34ecd3f2aa7d98303b54600aa93cd3f1ff0fee30

See more details on using hashes here.

File details

Details for the file ieegprep-1.6.0-py3-none-any.whl.

File metadata

  • Download URL: ieegprep-1.6.0-py3-none-any.whl
  • Upload date:
  • Size: 81.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for ieegprep-1.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f2a62169084096cdce3b00cafe2c2f27315820490615cf59029f346e9286ce2c
MD5 5a6d574287dc8beab6199ab7642a2d0a
BLAKE2b-256 ed52dce4e437ce86cd60dcd3b2e0d26ef007a32f28a5870cd16ee9a4bf53f3d8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page