trxscan
Python bindings for TRXScan, a headless diffusion-MRI simulator (MITK Fiberfox physics in Rust) with realistic single-shot EPI artifacts: susceptibility distortion, T2/T2* decay, eddy currents, Nyquist ghosts, partial Fourier, Gibbs ringing, k-space spikes, multi-coil reception with GRAPPA, k-space noise, head motion and multiband dropout, gradient nonlinearity, synthetic GRE fieldmaps, and the closed-form ground truth of the same object.
pip install trxscan # wheels for Linux, macOS, Windows; no compiler, no system libs
pip install "trxscan[dipy,trx,viz]" # dipy gradient tables, TRX streamlines, ODX export for TRXViz
Four nouns, one verb
import trxscan as ts
from dipy.core.gradients import gradient_table
from dipy.io.gradients import read_bvals_bvecs
phantom = ts.Phantom.load("sub-60501") # real anatomy: tissue maps, 1M streamlines, measured fieldmap, motion traces
gtab = gradient_table(*read_bvals_bvecs("my.bval", "my.bvec")) # your scheme, in dipy's object
proto = ts.Protocol.HBCD.replace(voxel_mm=2.5, coils=8, accel=2) # scanner settings; presets are instances
art = ts.Artifacts(noise=2e-4, ghost=0.015) # everything off by default
sim = phantom.simulate(gtab, proto, art, slices=40) # one axial slice, every volume: a few seconds
sim.magnitude # nibabel Nifti1Image (nx, ny, 1, n_vol) with the slice's true affine
sim.phase # radians
sim.kspace.acquired # (n_vol, 1, coils, ky, kx) complex64 as acquired (pre-GRAPPA); .reconstructed, .combined, .mask
sim.readout # EPI line timing: ky order, t_ms per line, total_readout_ms
sim.to_bids("out/sub-60501_dir-AP") # the same files the trxscan CLI writes
truth = phantom.microstructure(proto, gtab, slices=40) # 27 ground-truth maps (fa, md, mk, rtop, icvf, odi, ...)
The unit of simulation is a slice: the acquisition stage is exactly per slice, and the signal
stage rasterizes only what crosses it, so a single slice of the full phantom under a 76-volume
scheme with 8 coils and GRAPPA takes about four seconds. Ask for slices="all" (or a range)
for a volume.
Real head motion, real acquisitions
motion = ts.Motion.from_confounds("sub-01_dir-AP_desc-confounds_timeseries.tsv") # qsiprep/eddy
moving = phantom.simulate(gtab, proto.replace(mb=3), ts.Artifacts(motion=motion, dropout=0.1), slices=40)
moving.dropout # which shots dropped, and by how much
real = ts.BidsDwi.load("sub-01/dwi/sub-01_dir-AP_dwi.nii.gz") # sidecar + header -> gtab and Protocol
sim = phantom.simulate(real.gtab, real.protocol, ts.Artifacts(noise=1e-4), slices=40)
Single voxels, like dipy.sims, with real artifacts
v = ts.Voxel(fibers=[((1, 0, 0), 0.6), ((0, 1, 0), 0.4)], wm=0.8, gm=0.15, csf=0.05, tissue="adult")
v.signal(gtab, te_ms=88).total # per-compartment T2, exact directions (matches dipy's single_tensor)
v.truth().fa, v.truth().mk # what a fit should recover (FORCE closed forms, dipy-validated)
v.signal(gtab, motion=motion) # fibres rotated per volume: the b-vector rotation problem in one voxel
ts.Voxel.noise(v.signal(gtab).total, 0.02, coils=8, accel=2) # magnitude noise through the real coil combine
obj = ts.objects.fill(ts.objects.box(8, matrix=32), v) # the voxel inside a small object
acq = obj.simulate(gtab, ts.Protocol.HBCD.replace(voxel_mm=2.0, coils=8, accel=2), ts.Artifacts(noise=2e-4, ghost=0.02))
acq.magnitude, acq.series((16, 16)) # Gibbs ringing, PF blur, ghost, GRAPPA noise on a box
Conventions
- Volumes come back as
nibabel.Nifti1Imagewith qform and sform set; k-space ascomplex64with the phase-encode axis first ([..., ky, kx]). - Everything is deterministic in
Artifacts(seed=...); a slice simulated alone is bit-identical to that slice of the full run, andto_bidsreproduces the CLI's files. Artifacts()is the clean reference.Protocol.DEFAULTis the simulator'sAcquisitiondefault;Protocol.HBCDis the HBCD-like protocol the CLI ships.- Partial Fourier behaves like a scanner: the train skips its first lines and reaches the
k-space centre sooner (
Protocol.readout(...)shows it); lowerte_msyourself to bank the TE gain.pf_mode="contiguous"restores the legacy tail-dropping rule. - Set
TRXSCAN_DATA=/pathto use a local copy of the phantom bundles instead of downloading.
Building from source
pip install maturin
cd python && maturin develop --release # in a virtualenv
The extension depends only on the std-only simulation core (kspace,par features); file
I/O is done in Python (nibabel, trx-python), so no HDF5 or cmake is involved.
Metadata
Release files for trxscan 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 | |
|---|---|---|---|
| trxscan-0.1.0.tar.gz | 401.3 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| trxscan-0.1.0-cp311-abi3-win_amd64.whl | CPython 3.11 | abi3 | Windows x86-64 | Details |
| trxscan-0.1.0-cp311-abi3-musllinux_1_2_x86_64.whl | CPython 3.11 | abi3 | Linux musl 1.2+ x86-64 | Details |
| trxscan-0.1.0-cp311-abi3-musllinux_1_2_aarch64.whl | CPython 3.11 | abi3 | Linux musl 1.2+ ARM64 | Details |
| trxscan-0.1.0-cp311-abi3-manylinux_2_28_x86_64.whl | CPython 3.11 | abi3 | Linux glibc 2.28+ x86-64 | Details |
| trxscan-0.1.0-cp311-abi3-manylinux_2_28_aarch64.whl | CPython 3.11 | abi3 | Linux glibc 2.28+ ARM64 | Details |
| trxscan-0.1.0-cp311-abi3-macosx_11_0_arm64.whl | CPython 3.11 | abi3 | macOS 11.0+ ARM64 | Details |
| trxscan-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl | CPython 3.11 | abi3 | macOS 10.12+ x86-64 | Details |
Total release size: 7.7 MB
Release files / trxscan-0.1.0.tar.gz
| Download URL | trxscan-0.1.0.tar.gz |
|---|---|
| Size | 401.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
762cff6b55cc15254e82616ec69bcc6fef273aca8160caff4f8ac26fd9da4a80
|
|
BLAKE2b-256 checksum How to use checksums |
47726245a390607fbd2653384f2bdb8993b821057e23af9808da9aff12b28537
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 28, 2026.
Transparency logRelease files / trxscan-0.1.0-cp311-abi3-win_amd64.whl
| Download URL | trxscan-0.1.0-cp311-abi3-win_amd64.whl |
|---|---|
| Size | 884.8 kB |
| Tags | CPython 3.11 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
86400bc19d7e84fe9249931d68618f4f5bb8a916a788751700c5f100aa83d4eb
|
|
BLAKE2b-256 checksum How to use checksums |
13123a1fb4aef24461348b2676070f6a3825cbb99cbda084f55d75b8ea8d05d6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 28, 2026.
Transparency logRelease files / trxscan-0.1.0-cp311-abi3-musllinux_1_2_x86_64.whl
| Download URL | trxscan-0.1.0-cp311-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 1.3 MB |
| Tags | CPython 3.11 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
31d3f0fa67ef11ed5728b1269846d8829e858c91971a46bfed2ffb4dd21a9e8d
|
|
BLAKE2b-256 checksum How to use checksums |
9e2650900277916a9d71adb6c8a1ebc26df768738339020e3ae43821c7d58f77
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 28, 2026.
Transparency logRelease files / trxscan-0.1.0-cp311-abi3-musllinux_1_2_aarch64.whl
| Download URL | trxscan-0.1.0-cp311-abi3-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.11 Linux musl 1.2+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
4a3a3a21d937c7ee5c831750dde8180f677fbe6aee089096072ab8274bf313ba
|
|
BLAKE2b-256 checksum How to use checksums |
daa3902e56dd9ece7daf2082ace6287bac883968cc8a0418a587e1dfba8dfaaa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 28, 2026.
Transparency logRelease files / trxscan-0.1.0-cp311-abi3-manylinux_2_28_x86_64.whl
| Download URL | trxscan-0.1.0-cp311-abi3-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.11 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
e08a94e9d41ead0fa3996ccfb4f73e65f89155fb95893edc46ca32d2dc1e196f
|
|
BLAKE2b-256 checksum How to use checksums |
1c791e6671609e3c2498cccd68ac32cc648dadbff8dbdb9ad62bc38971831ba5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 28, 2026.
Transparency logRelease files / trxscan-0.1.0-cp311-abi3-manylinux_2_28_aarch64.whl
| Download URL | trxscan-0.1.0-cp311-abi3-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 962.6 kB |
| Tags | CPython 3.11 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
2c07c4d5f5753613cad9fd0b0afcf75bcee83c961b79ab4d562bb863b4825249
|
|
BLAKE2b-256 checksum How to use checksums |
ace040e7289495799fa707ca7244c72cfddfb33a5389bfe7c56e4ee0f1927601
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 28, 2026.
Transparency logRelease files / trxscan-0.1.0-cp311-abi3-macosx_11_0_arm64.whl
| Download URL | trxscan-0.1.0-cp311-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 891.7 kB |
| Tags | CPython 3.11 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
f3584a3820e1685faabf26a18a6fa9d82757f3bedd6751d457678459085e5c1a
|
|
BLAKE2b-256 checksum How to use checksums |
a0ff3d2d86c928e4b9be259c6db14654e424caa9b69d8d41d50a47fffb720014
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 28, 2026.
Transparency logRelease files / trxscan-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl
| Download URL | trxscan-0.1.0-cp311-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 984.3 kB |
| Tags | CPython 3.11 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
8529bbabf0bdc4e767cfaa81a75b11013c2dc7fbc2af2311ad65a5da25f9b8a6
|
|
BLAKE2b-256 checksum How to use checksums |
64e65b478d161118dca9ea076fc94afdbc8a135aac248965a8e03046e61e078d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 28, 2026.
Transparency log