Skip to main content

A python library for neuroimaging transformations

Project description

warpkit

Build PyPI docker codecov

A Python library for neuroimaging transforms, focused on the Multi-Echo DIstortion Correction (MEDIC) algorithm. The pre-print is available at https://www.biorxiv.org/content/10.1101/2023.11.28.568744v1.

The phase-unwrapping core is a self-contained C++17 port of ROMEO — there is no Julia runtime to install, and binary wheels ship with the ITK pieces statically linked. If you used an older release of warpkit that required julia on PATH, that step is gone.

Installation

From PyPI (recommended)

pip install warpkit

Pre-built wheels are published for Linux (x86_64 + aarch64) and macOS (universal2). If pip falls back to a source build and fails, please open an issue with the output of pip install warpkit -v.

Standalone binaries (no Python required)

Each GitHub release attaches a zip per arch (linux-x86_64, linux-aarch64, macos-arm64) containing all seven wk-* CLIs as standalone binaries — no Python install or system ITK needed. Extract, add to PATH, and run. See the bundled README.md inside the zip for install/PATH instructions and the macOS Gatekeeper note.

Docker

docker run -it --rm ghcr.io/vanandrew/warpkit:latest --help

The image's entrypoint is the wk-medic CLI.

From source

You need a C++17 compiler and CMake ≥ 3.24. Everything else (Python, build deps, ITK) is resolved by uv.

git clone https://github.com/vanandrew/warpkit.git
cd warpkit
uv sync --group dev --config-setting editable_mode=strict

editable_mode=strict is the recommended setuptools editable layout — it avoids the import-path pitfalls of the default editable install. Append -v to uv sync if a build fails and include the full log when reporting the issue.

What is MEDIC?

MEDIC takes ME-EPI phase data:

phase

and turns it into a per-frame field map:

field map

You can then use these field maps to distortion-correct your data.

Using MEDIC

warpkit is meant to be integrated into a larger neuroimaging pipeline. The Python entry point:

import nibabel as nib
from warpkit.distortion import medic
from warpkit.utilities import displacement_map_to_field

# each list entry is a different echo
phases = [nib.load(p) for p in phases_paths]
magnitudes = [nib.load(p) for p in magnitude_paths]
TEs = [TE1, TE2, ...]                     # milliseconds
total_readout_time = ...                  # seconds
phase_encoding_direction = ...            # one of i, j, k, i-, j-, k-, x, y, z, x-, y-, z-

field_maps_native, displacement_maps, field_maps = medic(
    phases, magnitudes, TEs, total_readout_time, phase_encoding_direction
)

Returns are nibabel.Nifti1Image objects:

  • field_maps_native — field maps in distorted space (Hz). Mostly useful for debugging.
  • displacement_maps — displacement in undistorted space (mm). Convert with displacement_map_to_field before applying.
  • field_maps — field maps in undistorted space (Hz). Equivalent to topup/fugue output, but framewise.

To convert a displacement map to a per-frame warp field for your tool of choice:

displacement_maps.to_filename("/path/to/save.nii.gz")

displacement_field = displacement_map_to_field(
    displacement_maps, axis="y", format="itk", frame=0
)

format selects the output convention. Apply with the matching tool:

format Apply with Notes
itk warpkit.utilities.resample_image warpkit's internal format.
ants antsApplyTransforms ANTs uses ITK underneath, but its warp convention differs from ours.
afni 3dNwarpApply
fsl applywarp If you'd rather use fugue, feed it field_maps instead.

CLI

All warpkit CLIs are installed on PATH with a wk- prefix to avoid colliding with same-named tools from FSL/ANTs/AFNI/etc.:

Command Purpose
wk-medic End-to-end MEDIC pipeline: phase + magnitude → field maps + displacement maps.
wk-unwrap-phase Stage 1: ROMEO multi-echo phase unwrapping → unwrapped phase + per-frame masks.
wk-compute-fieldmap Stage 2: take stage-1 outputs → native + displacement + undistorted-space field maps.
wk-apply-warp Resample an image through a displacement map / field (single or per-frame series).
wk-convert-warp Convert between maps ↔ fields and between ITK / FSL / ANTs / AFNI; --invert warps.
wk-convert-fieldmap Convert between mm displacement maps/fields and Hz B0 field maps.
wk-compute-jacobian Per-voxel Jacobian determinant (1 = no change, <1 = compression, >1 = expansion).

wk-medic runs the full pipeline; wk-unwrap-phase + wk-compute-fieldmap run the same thing in two stages so you can inspect/reuse the unwrapped phase. Acquisition parameters can come either from BIDS sidecars or from the command line — pick one.

From BIDS sidecars:

wk-medic \
  --magnitude mag_e1.nii.gz mag_e2.nii.gz mag_e3.nii.gz \
  --phase phase_e1.nii.gz phase_e2.nii.gz phase_e3.nii.gz \
  --metadata mag_e1.json mag_e2.json mag_e3.json \
  --out-prefix sub-01_run-01

EchoTime is read per file (seconds → converted to ms internally); TotalReadoutTime and PhaseEncodingDirection are taken from the first sidecar.

Or by passing acquisition parameters directly:

wk-medic \
  --magnitude mag_e1.nii.gz mag_e2.nii.gz mag_e3.nii.gz \
  --phase phase_e1.nii.gz phase_e2.nii.gz phase_e3.nii.gz \
  --TEs 14.2 38.93 63.66 \
  --total-readout-time 0.0501 \
  --phase-encoding-direction j- \
  --out-prefix sub-01_run-01

--TEs is in milliseconds, --total-readout-time in seconds, and --phase-encoding-direction is one of i, j, k, i-, j-, k-, x, y, z, x-, y-, z-.

Run any wk-* CLI with --help for the full option list.

Common follow-on workflows

Apply a MEDIC displacement-map series to the BOLD it was derived from (per-frame distortion correction):

wk-apply-warp \
  --input bold.nii.gz \
  --transform sub-01_run-01_displacementmaps.nii \
  --phase-encoding-axis j \
  --output bold_corrected.nii.gz

Convert MEDIC's per-frame displacement maps into per-frame ANTs-format displacement fields:

wk-convert-warp \
  --input sub-01_run-01_displacementmaps.nii \
  --to field --axis j --to-format ants \
  --output field_{0..14}.nii.gz

Compute the per-frame Jacobian determinant (volume-change map) of those displacement maps:

wk-compute-jacobian \
  --input sub-01_run-01_displacementmaps.nii \
  --axis j \
  --output sub-01_run-01_jacobian.nii

Convert MEDIC's mm displacement maps to a Hz B0 field map (or back — this CLI handles either direction, with maps or fields on the mm side):

wk-convert-fieldmap \
  --input sub-01_run-01_displacementmaps.nii \
  --to fieldmap \
  --total-readout-time 0.0501 \
  --phase-encoding-direction j- \
  --output sub-01_run-01_fieldmap.nii

Authors

Vahdeta Suljic <suljic@wustl.edu>, Andrew Van <vanandrew77@gmail.com>

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

warpkit-1.1.0.tar.gz (28.4 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

warpkit-1.1.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (29.0 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

warpkit-1.1.0-cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (29.0 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.26+ ARM64manylinux: glibc 2.28+ ARM64

warpkit-1.1.0-cp314-cp314-macosx_10_15_universal2.whl (29.4 MB view details)

Uploaded CPython 3.14macOS 10.15+ universal2 (ARM64, x86-64)

warpkit-1.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (29.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

warpkit-1.1.0-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (29.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.26+ ARM64manylinux: glibc 2.28+ ARM64

warpkit-1.1.0-cp313-cp313-macosx_10_13_universal2.whl (29.4 MB view details)

Uploaded CPython 3.13macOS 10.13+ universal2 (ARM64, x86-64)

warpkit-1.1.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (29.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

warpkit-1.1.0-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (29.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.26+ ARM64manylinux: glibc 2.28+ ARM64

warpkit-1.1.0-cp312-cp312-macosx_10_13_universal2.whl (29.4 MB view details)

Uploaded CPython 3.12macOS 10.13+ universal2 (ARM64, x86-64)

warpkit-1.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (29.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

warpkit-1.1.0-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (29.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.26+ ARM64manylinux: glibc 2.28+ ARM64

warpkit-1.1.0-cp311-cp311-macosx_10_9_universal2.whl (29.4 MB view details)

Uploaded CPython 3.11macOS 10.9+ universal2 (ARM64, x86-64)

File details

Details for the file warpkit-1.1.0.tar.gz.

File metadata

  • Download URL: warpkit-1.1.0.tar.gz
  • Upload date:
  • Size: 28.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for warpkit-1.1.0.tar.gz
Algorithm Hash digest
SHA256 27eb32246c36a730fd5d7a07ae198aff5f3f361242630d37576b9e87c158bec1
MD5 0d8b7f66bcfb7b47bd6557e6b60ffc3d
BLAKE2b-256 5cb01bfefc850de24ca89a81f781ae7fc7db5424bdfb371618ed462f88fed468

See more details on using hashes here.

Provenance

The following attestation bundles were made for warpkit-1.1.0.tar.gz:

Publisher: build.yml on vanandrew/warpkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file warpkit-1.1.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for warpkit-1.1.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a5c9ec7df4697bde3b64f0b3f8a39f0b9eea8c00015316cff745791a67811cf6
MD5 7a94204e39138a35778e14c9886118f8
BLAKE2b-256 5d4fa8ea4a6cdbd18877893654fc8c4eb17f2c6a333ba6d98324b081e59e5f56

See more details on using hashes here.

Provenance

The following attestation bundles were made for warpkit-1.1.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build.yml on vanandrew/warpkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file warpkit-1.1.0-cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for warpkit-1.1.0-cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 baf4f2d8abf8d88ddc60a24ed4d6e786ef2da8827f8b32f6268588d410b21e50
MD5 b9c27b0b8bb6d610a7cb254647a2a9c2
BLAKE2b-256 8dac899cbe0ef1b171a7760fbc55a8a1a2305141b85c0ecf59840f89c502d4b2

See more details on using hashes here.

Provenance

The following attestation bundles were made for warpkit-1.1.0-cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl:

Publisher: build.yml on vanandrew/warpkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file warpkit-1.1.0-cp314-cp314-macosx_10_15_universal2.whl.

File metadata

File hashes

Hashes for warpkit-1.1.0-cp314-cp314-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 bfef658f6c20cc49e2bd5235e228b6af097dcfb46f19305927f021d70f4d4cd2
MD5 7f841003bb7b32490199f32fe4bf721a
BLAKE2b-256 47f6406cd76127dd838a93d9ac9574aa86c8796f40b9790962bc28f9b0fd24e7

See more details on using hashes here.

Provenance

The following attestation bundles were made for warpkit-1.1.0-cp314-cp314-macosx_10_15_universal2.whl:

Publisher: build.yml on vanandrew/warpkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file warpkit-1.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for warpkit-1.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 aa2120dd9bc3ce21c21e8fe0d4a2c8eb9dab09c23439715f7e8ebb7bf37b3061
MD5 97e5fb9296e5ee91a7462471049b3f1c
BLAKE2b-256 33114edf895d90547bb8094306adebf0ea5fb1724dcb4d077a3e4e935143c611

See more details on using hashes here.

Provenance

The following attestation bundles were made for warpkit-1.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build.yml on vanandrew/warpkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file warpkit-1.1.0-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for warpkit-1.1.0-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 7cec7618e30eb54dd7dad8cab96b4c75b1fecd3ba3c0e27f349cbca5e8ca06f2
MD5 60320d75bbe627921860190f992f3399
BLAKE2b-256 9ff2829840f33eb0a9f137a54730eef6829b1cfc5d79438c5abd91bebb845861

See more details on using hashes here.

Provenance

The following attestation bundles were made for warpkit-1.1.0-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl:

Publisher: build.yml on vanandrew/warpkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file warpkit-1.1.0-cp313-cp313-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for warpkit-1.1.0-cp313-cp313-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 464294cb05c6d9ebaf1de53d0b5d56d13f43822f7d3688f7f68be89fd733e6e4
MD5 9500579158a20126c6203969e9e30e61
BLAKE2b-256 9d65c143040eb4137c59fe9d5a616d67e66384e0633b64031d0e3dece0e13d87

See more details on using hashes here.

Provenance

The following attestation bundles were made for warpkit-1.1.0-cp313-cp313-macosx_10_13_universal2.whl:

Publisher: build.yml on vanandrew/warpkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file warpkit-1.1.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for warpkit-1.1.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 50354c986cb80f3ae003a93c9f29965a8f1e86b93e5a4c162aa24b36e22f7ed8
MD5 7af8605f884bee14fca09b91e323feb8
BLAKE2b-256 739270086ee8878b5d8a4b62fb26e9c13f1531a870a7a0090f1289cb653c6a41

See more details on using hashes here.

Provenance

The following attestation bundles were made for warpkit-1.1.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build.yml on vanandrew/warpkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file warpkit-1.1.0-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for warpkit-1.1.0-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 928140de9f9d1a8ce4f676bc3d7ccbd21b298cb4424d024b50ef325f040f340b
MD5 6970434523d274ed2040aa2c2898ac34
BLAKE2b-256 0bda5a09d61ec0df85dc4a6d4d581d5e64310b7d633fd0e487f289ea54c7b4b0

See more details on using hashes here.

Provenance

The following attestation bundles were made for warpkit-1.1.0-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl:

Publisher: build.yml on vanandrew/warpkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file warpkit-1.1.0-cp312-cp312-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for warpkit-1.1.0-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 d00e4738ad0088e878a77b802e58561ad04160f4630add9d5966e9f12f4b348a
MD5 23baeffc3213fff9530a3781bf5a7a5c
BLAKE2b-256 e89e8c3f3997b2ad9550574758e86eab76167c87875181647a4f948a10dcf505

See more details on using hashes here.

Provenance

The following attestation bundles were made for warpkit-1.1.0-cp312-cp312-macosx_10_13_universal2.whl:

Publisher: build.yml on vanandrew/warpkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file warpkit-1.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for warpkit-1.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f50ec4c93d5a187d35674c99dfed69ac8e55386a8f9b4b436c652dea44d0610f
MD5 00d4395fe5a2fb85d48c1a13cf6620b5
BLAKE2b-256 c7dbed0e234a1e7bcf2b244344782abd6e9f88525117728b946f3e7f3a066752

See more details on using hashes here.

Provenance

The following attestation bundles were made for warpkit-1.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build.yml on vanandrew/warpkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file warpkit-1.1.0-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for warpkit-1.1.0-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 8b7c1a6c45df3f836db1496a7436eaa15871a01af441cd13d23d993fe055f53b
MD5 66f4b17036650028c8b93818a2a9a6bd
BLAKE2b-256 a3d1098968a614144b1464321ca5c5903e52847c26b4df3443d5069af7351c1b

See more details on using hashes here.

Provenance

The following attestation bundles were made for warpkit-1.1.0-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl:

Publisher: build.yml on vanandrew/warpkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file warpkit-1.1.0-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for warpkit-1.1.0-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 eeca20ffaea848289d3a713c7998b54483bbb1cc2d87204eb7ceb4723c9b7d2c
MD5 9416430753dfadff94bd972beb7e5d9a
BLAKE2b-256 f5317f7e30350fe355e63098a15f1fb7c20a6a07ca5218b4b292d7cc533002c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for warpkit-1.1.0-cp311-cp311-macosx_10_9_universal2.whl:

Publisher: build.yml on vanandrew/warpkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page