imzy
imzy provides a common reader interface for imzML, Bruker, and Waters imaging mass spectrometry data. It includes tools for reading spectra, extracting ion images, computing common normalization factors, exporting centroid tables to HDF5 or Zarr, and converting supported inputs to imzML.
See the documentation for the quickstart, usage guides, runnable examples, API reference, and benchmarks.
Installation
Install the core package with pip:
pip install imzy
Optional storage and plotting extras are available when you need them:
pip install "imzy[hdf5]"
pip install "imzy[zarr]"
pip install "imzy[plot]"
pip install "imzy[all]"
imzy requires Python 3.10 or newer.
The Zarr backend requires Python 3.11 or newer and Zarr 3 (zarr>3,<4). On Python 3.10, the all and test
extras include the core, HDF5, and plotting dependencies; Zarr support is omitted.
Rust imzML backend
Release wheels include a Rust backend for memory-mapped spectrum access, pixel iteration, TIC calculation, and ion images. Installing a wheel needs no Rust compiler. The XML parser and metadata cache remain in Python.
from imzy import IMZMLReader
with IMZMLReader("sample.imzML", backend="auto") as reader:
print(reader.backend) # "rust" when available, otherwise "python"
mzs, intensities = reader.get_spectrum(0)
images = reader.get_ion_images([734.569, 760.585], ppm=10, silent=True)
Use backend="rust" to require the extension or backend="python" to select the fallback. Arrays are read-only;
call .copy() for writable data. Aligned arrays use views into the file and unaligned arrays are copied safely.
Keep the dataset unchanged while a reader, returned array, or iterator exists. close() releases the reader's mapping;
existing arrays and iterators keep their mappings alive, including any file locks held on Windows.
Source installations build the extension automatically when Cargo is available. To require it, install the stable Rust toolchain and run:
IMZY_BUILD_RUST=1 pip install .
IMZY_BUILD_RUST=0 pip install . explicitly selects a compiler-free installation. PowerShell users can set
$env:IMZY_BUILD_RUST = "1" before running pip install .. Compilation failures are reported rather than silently
producing a fallback wheel. Supported input arrays are uncompressed little-endian float32, float64, int32, and int64.
Rayon parallelizes bulk extraction; set RAYON_NUM_THREADS before starting Python to limit its worker count.
Ion extraction expects m/z arrays in ascending order.
Supported Formats
| Format | Support |
|---|---|
imzML (.imzML/.ibd) |
Windows, macOS, Linux |
Bruker TSF/TDF/NeoFlex (.d) |
Windows, Linux, macOS (with pytsf) |
Bruker BAF (.d with analysis.baf + *peaks.sqlite) |
Windows, Linux |
Bruker rapifleX (folder with .dat, _info.txt, _poslog.txt) |
Windows, macOS, Linux |
Waters MassLynx (.raw) |
Windows |
Bruker TDF ion mobility data can be read, but imzML export currently writes spectra collapsed to the m/z axis.
Bruker on macOS
Bruker ships no timsdata library for macOS, so imzy reads .d data there with
pytsf, when it is installed:
pip install "pytsf @ git+https://github.com/VU-MSRC/timsMac.git@main"
Differences from Windows/Linux:
- TSF spectra are identical; m/z agrees to about 1 ppm.
- TDF intensities are the values stored in the file (the vendor library scales them by an undocumented per-file factor).
- TDF 1/K0 is approximate (about 0.3% with reference ions in the file, a few % otherwise); voltage conversion is not available.
- Recalibrated states (
use_recalibrated_state=True) are not applied.
Python Usage
import numpy as np
from imzy import get_reader, write_imzml
path = "path/to/dataset"
reader = get_reader(path)
# Read one spectrum by pixel index.
mzs, intensities = reader.get_spectrum(0)
# Sum spectra across selected pixels.
summed_mzs, summed_intensities = reader.get_summed_spectrum(np.arange(100))
# Iterate through spectra. Each item is an (m/z, intensity) pair.
for mzs, intensities in reader.spectra_iter():
...
# Create a 2-D total ion current image.
tic_image = reader.reshape(reader.get_tic())
# Extract one ion image, using either a tolerance in Da or ppm.
ion_image = reader.get_ion_image(885.549, ppm=10)
# Extract many ion images in one pass.
target_mzs = [885.549, 886.552, 887.555]
images = reader.get_ion_images(target_mzs, tol=0.05)
# Export any imzy reader to imzML.
output_path = write_imzml(reader, "converted_dataset", silent=True)
Useful reader properties include n_pixels, image_shape, x_coordinates, y_coordinates, xyz_coordinates,
mz_min, mz_max, is_centroid, rois, x_pixel_size, and y_pixel_size.
Command Line Usage
The imzy command can convert any supported input to imzML:
imzy convert path/to/input path/to/output --silent
Common options:
imzy convert path/to/input path/to/output \
--spectrum-type auto \
--ibd-mode auto \
--normalization TIC \
--overwrite
Use --roi to export a specific Bruker TSF/TDF/NeoFlex/BAF/rapifleX region of interest:
imzy convert path/to/bruker.d path/to/output --roi 0
Run imzy convert --help for the full list of options.
Normalization and Batch Exports
Readers can compute normalization multipliers for common strategies such as TIC, RMS, median, percentile-filtered TIC, and vector norms:
normalizations = reader.get_normalizations(silent=True)
tic_scales = normalizations["TIC"]
For larger extraction jobs, write flat centroid tables to optional HDF5 or Zarr stores:
target_mzs = [734.569, 760.585, 782.567]
hdf5_path = reader.to_hdf5("centroids.h5", target_mzs, ppm=10, silent=True)
zarr_path = reader.to_zarr("centroids.zarr", target_mzs, ppm=10, silent=True)
Install imzy[hdf5] or imzy[zarr] before using those storage backends.
imzML Writing
Use write_imzml for reader-to-reader conversion, or IMZMLWriter when you need to add spectra manually:
from imzy import IMZMLWriter
with IMZMLWriter(
"manual_export", pixel_size=(50.0, 50.0), spectrum_type="centroid", ibd_mode="processed"
) as writer:
writer.add_spectrum([100.0, 101.0], [10.0, 50.0], (1, 1))
writer.add_spectrum([100.0, 101.0], [20.0, 30.0], (2, 1))
Writer options include spectrum_type, ibd_mode, coordinate_origin, normalization, indices, overwrite, and
on_error.
Plugins
Custom readers can be registered through the imzy.plugins entry point. Implement the imzy_reader hook and return a
reader when the input path is supported:
from __future__ import annotations
import typing as ty
from pathlib import Path
from koyo.typing import PathLike
from imzy import BaseReader
from imzy.hookspec import hook_impl
class YourReader(BaseReader):
"""Reader for your custom imaging format."""
@hook_impl
def imzy_reader(path: PathLike, reader_kwargs: dict[str, ty.Any]) -> BaseReader | None:
"""Return a reader when path points to a supported dataset."""
if Path(path).suffix != ".yourformat":
return None
return YourReader(path, **reader_kwargs)
Then expose the module from your package metadata:
[project.entry-points."imzy.plugins"]
your_project_name = "your_project_name.imzy"
When get_reader() is called, imzy registers built-in readers and then loads installed plugins from this entry point.
Development
Install an editable build, including the optional native extension:
uv pip install -e ".[test]"
Run the main checks before opening a change:
uv run pytest
cargo test --manifest-path rust/Cargo.toml
cargo fmt --manifest-path rust/Cargo.toml -- --check
See CONTRIBUTING.md for contribution guidelines and SECURITY.md for reporting security issues.
Performance benchmarks
The benchmark website tracks Python and Rust performance across main revisions using Airspeed Velocity (ASV). It covers reader initialization, spectra, ion images, TICs, normalizations, and imzML, HDF5, and Zarr exports. Results publish after main changes and weekly; pull requests run correctness and smoke checks.
See the benchmark guide for setup, local runs, methodology, and GitHub Pages initialization.
After editing Rust sources, rerun the editable installation to rebuild the extension. The standalone backend comparison also remains available:
uv run python scripts/benchmark_imzml.py --output benchmark.json
The benchmark generates varied continuous and processed spectra, warms Numba and the OS page cache, consumes complete
spectra, resets TIC caching, validates results, and alternates backend order. It reports median latency, pixel throughput,
and speedups. Use --pixels, --points, --targets, and --repeats to change the workload.
See the benchmark report for local measurements and their methodology.
Documentation
Build the documentation in a separate environment:
uv venv .asv/docs-env --python 3.12
uv pip install --python .asv/docs-env/bin/python --group docs
.asv/docs-env/bin/python -m mkdocs build --strict
.asv/docs-env/bin/python -m mkdocs serve
On Windows, use .asv/docs-env/Scripts/python.exe. See the
documentation development guide for examples, checks, and Pages setup.
License
This project is licensed under the BSD 3-Clause License. See LICENSE for details.
Citation
@misc{imzy,
author = {Migas, Lukasz G. and contributors},
title = {imzy: A reader and writer interface for imzML and other imaging mass spectrometry formats},
year = {2022},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/vandeplaslab/imzy}}
}
Metadata
Release files for imzy 0.4.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 | Provenance | Actions |
|---|---|---|---|---|
| imzy-0.4.0.tar.gz | 32.9 MB | Without provenance | Details for imzy-0.4.0.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| imzy-0.4.0-cp310-abi3-win_amd64.whl | CPython 3.10 | abi3 | Windows x86-64 | Details for imzy-0.4.0-cp310-abi3-win_amd64.whl |
| imzy-0.4.0-cp310-abi3-manylinux_2_28_x86_64.whl | CPython 3.10 | abi3 | Linux glibc 2.28+ x86-64 | Details for imzy-0.4.0-cp310-abi3-manylinux_2_28_x86_64.whl |
| imzy-0.4.0-cp310-abi3-macosx_11_0_arm64.whl | CPython 3.10 | abi3 | macOS 11.0+ ARM64 | Details for imzy-0.4.0-cp310-abi3-macosx_11_0_arm64.whl |
| imzy-0.4.0-cp310-abi3-macosx_10_12_x86_64.whl | CPython 3.10 | abi3 | macOS 10.12+ x86-64 | Details for imzy-0.4.0-cp310-abi3-macosx_10_12_x86_64.whl |
Total release size: 96.3 MB
Release files / imzy-0.4.0.tar.gz
| Download URL | imzy-0.4.0.tar.gz |
|---|---|
| Size | 32.9 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bff7ffdb8acc623354e63f083675820eafecc231f2dd7178dfd96f79eda6cdfd
|
|
BLAKE2b-256 checksum How to use checksums |
ac9056f757471ec69e490ee4d3c003e60b9e3f74721e956e973fbf78d9a38158
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / imzy-0.4.0-cp310-abi3-win_amd64.whl
| Download URL | imzy-0.4.0-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 15.7 MB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
e16bd2bd721ba36efc686a730d05e6f93cb8c9e958954cc1aa68917a90ebaf01
|
|
BLAKE2b-256 checksum How to use checksums |
bf723eeb980eec88bc3a4c7ff8754a0d256d92a2d3f8b77390f0b559c440c747
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / imzy-0.4.0-cp310-abi3-manylinux_2_28_x86_64.whl
| Download URL | imzy-0.4.0-cp310-abi3-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 16.0 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
ff398351633c618109dab0ff8404918b4a8245a338a8dfae322b7193f0a96bd5
|
|
BLAKE2b-256 checksum How to use checksums |
5774e664fe93dd1de00446dcc154523eec86a2e621bec7d23c57ba6b8b4cf61a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / imzy-0.4.0-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | imzy-0.4.0-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 15.9 MB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
6a309b484446249fb2385ef092bcd939bbae8c25334575ee118982fc20e4d241
|
|
BLAKE2b-256 checksum How to use checksums |
89fb48fa9a08b21886d3b66437622fc11ee28d99e35da4ad3eebfb2e58457bf5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / imzy-0.4.0-cp310-abi3-macosx_10_12_x86_64.whl
| Download URL | imzy-0.4.0-cp310-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 15.9 MB |
| Tags | CPython 3.10 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
252b9bd7541025e086da4e348e68aa09797821e8eebdbb88675bff8375070179
|
|
BLAKE2b-256 checksum How to use checksums |
1d4924484c9ba085ac5355d5f4500d000e3de2f284a75341f40a2213b5e6c316
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Security for imzy 0.4.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.