API Reference#

This reference is generated automatically from the physioex docstrings, so it always mirrors the installed code (the physioex-dev API). For the high-level picture of how these pieces fit together, see the library architecture pages.

physioex.data#

The raw-EDF, lazy-loading dataset layer, the preprocessing pipeline, the on-disk cache, EDF/annotation readers and sleep-event helpers.

physioex.data.BasePhysioDataset

Abstract base class for lazy-loading EDF-based sleep datasets.

physioex.data.MultiDataset

Wraps multiple BasePhysioDataset instances into a single unified dataset.

physioex.data.SubjectSpec

Metadata describing how to locate a single subject's raw data.

physioex.data.PreprocessingStep

Base class for all preprocessing operations.

physioex.data.PreprocessingPipeline

physioex.data.CompiledPipeline

physioex.data.CompiledStep

Result of compiling a PreprocessingStep against a specific input fs.

physioex.data.Identity

Passthrough; does nothing.

physioex.data.BandpassFilter

IIR Butterworth bandpass filter (zero-phase via sosfiltfilt).

physioex.data.NotchFilter

IIR notch filter (powerline removal).

physioex.data.Resample

Resample to target sampling rate.

physioex.data.ZScoreNormalize

Per-subject per-channel z-score normalization.

physioex.data.XSleepNetSpectrogram

STFT spectrogram with power-dB scaling, matching Huy Phan's SeqSleepNet / XSleepNet / SleepTransformer preprocessing.

physioex.data.get_preset

Instantiate a preset by name.

physioex.data.available_presets

Return sorted list of available preset names.

physioex.data.ChannelCache

physioex.data.dict_collate_fn

Collate a list of dict-returning dataset items.

physioex.data.stack_channels

Convert a collated dict batch to a (B, L, C, ...) tensor for model input.

physioex.data.is_dict_batch

Return True if batch looks like a dict-style PhysioEx batch.

physioex.data.EDFHeader

physioex.data.ResolvedChannel

physioex.data.probe_edf_header

Read the EDF structural header only (no signal data).

physioex.data.resolve_channels

Resolve user channel requests against the EDF's available channels.

physioex.data.SleepEvent

physioex.data.map_events_to_epochs

Map a flat list of events to per-epoch event lists.

physioex.data.events_to_dicts

Convert a list of SleepEvent objects to a list of dicts.

physioex.data.dicts_to_events

Reconstruct SleepEvent objects from a list of dicts.

Datasets are resolved by name from the registry:

physioex.models#

Foundation encoders (a uniform (B, L, C, T) -> (B, L, D) wrapper around heterogeneous pretrained backbones), embedding/pretrained helpers, and the classic sleep-staging architectures.

physioex.models.FoundationEncoder

Abstract adapter: frozen encoder that returns embeddings.

physioex.models.CBraModEncoder

CBraMod accepts any number of EEG channels, pools over them.

physioex.models.BENDREncoder

BENDR maps input channels to a fixed 20-channel 10-20 layout.

physioex.models.LaBraMEncoder

LaBraM with channel-aware position embeddings; lazy model build.

physioex.models.BIOTEncoder

BIOT with 16-channel double-banana layout + q95 normalization.

physioex.models.SleepFMEncoder

SleepFM pads input to 10 channel slots and masks unused ones.

physioex.models.TFCEncoder

TF-C: single-channel time + frequency transformer.

physioex.models.REVEEncoder

REVE with position bank for channel-aware embeddings.

physioex.models.SJEEncoder

Signal-JEPA with fixed 19-channel 10-20 layout.

physioex.models.NeuroLMEncoder

NeuroLM with patch-based tokenization and VQ channel vocabulary.

physioex.models.load_from_pretrained

Load a pretrained model from HuggingFace Hub.

physioex.models.extract_embeddings

Extract and cache contextualized embeddings for all subjects.

physioex.models.load_embeddings

Load cached embeddings, downloading from HuggingFace if needed.

physioex.models.linear_probe

5-fold subject-wise cross-validated linear probe on cached embeddings.

Classic architectures:

physioex.train#

A hand-written PyTorch training/evaluation loop (not Lightning), with metric and statistics helpers, pluggable logging, and the three console-script entry points.

physioex.train.trainer.Trainer

physioex.train.trainer.seed_everything

Seed all relevant RNGs for reproducibility.

physioex.train.multidevicetrainer.Trainer

physioex.train.logger.Logger

Backend-agnostic experiment logger.

physioex.train.logger.NoOpLogger

A logger that discards everything.

physioex.train.logger.build_logger

Instantiate a logger backend.

physioex.train.models.load.load_model

Load a model with dual-format checkpoint support.

Metrics, statistics and progress helpers are documented at module level:

physioex.train.metrics

physioex.train.stats

Per-subject metric aggregation (mean / std / confidence interval).

physioex.train.progress

physioex.explain#

Post-hoc attribution, the foundational Conceptual Spectral Decomposition (CSD), and prototype discovery.

physioex.explain.foundational

Explainability methods for foundation model embeddings.

physioex.explain.prototypes.posthoc