Skip to main content

TMS-EEG Evoked Potential Analysis Framework

Project description

PyPI Version Python Version License Open Issues


TEPpy Logo

TEPpy

TMS-EEG Evoked Potential Analysis Framework
Explore the docs »

Report Bug   Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Citation
  5. Contact
  6. Contributing
  7. License

About The Project

TEPpy is a Python package for analyzing Transcranial Magnetic Stimulation combined with Electroencephalography (TMS-EEG) data. It provides tools for characterizing TMS-EEG evoked potential (TEP) temporal and spectral features, with automated peak detection and time-frequency analysis methods.

Key Features

  • Convert MNE-Python Epochs objects to TEP objects
  • Automatic detection of TEP peaks
  • Automatic selection of most reponsive channels
  • Time-frequency analysis using Stockwell transform
  • Extraction of temporal and spectral features
  • Visualization of temporal and spectral features
  • Customizable analysis parameters for research flexibility

Analysis Workflow

TEPpy Analysis Workflow Typical TEPpy analysis workflow from MNE Epochs to extracted features

Getting Started

Dependencies

  • numpy>=2.0.1
  • scipy>=1.14.0
  • mne>=1.9.0
  • matplotlib>=3.9.1
  • stockwell>=1.2

Installation

Install from PyPI:

pip install teppy

Core Concepts

TEP Class

Converts MNE Epochs objects into analyzable TEP data structures:

  • Performs automatic peak detection (P1, P2, P3)
  • Extracts amplitude, latency, and peak-to-peak features
  • Provides channel selection methods

TEP(epochs, exclude_channels=None, p1_range=[0.01, 0.04], low_limit=35, sign_corr='convexity')

Key methods:

compute_timefreq(): Perform time-frequency analysis

get_ntop_ch(): Get top channel names

plot_summary(): Generate summary plot

Feature accessors: get_amplitudes(), get_latencies(), etc.

TimeFreq Class

Stores and analyzes time-frequency decomposition results:

  • Computes power and inter-trial coherence
  • Estimates natural frequency
  • Provides visualization tools

Key methods:

plot_natfreq1(): Comprehensive natural frequency visualization

plot_natfreq2(): Compact visualization

get_natfreq(): Compute natural frequency

Data accessors: get_power(), get_itc(), get_complex()

Usage

1. Loading Data

import mne
from teppy import TEP

# Load EEG epochs
epochs = mne.read_epochs('your_data.fif', verbose=False)

# Define channels to exclude
exclude_channels = ['Fp1', 'Fpz', 'Fp2', 'F7', 'F8', 'FT7', 'FT8', 'T7',
                    'T8', 'TP7', 'TP8', 'TP9', 'TP10', 'P7', 'P8', 'Iz']

2. Creating TEP Object

tep = TEP(
    epochs,
    exclude_channels=exclude_channels,
    p1_range=[0.01, 0.04],  # P1 detection window (s)
    low_limit=35,            # Minimum peak separation (Hz)
    sign_corr='convexity'    # Signal correction method
)

3. Extracting Features

# Get top 4 channels
top_channels = tep.get_ntop_ch(ntop=4)

# Get comprehensive feature summary
feature_summary = tep.info_ntop(ntop=4)

4. Generating Summary Plot

fig = tep.plot_summary(
    ntop=4,
    tlim=(-0.1, 0.3),      # Time limits (s) of the plot
    cmap_topo='Reds',    # Topomap colormap
)
fig.savefig('tep_summary.png', dpi=300)

5. Time-Frequency Analysis

# Compute time-frequency decomposition
timefreq = tep.compute_timefreq(
    ntop=4,                 # Use top 4 channels
    method='stock1',        # MNE's Stockwell implementation
    fmin=4, fmax=45,        # Frequency range
    baseline_correction=True,
    baseline_range=(-0.5, -0.1)
)

# Plot natural frequency map
fig = timefreq.plot_natfreq1(
    natfreq_window=[0.02, 0.15],  # Natural frequency window
    plot_tlim=(-0.1, 0.3), # Time limits (s) of the plot
    plot_ms=True, # plot the time axis in ms
    cmap='RdBu_r'
)
fig.savefig('timefreq_analysis.png', dpi=300)

Advanced Features

Custom Channel Selection

# Select specific channels
timefreq_custom = tep.compute_timefreq(
    pick_ch=['Cz', 'Pz', 'Fz'],  # Custom channel selection
    method='stock2',              # Alternative Stockwell implementation
    gamma=1.5,                    # Gamma parameter for stock2
    return_complex=True            # Return complex coefficients
)

Batch Processing

results = []
subjects = ['sub-01', 'sub-02', 'sub-03']

for subject in subjects:
    epochs = mne.read_epochs(f'{subject}_epo.fif')
    tep = TEP(epochs, exclude_channels=exclude_channels)
    tf = tep.compute_timefreq(ntop=4)
    
    results.append({
        'subject': subject,
        'nat_freq': tf.get_natfreq(natfreq_window=[0.02, 0.15]),
        'top_channels': tep.get_ntop_ch(ntop=4),
        'p1p2_amplitude': tep.get_peaktopeak(ntop=4).mean(0)[0] # [0]: Get P1-P2 amplitude 
    })

Accessing Underlying Data

# Get raw power data
power_data = timefreq.get_power(average_channels=True)

# Get complex coefficients
complex_data = timefreq.get_complex()

# Get evoked spectrum
evoked_spectrum = timefreq.get_evoked_spectrum(
    sum_window=[0.02, 0.12]
)

Citation

Contact

Contributing

Contributions are welcome! Please fork the repository and submit pull requests. Report issues on the GitHub issue tracker.

License

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

teppy-0.2.0.tar.gz (34.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

teppy-0.2.0-py3-none-any.whl (32.7 kB view details)

Uploaded Python 3

File details

Details for the file teppy-0.2.0.tar.gz.

File metadata

  • Download URL: teppy-0.2.0.tar.gz
  • Upload date:
  • Size: 34.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.7

File hashes

Hashes for teppy-0.2.0.tar.gz
Algorithm Hash digest
SHA256 eb0bcfd642f17b0c17e45c14bb658c4ffa99c8c345c974bed243facc6a7ecb7a
MD5 b0ce540a8e46a160a99f93f67b33c705
BLAKE2b-256 d537929c415290f7b92cef867ef2da33eac3506edf4f1cb1c534ac401354f361

See more details on using hashes here.

File details

Details for the file teppy-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: teppy-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 32.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.7

File hashes

Hashes for teppy-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4fcd1e1d28a3f66a175b0e17727d6edecbb3b9796d5352b4c82609a3d0cddc97
MD5 b0cad92a788c32f5a2a5e9c44255bcbe
BLAKE2b-256 5880ad5bd84e40f4c7a0c1c9df19d8709cb84485d63869e74aaa6cbac0b86d6b

See more details on using hashes here.

Supported by

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