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.FFTResample

FFT-based resample (scipy.signal.resample) to a target rate.

physioex.data.InterpResample

Linearly interpolate a signal onto a fixed time grid.

physioex.data.FixedLength

Pad the END with fill or truncate the END to a fixed length.

physioex.data.ZScoreNormalize

Per-subject per-channel z-score normalization.

physioex.data.ZScore

Whole-signal z-score with a tunable ddof and a std floor.

physioex.data.Clip

Symmetric outlier clipping around the signal mean.

physioex.data.ChebyshevLowpass

Type-II Chebyshev IIR lowpass (zero-phase via sosfiltfilt).

physioex.data.PhysicalScale

Scale a channel using its EDF header (physical dimension / range).

physioex.data.XSleepNetSpectrogram

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

physioex.data.steps.JonesECGPreprocess

Full Jones et al. (2024) ECG preprocessing in a single step.

physioex.data.get_preset

Instantiate a preset by name.

physioex.data.available_presets

Return sorted list of available preset names.

physioex.data.get_label_transform

Return the label transform registered under name.

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, downloading the weights if needed.

physioex.models.pretrained.list_pretrained

List the pretrained models available through load_from_pretrained.

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:

Cardiorespiratory architectures (whole-night models with published weights):

physioex.models.wav2sleep.Wav2Sleep

Model for sleep staging.

physioex.models.sleepppgnet.SleepPPGNet

SleepPPG-Net with a physioex per-epoch interface.

physioex.models.jones_ecg.JonesECGNet

ECG-only sleep staging network of Jones, Itti & Sheth (2024).

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.replication

Library support for replicating published cardiorespiratory results.

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), prototype discovery, and Layer-wise Relevance Propagation (explain extra).

physioex.explain.foundational

Explainability methods for foundation model embeddings.

physioex.explain.prototypes.posthoc

physioex.explain.lrp

Layer-wise Relevance Propagation (LRP) for PhysioEx.