Skip to main content

Write BioFormats/ImageJ compatible tiffs with zstd compression in parallel.

Project description

pytest cargo test

Tiffwrite

Write BioFormats/ImageJ compatible tiffs with zstd compression in parallel using Rust.

Features

  • Writes bigtiff files that open in ImageJ as hyperstack with correct dimensions.
  • Parallel compression.
  • Write individual frames in random order.
  • Compresses even more by referencing tag or image data which otherwise would have been saved several times. For example empty frames, or a long string tag on every frame. Editing tiffs becomes mostly impossible, but compression makes that very hard anyway.
  • Enables memory efficient scripts by saving frames whenever they're ready to be saved, not waiting for the whole stack.
  • Colormaps
  • Extra tags, globally or frame dependent.

Python

Installation

pip install tiffwrite

or

  • install rust
  • pip install tiffwrite@git+https://git.pomppervova.nl/wim/tiffwrite

Usage

Write an image stack

tiffwrite(file, data, axes='TZCXY', dtype=None, bar=False, *args, **kwargs)
  • file: string; filename of the new tiff file.
  • data: 2 to 5D numpy array in one of these datatypes: (u)int8, (u)int16, float32.
  • axes: string; order of dimensions in data, default: TZCXY for 5D, ZCXY for 4D, CXY for 3D, XY for 2D data.
  • dtype: string; cast data to dtype before saving, only (u)int8, (u)int16 and float32 are supported.
  • bar: bool; whether to show a progress bar.
  • args, kwargs: arguments to be passed to IJTiffFile, see below.

Write one frame at a time

with IJTiffFile(file, dtype='uint16', colors=None, colormap=None, pxsize=None, deltaz=None,
                timeinterval=None, **extratags) as tif:
some loop:
    tif.save(frame, c, z, t)
  • path: string; path to the new tiff file.

  • dtype: string; cast data to dtype before saving, only (u)int8, (u)int16 and float32 are supported by Fiji.

  • colors: iterable of strings; one color per channel, valid colors (also html) are defined in matplotlib.colors. Without colormap BioFormats will set the colors in this order: rgbwcmy. Note that the color green is dark, the usual green is named 'lime' here.

  • colormap: string; choose any colormap from the colorcet module. Colors and colormap cannot be used simultaneously.

  • pxsize: float; pixel size im um.

  • deltaz: float; z slice interval in um.

  • timeinterval: float; time between frames in seconds.

  • compression: int; zstd compression level: -7 to 22.

  • comment: str; comment to be saved in tif

  • extratags: Sequence[Tag]; other tags to be saved, example: Tag.ascii(315, 'John Doe') or Tag.ascii(33432, 'Made by me').

  • frame: 2D numpy array with data.

  • c, z, t: int; channel, z, time coordinates of the frame.

Examples

Write an image stack

from tiffwrite import tiffwrite
import numpy as np

image = np.random.randint(0, 255, (5, 3, 64, 64), 'uint16')
tiffwrite('file.tif', image, 'TCXY')

Write one frame at a time

from tiffwrite import IJTiffFile
import numpy as np

with IJTiffFile('file.tif', pxsize=0.09707) as tif:
    for c in range(3):
        for z in range(5):
            for t in range(10):
                tif.save(np.random.randint(0, 10, (32, 32)), c, z, t)

Saving multiple tiffs simultaneously

from tiffwrite import IJTiffFile
import numpy as np

with IJTiffFile('fileA.tif') as tif_a, IJTiffFile('fileB.tif') as tif_b:
    for c in range(3):
        for z in range(5):
            for t in range(10):
                tif_a.save(np.random.randint(0, 10, (32, 32)), c, z, t)
                tif_b.save(np.random.randint(0, 10, (32, 32)), c, z, t)

Rust

use ndarray::Array2;
use tiffwrite::IJTiffFile;

{  // f will be closed when f goes out of scope
    let mut f = IJTiffFile::new("file.tif")?;
    for c in 0..3 {
        for z in 0..5 {
            for t in 0..10 {
                let arr = Array2::<u16>::zeros((100, 100));
                f.save(&arr, c, z, t)?;
            }
        }
    }
}

Tricks & tips

  • The order of feeding frames to IJTiffFile is unimportant, IJTiffFile will order the ifd's such that the file will be opened as a correctly ordered hyperstack.
  • Using the colormap parameter you can make ImageJ open the file and apply the colormap. colormap='glasbey' is very useful.

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

tiffwrite-2026.6.0.tar.gz (35.5 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

tiffwrite-2026.6.0-cp310-abi3-win_arm64.whl (1.7 MB view details)

Uploaded CPython 3.10+Windows ARM64

tiffwrite-2026.6.0-cp310-abi3-win_amd64.whl (1.8 MB view details)

Uploaded CPython 3.10+Windows x86-64

tiffwrite-2026.6.0-cp310-abi3-musllinux_1_2_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ x86-64

tiffwrite-2026.6.0-cp310-abi3-musllinux_1_2_aarch64.whl (1.9 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tiffwrite-2026.6.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

tiffwrite-2026.6.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.9 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

tiffwrite-2026.6.0-cp310-abi3-macosx_11_0_arm64.whl (3.2 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

tiffwrite-2026.6.0-cp310-abi3-macosx_10_12_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file tiffwrite-2026.6.0.tar.gz.

File metadata

  • Download URL: tiffwrite-2026.6.0.tar.gz
  • Upload date:
  • Size: 35.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for tiffwrite-2026.6.0.tar.gz
Algorithm Hash digest
SHA256 15ee6e1df6e1743084a091c238fd1f3f9fb7374e24c05254d04909ee06ae1b1b
MD5 e54f90e8eba01aee91f5ef54b1192bd5
BLAKE2b-256 abaeedb8bada7c1eb53bc2dc9aaa366815c7de05acec4f16ad3b09bb393afb19

See more details on using hashes here.

File details

Details for the file tiffwrite-2026.6.0-cp310-abi3-win_arm64.whl.

File metadata

File hashes

Hashes for tiffwrite-2026.6.0-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 9d8af68324f2c2565ff45e31a33cf5fe6ea9f8eeb12bc64a21e60ef3f306c29f
MD5 41f0e97590aad87417132543e62ecac4
BLAKE2b-256 365741645df36ca720ea43b3347df5d3f509ec297229ec91cb1c96827fa646d8

See more details on using hashes here.

File details

Details for the file tiffwrite-2026.6.0-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for tiffwrite-2026.6.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 60da8a3c078a2ad0d61ad84c7b80b13f925b5e936369ce43d9f68af58d9c85b9
MD5 27d18c18e6c7c40ec822f3a0029a1d17
BLAKE2b-256 18e8a43ffeab74bead7ea3573f7f2d483961824b700161dd0c7e24b21d4ac7eb

See more details on using hashes here.

File details

Details for the file tiffwrite-2026.6.0-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for tiffwrite-2026.6.0-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5bedc6f07177f108c31f4bdb98a7fcf57ad4f1a44a2d79f04f88c8549fc739cf
MD5 dcf8a2697fcc0f0afb792aabd92b2df8
BLAKE2b-256 1d774b90035230ffff0744cfad92587cc92618427a0e9225c63b468864891c8f

See more details on using hashes here.

File details

Details for the file tiffwrite-2026.6.0-cp310-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for tiffwrite-2026.6.0-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 1c1c8afb7e855cda5a22e02311270186bc1e7545415d3e88f85cf893e2b15151
MD5 6e930fa2062a0ed166e632e100c19c1a
BLAKE2b-256 15e7ae5c57f2956baa44b46ec44b96522431ad97be50a0f3527bf4d2666836c8

See more details on using hashes here.

File details

Details for the file tiffwrite-2026.6.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tiffwrite-2026.6.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 808762329ccf2e1be0e6ce9e64dc584afc6fc3039ffa0abe76c4565e7f9631a2
MD5 022c4a38639c911cee3cadeea28249e2
BLAKE2b-256 311b39f73005e3cf0bcafd56e5c2e88fc5cf7a80db867f3d2dbd3601e91b7aa8

See more details on using hashes here.

File details

Details for the file tiffwrite-2026.6.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for tiffwrite-2026.6.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 4b89e8319449beb9a0b91b8d7b4b487454f57ef30ca8b5521641a0c4c09dbb83
MD5 5bf1d4610368200fcbcfeaf94b24c869
BLAKE2b-256 8258e637db3e54bd4ca1e9248bbef2c66e28e29478c62c3e82266dbefa90db8d

See more details on using hashes here.

File details

Details for the file tiffwrite-2026.6.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tiffwrite-2026.6.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 aa993e42f9f27f3ad5b0b565a29d88d04760448c59b9f0d26bf605b219b99d2e
MD5 9eadddbbb9465dfe2490888b8b49e4e6
BLAKE2b-256 ee6ddfb9bb1a4644b7e88ae20f6b57a5716b47347c3166bd0f0c000766173b90

See more details on using hashes here.

File details

Details for the file tiffwrite-2026.6.0-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for tiffwrite-2026.6.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 c569636f0f7470d459b7b72c2f56dedb8817f075069ee30a83c6c7486a537bae
MD5 8049208cfb3300441610e5f9b305e9a9
BLAKE2b-256 2ab287bbbf0d797eda981fb31a60d14411efe24732c466516fc0dfc880af4435

See more details on using hashes here.

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