Tutorial

Offline Neurology Epilepsy & Continuous EEG Seizure Prediction Engine

Difficulty: Advanced Time: 25 min read

Introduction

Continuous electroencephalography (cEEG) monitoring in epilepsy monitoring units (EMUs) and intensive care units requires real-time detection of pre-ictal epileptiform spikes and seizure onset. In this cookbook, we introduce EpilepsyGuard-EEG-v1, an offline 1-D CNN + Transformer model designed to process 16-channel scalp/intracranial EEG streams on edge hardware to predict focal and generalized seizures up to 30 minutes before clinical onset.

Prerequisites

  • Python 3.9+
  • PyTorch & MNE-Python
  • openphr-cli
  • EDF/BDF format continuous EEG recordings

Step 1: Ingest Local EEG Telemetry Stream

Load 16-channel 10-20 system scalp EEG signals, apply notch filtering (60 Hz) and bandpass filtering (0.5-70 Hz), and construct 5-second overlapping sliding windows.

import mne
import numpy as np
import torch

# Load local European Data Format (EDF) EEG recording
raw = mne.io.read_raw_edf('eeg_patient_01.edf', preload=True)
raw.filter(l_freq=0.5, h_freq=70.0)
raw.notch_filter(freqs=60.0)

# Extract 16 standard channels (Fp1-F7, F7-T7, etc.)
data, times = raw[:16, :raw.info['sfreq'] * 5] # 5-second segment
tensor_eeg = torch.tensor(data, dtype=torch.float32).unsqueeze(0)
print("EEG segment shape:", tensor_eeg.shape)

Step 2: Execute Local Seizure Prediction Pipeline

Run the openphr-cli pipeline to process raw EEG windows, detect epileptiform discharges, and output real-time seizure probability indices:

openphr-cli run epilepsyguard-eeg-v1 \
    --input-edf ./eeg_patient_01.edf \
    --channels 16-channel-standard \
    --output-alert ./seizure_forecast.json

Expected Outcome

A continuous probability stream of pre-ictal states with low false-alarm rates, enabling prompt clinical intervention and automated patient warning without cloud data transmission.