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.1.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.1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (757.2 kB view details)

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

warpkit-1.2.1-cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (699.0 kB view details)

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

warpkit-1.2.1-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.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (757.2 kB view details)

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

warpkit-1.2.1-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (698.8 kB view details)

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

warpkit-1.2.1-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.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (757.4 kB view details)

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

warpkit-1.2.1-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (698.8 kB view details)

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

warpkit-1.2.1-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.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (756.2 kB view details)

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

warpkit-1.2.1-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl (697.9 kB view details)

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

warpkit-1.2.1-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.1.tar.gz.

File metadata

  • Download URL: warpkit-1.2.1.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.1.tar.gz
Algorithm Hash digest
SHA256 626b0fd057ef4da2e19e51498cccd94dc947110c8fc2c1c70113a6963912ac61
MD5 f9bf1642a15ab49ed4e8897f70dde83d
BLAKE2b-256 e51e405495fc6ac1fa4261fa2512466a455eff1e1db9573693556243a5e6f1bc

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for warpkit-1.2.1-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8d492fa6770af3806e28835c4c6272a227a2d391fe6a9d9bc9163a9707c6337a
MD5 cfc64b931ca5c54c77b3bcaa73584eb1
BLAKE2b-256 acda19044aa4f0296d7bc36deca4f7e189bde93f603b9bac93410d980b948634

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for warpkit-1.2.1-cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 fae0d3280c49cc529890349334370dbc0adfd8f14102a8bd0baffe923cb0f876
MD5 f67c59e2403b52f3c1f58518e09ea092
BLAKE2b-256 91c526e37ce477ea1170999396310a4594a4ebbe999c90963469618ec7830c5d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for warpkit-1.2.1-cp314-cp314-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 7aa2a2e61720298dca3f7401a5725379a49bc683e3ca24e4f2c918d7359a240b
MD5 296f4bcd8857e351fdc9ffa78ed81eef
BLAKE2b-256 24fe793d64ff38ab0151974dd14e961f9e408e3cf53ea70f4a3cfdcc95d66602

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for warpkit-1.2.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 528f97a8f5816cb12e7f749cb450fe4e77634d9c77a076d709e76d40d9bb6dc0
MD5 c305f260e0cf7dc422e588031867db7e
BLAKE2b-256 a391d9919681e286ceeb265f32cd10dd76361b388bc94ecdc4df195cd13dd988

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for warpkit-1.2.1-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 d36bc562af67765cef118ed6cc46e76498d12c7ed536f1b18b799f5323f671fb
MD5 aee7d18481c985ac9d575c73243bb376
BLAKE2b-256 8eda120995b9a3a8683eafbc79b261e41ca2d32826e2e94e2f68d6d89374561d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for warpkit-1.2.1-cp313-cp313-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 66f2ab5f59e4fb8a4acc05b8c7d4de781c4c11a2b34ccebe07363cca8ac92dbd
MD5 1cbc4d31992e74e2857abc55b7d448d2
BLAKE2b-256 2098779e82e6164712cd6421d945ecef8b5f802a342e41ef5e3cc4c6beaa0323

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for warpkit-1.2.1-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ccbffe94bef9ebaecd507e39e8c8b59184da3745a3c3a2f506a5eb3341f028b1
MD5 c449555d19e5f58c73a76624829e08a8
BLAKE2b-256 39ffb279045420056a817049a8f745f22f68085a11f01ff221ea22bc0dafebee

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for warpkit-1.2.1-cp312-cp312-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 ceb9817d24d25992bbbc8c5e28ebc98770fce7908c7ea38d8e79537963d1b338
MD5 c52d5a8181507226cad3b2cc15a0136c
BLAKE2b-256 408d76a9752861cd704a38dd0a528d4e3cdd4004da7fb667e70a86e29372a1d1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for warpkit-1.2.1-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 d4fe7d9be8b5d41ad99713ad5a05d5521cbcfbc59d6a7423452aa5136352ec6d
MD5 a40735e8284b4dec7223405da1b4f529
BLAKE2b-256 d566972d60f41a4f6e44023ed8011e27e720067502368e3db619c38bb035e6b5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for warpkit-1.2.1-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 83c24b87fbdbca33eb8daf048c18f85c7eb299d06ecbf4c8b0ce59bdc1545518
MD5 cdda355b53b46211d0f79a655cfee0b5
BLAKE2b-256 e57197ba8b379744d22ba6fe6cdc06277fb3802aa66fbfd6f06b5a854fdbb58f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for warpkit-1.2.1-cp311-cp311-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 a15828dea45720b99248f90e3703ad1d45ed5927da31c4b40afaa40c1f40b630
MD5 7ccedc874495b5eaa3f93ed11416d96a
BLAKE2b-256 73b51a438713f59e0df98a9b029301b21389d57b0c9d21107597bbeb0c42f194

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for warpkit-1.2.1-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 0b92a9dccf484c3fe968e3197d9f7f419924129113b918770c0a604a3bb3ba0d
MD5 c3fc5c22da2a7083fe178fb41626763e
BLAKE2b-256 3d8bc822c5eae8b0b7bc1e588618f1845c74f9fd38436602853c2021842be23b

See more details on using hashes here.

Provenance

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