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

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.0.1.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.0.1-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.0.1-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.0.1-cp314-cp314-macosx_10_15_universal2.whl (29.4 MB view details)

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

warpkit-1.0.1-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.0.1-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.0.1-cp313-cp313-macosx_10_13_universal2.whl (29.4 MB view details)

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

warpkit-1.0.1-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.0.1-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.0.1-cp312-cp312-macosx_10_13_universal2.whl (29.4 MB view details)

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

warpkit-1.0.1-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.0.1-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.0.1-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.0.1.tar.gz.

File metadata

  • Download URL: warpkit-1.0.1.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.0.1.tar.gz
Algorithm Hash digest
SHA256 7eb015625ab15b1ec0d43bd623c36174279c6ec21f5028ef7cf1b43028677dc0
MD5 e522a97824dfe52e84116b142749d232
BLAKE2b-256 4104da194249b4a7dc2b870d93ac44fbfc39bb432f368c72fa7c3a75de738926

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for warpkit-1.0.1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ea873a01f403fd77d8fd163b9c227b7fb58a6bf59ce375808275d63ac56b0515
MD5 7d171c80aeb6daa826a99f4c17d79461
BLAKE2b-256 b7d9d3d9bd8feae7e00bf646c08abb51b42b9d7f538d5507a6734c001dcabf24

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for warpkit-1.0.1-cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 48731f2e2431944b969f33bf541fb92d25b78770e0b424275f1d2903d552afd1
MD5 bb5d2f7e85177fcf99e56a24047ff489
BLAKE2b-256 b2c7b26f6007739f0cc6789a94d8d6b7be589081f49ad3bdfcee70941871d567

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for warpkit-1.0.1-cp314-cp314-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 338d88d59cbe1041533140119d2d48d8bce15a851bdc73a4d0bc35eed0d0b09f
MD5 bcf463ee9e5405d873f89914150706f7
BLAKE2b-256 c4d872922f492f477216e42aa67ccecb5e3e760a8f6deddb072f7d34f9a788f4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for warpkit-1.0.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bcd71451ad2be2a01f83dc68629a35a0b937ba1222eab6fe02ee28b0fd6c4e17
MD5 0223f0b8d770785861aab37ac89184b9
BLAKE2b-256 4ddf6c0392aed8e7ffcf4b7d24811a58e601b0727a421a180c05064f41076459

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for warpkit-1.0.1-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 6beabb351d002721b0b81d8ec22757766944181dceee72e37b1a7f90e12ef6b7
MD5 cb688dede195886ee8e388467de45757
BLAKE2b-256 10ac9f94704a1c9b5fcb4ee488c26f9e87d0c1340d857d0747a5018687bb6a9e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for warpkit-1.0.1-cp313-cp313-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 a132b9af8abcc49b237f0af265443e2c2c9da8616c6ce3b6524da60f570934ad
MD5 741ed10418978964c728c4b4244470c3
BLAKE2b-256 9f4e667f2df66d47d445b9ac01a024d2c9e4eb10a937bd8dbb27229756caba22

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for warpkit-1.0.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ae423760e9a85a1a437b30441d0fb73819c22a1c6df2a9b5d58e1589bf8d5483
MD5 6643cc89ee8b939951effdf6261b1e92
BLAKE2b-256 2bf8c3e4d289f7a70f3f5091c0e0a887df157424aad4debca1ea52dc3f978fc8

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for warpkit-1.0.1-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 20f512df7a9dfd6b3413a0d17b2543a2ed29033fb63879042bc5eef786e3745e
MD5 85acc6c1f97a18ed5774ed289e8b4005
BLAKE2b-256 c9911785acb499ac752318cec00fa821249331d61c339eb735dd13157009a498

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for warpkit-1.0.1-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 597fbee1774ce3c1ce7cab513726cffdb7775b07bc7a47f4b3b98d34b1efdbd4
MD5 00ff27253f0abc0a72a5f35bd039af1d
BLAKE2b-256 4a4bebbf80f5f4051bf030136f4aac53d4029ad31699e1964ae50b2bc77f5904

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for warpkit-1.0.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 742bad34f0a21f3e061e20eb0d2dc2f1ba11768c716c98779f4307f9c7a96027
MD5 13e356e59fc5918662c090ac408abc55
BLAKE2b-256 2e1d9fa0729b975d0cbcae37e6950a0785683e021b45d488d2c4deb97a00e3ae

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for warpkit-1.0.1-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 2aefc41b4bd254295f8017e065c832d06dc6c7ee4e23fb846f1365467fa35a3f
MD5 60c4d6b5b0c1cca41ae957beb7c2b2f9
BLAKE2b-256 14a3a1ef235d1163308d9e2fc65d7a91536ce8a48604bd0b312aa52924efc02a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for warpkit-1.0.1-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 acdc888cd2981240e5ea80ae9e149943ecdbaa80fe326e1a8e0f97dc91cbb870
MD5 4745bc4b2dca0f42520695f19e123c4c
BLAKE2b-256 56a86019bbcf1fa5d4f6860ad3e805b341875c0e465fadf92a7c767f68dc7bde

See more details on using hashes here.

Provenance

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