Skip to main content
PyTARQUIN Logo

PyTARQUIN

A lightweight Python wrapper for TARQUIN spectral fitting in MR spectroscopy

Python License

PyTARQUIN is a lightweight Python wrapper that streamlines the use of TARQUIN for MRS fitting. It handles flexible data input, writes TARQUIN's input files, manages the TARQUIN executable for you, and parses its results (with single- and multi-core processing).


Features

  • Zero-setup binaries — the TARQUIN executable is resolved automatically (download, container image, or your own path); nothing is bundled in the wheel.
  • Flexible input — NumPy arrays, NIfTI-MRS (files, objects, and batches such as NIfTI-MRS+), jMRUI text, and LCModel .RAW, in time or frequency domain.
  • Every TARQUIN option — any command-line option by name, an LCModel .basis, or TARQUIN's internal basis simulated for your echo time.
  • Batch fitting — single- or multi-core, with full output parsing (concentrations, %SD, fit quality, and every other block TARQUIN reports).

Installation

From Source

git clone https://github.com/julianmer/PyTARQUIN.git
cd PyTARQUIN
pip install -e .

Add --recursive to the clone (or run git submodule update --init) to also fetch the ISMRM 2016 fitting challenge example data used by the tests.


How the TARQUIN binary is handled

TARQUIN is not shipped in the wheel. On first use it is found in this order, and the first one that works is cached:

  1. path2exec you pass to PyTARQUIN (or the TARQUIN_EXEC environment variable),
  2. a tarquin on your PATH (a distribution's package, say),
  3. the binary built by this repository's CI for the installed version (releases; Linux x86_64/aarch64 and Windows x86_64 statically linked, macOS arm64/x86_64 linking only the OS),
  4. the container image ghcr.io/julianmer/tarquin, if Docker or podman is running.

Each candidate is run once before it is accepted, so a binary that cannot run on your machine is skipped rather than cached. Useful switches: allow_download and allow_docker on PyTARQUIN, and the environment variables TARQUIN_EXEC (a binary of your own), TARQUIN_CACHE_DIR (where downloads are kept), TARQUIN_RELEASE_TAG and TARQUIN_DOCKER_IMAGE (another release or image), and TARQUIN_NO_DOCKER (set to anything: never use a container).

The binaries are TARQUIN 4.3.11, built from martin3141/tarquin at commit 47e9b98 with a small build-system patch (tarquin/); every build must reproduce the official 4.3.11 release on the 2016 challenge in CI, and the macOS and Linux builds fit it identically. To build one yourself: tarquin/build.sh (macOS, Linux, or Windows under MSYS2 UCRT64).

With the container, TARQUIN sees your working directory and your home directory; keep the basis set and any save_path under one of them. The image also works on its own:

docker run --rm -v "$PWD:$PWD" -w "$PWD" ghcr.io/julianmer/tarquin --input "$PWD/data.dpt" --format dpt --output_txt "$PWD/result.txt"

Getting Started

from tarquin_wrapper import PyTARQUIN

# Initialize the wrapper with your basis set (the TARQUIN binary is resolved automatically)
tarquin = PyTARQUIN(path2basis="/path/to/your/basis_set.basis")

# `data` can be a NumPy array of FIDs, a NIfTI-MRS path or object, a list of files, etc.;
# a water reference (one per spectrum) turns on TARQUIN's water scaling (mM)
concentrations, percent_sd = tarquin(data, water)

print("Signals:", tarquin.metabolites)
print("Concentrations:", concentrations)

Everything TARQUIN reported, one Report per spectrum:

report = tarquin.report(data)[0]
report.units                                  # 'au', or 'mM' with a water reference
report.sections["fit_quality"]["snr_max"]     # every block of TARQUIN's results

TARQUIN's internal basis and options:

tarquin = PyTARQUIN(
    echo_time=0.03,                            # the internal basis is simulated at it
    opts={"pul_seq": "slaser", "int_basis": "1h_brain", "max_iters": 50},
)

Data without acquisition parameters (NumPy arrays, .RAW) needs bandwidth= (Hz) and central_freq= (MHz).


Licensing

This wrapper (the Python code) is released under the Apache License 2.0 (see LICENSE).

TARQUIN itself is a separate program, (c) Greg Reynolds and Martin Wilson, distributed under the GNU General Public License, version 3 (see LICENSE.tarquin). This package does not bundle TARQUIN; when it downloads or runs the TARQUIN executable, that licence and the attributions in NOTICE apply, and those of the libraries the binaries link in THIRD-PARTY-NOTICES. The build scripts and patch in tarquin/ are part of the binaries' corresponding source and are GPL-3.0 as well; every release carries that source in full.


Acknowledgements


Built with ❤️ for the MRS community

Metadata

Release files for tarquin-wrapper 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tarquin-wrapper 0.1.0
File Size Uploaded
tarquin_wrapper-0.1.0.tar.gz 59.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tarquin-wrapper 0.1.0
File Interpreter ABI Platform
tarquin_wrapper-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 94.5 kB

Release files / tarquin_wrapper-0.1.0.tar.gz

Download URL tarquin_wrapper-0.1.0.tar.gz
Size 59.8 kB
Tags Source
SHA-256 checksum
How to use checksums
270c33dcd33092f9dc02012de037f29a06df2d6becab6adf1dee0a22a6ee8363
BLAKE2b-256 checksum
How to use checksums
7f8552f00fa6e232041f8a0383a7095d5718b8516bee3421e8a97e53a4245376
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / tarquin_wrapper-0.1.0-py3-none-any.whl

Download URL tarquin_wrapper-0.1.0-py3-none-any.whl
Size 34.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2ab8948980c7a0e2ac04d29aa47a39f34628c47f72f91a89c1631751f63e055e
BLAKE2b-256 checksum
How to use checksums
7b3b0c97fbf320dcd5d29ffd718b053b1c775469c30eb1b954b6412ec7e20a14
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

0.1.1

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page