Skip to main content

Crate exg_luna

Crate exg_luna 

Source
Expand description

§exg-luna — LUNA seizure-detection EEG preprocessing pipeline

Crate Docs

Part of the exg workspace. Uses exg DSP primitives (filter design, resampling, montage conversion) under the hood.

§Pipeline

Implements the full preprocessing chain used by the LUNA seizure detection model, matching the Python training pipeline:

  1. Channel rename (strip "EEG " prefix, "-REF" / "-LE" suffix)
  2. Pick standard 10-20 channels (21 electrodes)
  3. Bandpass filter 0.1–75 Hz (zero-phase FIR, MNE _firwin_design parity)
  4. Notch filter at 60 Hz (configurable for 50 Hz)
  5. Resample to 256 Hz (FFT polyphase)
  6. TCP bipolar montage (22 channels from 21 reference electrodes)
  7. Epoch into 5 s non-overlapping 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.

§I/O

This crate also provides safetensors serialization of preprocessed epochs in a format compatible with luna-rs InputBatch.

§Quick start

use exg::edf::open_raw_edf;
use exg_luna::{preprocess_luna, LunaPipelineConfig};

let raw = open_raw_edf("recording.edf").unwrap();
let data = raw.read_all_data().unwrap();
let ch_names = raw.channel_names();
let cfg = LunaPipelineConfig::default();
let epochs = preprocess_luna(data, &ch_names, raw.header.sample_rate, &cfg).unwrap();

Structs§

LunaEpoch
A single epoch ready for LUNA inference.
LunaPipelineConfig
Configuration for the LUNA preprocessing pipeline.

Constants§

STANDARD_10_20
The standard 21 electrodes of the 10-20 system used by TUH/LUNA.

Functions§

export_luna_epochs
Export LUNA-format epochs to a safetensors file.
load_luna_epochs
Load LUNA-format epochs from a safetensors file.
preprocess_luna
Run the LUNA preprocessing pipeline on a continuous recording.