DRIFT
Diffeomorphic Regional Interpolation and extrapolation of Flow Trajectories.
Data augmentation for segmentation that moves an image partway along an inter-patient deformation,
stored as a stationary velocity field v: φ = exp(w(x)·v), with a global or per-region time t
that can interpolate (t ∈ [0,1]) or extrapolate. Every sample is a diffeomorphism, and image and
labels are warped together, so labels stay exact.
Status: pre-release.
Install
pip install drift-aug # core
pip install "drift-aug[io]" # NIfTI and N4 support (needed by the command line)
Other extras: viz, monai, torchio.
How it works
- Build a field bank once: register each training subject A to a few partners B (affine, then a B-spline SVF), keep the non-rigid SVFs and their QC.
- Augment during training: pick a partner, draw a time per region (from A's labels), and warp A's
image and labels with
exp(-w·v_AB): att = 1A takes B's shape, othertinterpolate or extrapolate.
Anatomy-specific choices (preprocessing, registration mask and parameters, regions and their t ranges,
QC bounds) live in site profiles: breast_mri and thorax_mri are bundled (drift profiles).
Command line
drift bank build bank/ --images imgs/ --labels labels/ --profile breast_mri --backend torch
drift bank info bank/ --pairs
drift sweep bank/ case01 case07 --t -0.5 0 0.5 1 1.5 --out sweep/
drift augment bank/ case01 --n 8 --out aug/
drift register fixed.nii.gz moving.nii.gz --out reg/
Python
from drift.augment import DriftAugment
from drift.bank import FieldBank
aug = DriftAugment(FieldBank("bank/"), seed=0) # policy, mode and QC from the bank's profile
sample = aug({"subject": "case01", "image": image, "label": label}) # (C, *spatial) tensors/arrays
Framework adapters (apply them before random cropping):
- MONAI:
drift.integrations.monai.DriftAugmentd(["image", "label"], bank); reads the grid from theMetaTensoraffine. - TorchIO:
drift.integrations.torchio.RandomDrift(bank); warpsScalarImages andLabelMaps. - nnU-Net:
examples/nnunet_offline_drift.pywrites augmented copies into a new nnU-Net dataset with leak-free cross-validation splits.
Registration backends
torch(default): PyTorch reimplementation (NMI/LNCC/SSD, B-spline SVF, GPU). No external dependencies. On labelled breast MRI it matched or beat NiftyReg (Dice 0.924 vs 0.905) at ~4.6× the speed.niftyreg: wraps NiftyReg (reg_aladin,reg_f3d -vel); the reference implementation. Build it withscripts/build_niftyreg.sh, or put the binaries onPATHor in$NIFTYREG_BIN.
Development
uv sync --extra dev --extra io # add --all-extras for monai/torchio
uv run pytest --cov
uv run ruff check . && uv run ruff format --check .
uv run mypy
Tests that need NiftyReg, a GPU or real data skip themselves when those are missing. scripts/build_niftyreg.sh builds NiftyReg locally, and CI runs the NiftyReg tests against that build on every push and pull request. Commit messages follow Conventional Commits, which set the next version on release.
Examples
examples/01_square_to_circle_2d.ipynb: the core idea in 2D.examples/02_regional_edits.ipynb: per-region times, Eulerian vs Lagrangian.examples/03_build_bank_mri.ipynb: bank building and augmentation on breast MRI (Duke, setDRIFT_BREAST_DIR) or phantoms.examples/nnunet_offline_drift.py: nnU-Net integration.
Metadata
Release files for drift-aug 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| drift_aug-0.1.0.tar.gz | 691.7 kB | With provenance | Details for drift_aug-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| drift_aug-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for drift_aug-0.1.0-py3-none-any.whl |
Total release size: 753.9 kB
Release files / drift_aug-0.1.0.tar.gz
| Download URL | drift_aug-0.1.0.tar.gz |
|---|---|
| Size | 691.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
700054c8c0e36d601b25d8d71b4767180ffafb73cdad5d4aa389f726be2048c7
|
|
BLAKE2b-256 checksum How to use checksums |
69f1f82b7437a23ee6bb4f1041254ca62c650a0c4a23f6d5ba541dfb5126e135
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logRelease files / drift_aug-0.1.0-py3-none-any.whl
| Download URL | drift_aug-0.1.0-py3-none-any.whl |
|---|---|
| Size | 62.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f8d3b6fa694fc890862ed5c690e6d551fe7826ecf2b15f8d9c23908dfb283483
|
|
BLAKE2b-256 checksum How to use checksums |
31ff693e530dd3edc2ce51df837a256c9ca0296351b1e2c1b41765b8507caffc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logSecurity for drift-aug 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for drift_aug-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.