exg-luna
LUNA seizure-detection preprocessing pipeline for EEG — built on
exg.
Part of the exg workspace.
See also exg-source for EEG source
localisation.
This crate implements the full preprocessing chain used by the LUNA seizure
detection model, matching the Python training pipeline. It uses exg DSP
primitives (filter design, resampling, montage conversion) under the hood.
Installation
[]
= "0.0.3" # pulls in exg automatically
If you also need file readers (EDF, FIF) or source localisation from exg:
[]
= "0.0.3" # includes exg-source by default
= "0.0.3"
Pipeline steps
| Step | Operation | Details |
|---|---|---|
| 1 | Channel rename | Strip "EEG " prefix, "-REF" / "-LE" suffix |
| 2 | Pick 10-20 channels | 21 standard electrodes (STANDARD_10_20) |
| 3 | Bandpass filter | 0.1–75 Hz, zero-phase FIR (MNE _firwin_design parity) |
| 4 | Notch filter | 60 Hz (configurable for 50 Hz), zero-phase FIR |
| 5 | Resample | → 256 Hz (FFT polyphase) |
| 6 | TCP bipolar montage | 22 bipolar channels from 21 reference electrodes |
| 7 | Epoch | Non-overlapping 5 s windows (1280 samples) |
Note: Channel-wise z-score is not applied here — LUNA does that at
inference time inside the model. Use exg::normalize::zscore_channelwise_inplace
separately if needed.
Quick start
use open_raw_edf;
use ;
let raw = open_raw_edf.unwrap;
let data = raw.read_all_data.unwrap;
let ch_names = raw.channel_names;
let cfg = default; // 0.1–75 Hz BP · 60 Hz notch · TCP montage
let epochs = preprocess_luna.unwrap;
// → Vec<(Array2<f32>[22, 1280], Vec<String>)>
Custom configuration
use LunaPipelineConfig;
let cfg = LunaPipelineConfig ;
Safetensors I/O
Export and load preprocessed epochs in a format compatible with luna-rs
InputBatch:
use ;
use Array2;
use Path;
let epoch = LunaEpoch ;
export_luna_epochs.unwrap;
let loaded = load_luna_epochs.unwrap;
File layout
n_epochs: I32 [1]
signal_0: F32 [C, T]
positions_0: F32 [C, 3]
ch_names_0: U8 [len] ← newline-separated channel names
signal_1: ...
API
// Pipeline
pub const STANDARD_10_20: & // 21 electrodes
// I/O