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.wimpomp.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.5.1.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.5.1-cp310-abi3-win_arm64.whl (1.7 MB view details)

Uploaded CPython 3.10+Windows ARM64

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

Uploaded CPython 3.10+Windows x86-64

tiffwrite-2026.5.1-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.5.1-cp310-abi3-musllinux_1_2_aarch64.whl (1.9 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tiffwrite-2026.5.1-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.5.1-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.5.1-cp310-abi3-macosx_11_0_arm64.whl (3.2 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

tiffwrite-2026.5.1-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.5.1.tar.gz.

File metadata

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

File hashes

Hashes for tiffwrite-2026.5.1.tar.gz
Algorithm Hash digest
SHA256 506557c5bb1dcf985308530cec113213b1ec2d21bff164a0ea2b8682713ae16f
MD5 d4768985f7a80eb9006223efe431bdc0
BLAKE2b-256 d504cac2c717646292df70500c493289d7567e5a2e36643df74821a402e4d023

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2026.5.1-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 0691165bc0bb87398c52516e5eb255f09da95a7a655b223fdc881ea46d383aa0
MD5 9ef31f8f431914f09e08d2ce1f17fd41
BLAKE2b-256 7595a377158f923811492642cf08046f64a696dfc07af4f97f4158eb5dfdb498

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2026.5.1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 6b170ee226e9afe0c5caf4b766221f978c26dcee59c70cb512b5007f82e3f931
MD5 e8fa0d1257369c4086b326d0925333c7
BLAKE2b-256 d631b9892339be61a6bbc3a19a1c725ee74d01b64058dfd68541ab81e7200dca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2026.5.1-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b12244bb0f3f86e25c3ee40975b2528f9c5b762f10ca2e94be7264f49740dd3d
MD5 dcd2c80984746a3df07a0fcdd6e5a0aa
BLAKE2b-256 baba687c30aec8cecad9d0e768bea89134c638e06a61ade0ad2b5e5989d66b60

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2026.5.1-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 f44e172d76f7316ba2392f5fc4c0d1b0a42cf9ff6aeba67a3c8ab0701d1660f5
MD5 b1f257077ced7131f3a6d924edf0daf4
BLAKE2b-256 94bac9aa93170bf52bc94cc43a536010662cc6dee697c4017905390a9004adf3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2026.5.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ec3508ec2620af119db57a9a0dedb3f2a1a329de2228e9d899ee6a2dbee292eb
MD5 17da8c2c2bf8044701181b8fd2f12e9c
BLAKE2b-256 402393ad603dd5f67905eaab0d6c4dbf25495cbb1bd25b0183371e3cabbf4a86

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2026.5.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2afffcf8f7521a571b97da31fd48df57115754eb028bbb8f872574f877b429e4
MD5 8f5265e0d53010662075b65a4377668e
BLAKE2b-256 dcc88d7c3754bcec71933cefc6a33d563749442f5bdda9f3e79e8ff6e78870a0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2026.5.1-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0d606aea642da3818ab04d8142586f7ee6361213da122d3e260caf163914e2c4
MD5 db85eef5dc3d36636702097962336de3
BLAKE2b-256 043033d41594e26368afd0db8977b3ec89dfa02487164b09def28d3084329f26

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2026.5.1-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 67e5bbe00627fe6e77ced180ac226543f90c5473d528437421e2d76798b54edf
MD5 d52c03d7cfa2294867c31b68539988c4
BLAKE2b-256 9d0fc4500a1972ae879f17b86488cfe88dba962bb201b7022503f47d8ac5ef54

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