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.2.0.tar.gz (39.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.2.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (746.6 kB view details)

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

warpkit-1.2.0-cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (690.0 kB view details)

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

warpkit-1.2.0-cp314-cp314-macosx_10_15_universal2.whl (1.1 MB view details)

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

warpkit-1.2.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (746.5 kB view details)

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

warpkit-1.2.0-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (689.8 kB view details)

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

warpkit-1.2.0-cp313-cp313-macosx_10_13_universal2.whl (1.1 MB view details)

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

warpkit-1.2.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (746.6 kB view details)

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

warpkit-1.2.0-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (689.8 kB view details)

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

warpkit-1.2.0-cp312-cp312-macosx_10_13_universal2.whl (1.1 MB view details)

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

warpkit-1.2.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (746.1 kB view details)

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

warpkit-1.2.0-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (689.3 kB view details)

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

warpkit-1.2.0-cp311-cp311-macosx_10_9_universal2.whl (1.1 MB view details)

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

File details

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

File metadata

  • Download URL: warpkit-1.2.0.tar.gz
  • Upload date:
  • Size: 39.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.2.0.tar.gz
Algorithm Hash digest
SHA256 4b9d016f9d41106fe03711788ec55e2f109d63e40946b012143174391309086a
MD5 9b28bdbbc43262ff441f661caa4c0c1b
BLAKE2b-256 4fae161d5edbd6167b387a04d6c3895343658c79ddbeb2f5cd037c9777ebae34

See more details on using hashes here.

Provenance

The following attestation bundles were made for warpkit-1.2.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.2.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for warpkit-1.2.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 dd41d50d23103bf413c5ddc72cef08db2c3c1a76cc628d3ea5b4e4b96d3b7925
MD5 05768d89d3a657c87bd70f4702bda8ea
BLAKE2b-256 827e05acfe9cc56c5f43ec0a1448a9795c5193e01e144bd8f1444cec0d94206c

See more details on using hashes here.

Provenance

The following attestation bundles were made for warpkit-1.2.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.2.0-cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for warpkit-1.2.0-cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 4482fd72d650c87ec79c792baf364101bf27c6ca5b6a04fbb9566d79888ebf95
MD5 239e2ea6c0588af346c0e744abae088b
BLAKE2b-256 4fdd1ea3142f23803d5201e50734d81420ff19ef470e4b5228b55104ee113d88

See more details on using hashes here.

Provenance

The following attestation bundles were made for warpkit-1.2.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.2.0-cp314-cp314-macosx_10_15_universal2.whl.

File metadata

File hashes

Hashes for warpkit-1.2.0-cp314-cp314-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 315c1f2b7da10b5e9a78845f761250942cf9bf7ea19dd049f8aacedffc199619
MD5 f86d9a86c540800eb43bc581f5b78c47
BLAKE2b-256 c48750bcad777e36f589f2eaddf97148ddcae7ade1a8cb90b88ba5eba28e47de

See more details on using hashes here.

Provenance

The following attestation bundles were made for warpkit-1.2.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.2.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for warpkit-1.2.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d84d163cf13a8698213c7ba3cbf2f20e3797a052f14851a3e0f19b820469c979
MD5 48240ad36c57c6cf78784dd52dc351ff
BLAKE2b-256 2c822ee1bbc263c2f25b018574a8f5b40cd58c257b5d17f082126f67f6d6dd73

See more details on using hashes here.

Provenance

The following attestation bundles were made for warpkit-1.2.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.2.0-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for warpkit-1.2.0-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 169c99e4a2f302ed10dc890e8af0cae368780ef4c91a7010172e6c7f4466d405
MD5 1dfaadbfd5ba5e7a5e12f2fd2d2a4517
BLAKE2b-256 d5e568adc80b11ca34c96334bc9768007aeb98a52760d4c71d1c0dff13155940

See more details on using hashes here.

Provenance

The following attestation bundles were made for warpkit-1.2.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.2.0-cp313-cp313-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for warpkit-1.2.0-cp313-cp313-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 237a548fd25fb46b5283a2907be959657df18b7f64e07d3c2e4a14e7b9bb5df2
MD5 c96eacd6c01fcc623b4b13eaf2f53fe6
BLAKE2b-256 746b9e17f2a2967311cae7de229f9a254683d1ec1bc7f6e376d98095f6d49198

See more details on using hashes here.

Provenance

The following attestation bundles were made for warpkit-1.2.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.2.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for warpkit-1.2.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d5c96f1d3320d0f59b9c0bdb3caa56bc0689976e39f850e597cdb72c48eac67d
MD5 4d045ab12f3d4697d7e34b196d45c4f1
BLAKE2b-256 c3e1db42f1425aba0baea10978db033aed07139cae64b854d7ecf8625a68da80

See more details on using hashes here.

Provenance

The following attestation bundles were made for warpkit-1.2.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.2.0-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for warpkit-1.2.0-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 107c8a22c94c064a4c5e8512d0c7c922aac7d6b88a34495d769ecc1aaba15aaa
MD5 5200676876edce7969771d54b529404e
BLAKE2b-256 30d3e3eb631b1f70adc8021c4af7cd1a74484a647cd51336d177de0febb9c3be

See more details on using hashes here.

Provenance

The following attestation bundles were made for warpkit-1.2.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.2.0-cp312-cp312-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for warpkit-1.2.0-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 a4e44f57cd280fab25b60bdda623da6459773d6411310683b0f1fcc0fb9880b5
MD5 e1cb48728ce9ddeeda1bd96b657d8c68
BLAKE2b-256 2c841c92d41f37e85d356bfb47f386396c7144657520f5d1e9ed7a5b8e4f9a41

See more details on using hashes here.

Provenance

The following attestation bundles were made for warpkit-1.2.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.2.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for warpkit-1.2.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1468e8753200250a25c504af926fa06763b220d3095be888763637b3c4199369
MD5 f57ba1d851c670ebc1b863c21f559ea4
BLAKE2b-256 e4d462b5358183f972642932f0379b77ad49c7c1e4a06a9835a7348daba0d914

See more details on using hashes here.

Provenance

The following attestation bundles were made for warpkit-1.2.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.2.0-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for warpkit-1.2.0-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f39a93db856c76411141f7a5212a9db87c3c461aa5913d763c1759aa33f7b8e9
MD5 442cb72ff50a2973d9fd9484df783282
BLAKE2b-256 6d681e80bdd010e6eb344644a43d6dba7590b9587c1b45390b49672a8d250bb6

See more details on using hashes here.

Provenance

The following attestation bundles were made for warpkit-1.2.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.2.0-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for warpkit-1.2.0-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 c9a2053cc1509340b79dc59fe9b7874c220220bdd8818d672baa9d708671155a
MD5 5eef579ea6552601acd52a2d5b7de1bc
BLAKE2b-256 0c058b38d2bb467b74d66499da45bf9a1374008ca08e8017b909edcf7f95352d

See more details on using hashes here.

Provenance

The following attestation bundles were made for warpkit-1.2.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