Skip to main content

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

Project description

pytest

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://github.com/wimpomp/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-2025.8.0.tar.gz (24.9 kB view details)

Uploaded Source

Built Distributions

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

tiffwrite-2025.8.0-cp310-abi3-win_amd64.whl (560.3 kB view details)

Uploaded CPython 3.10+Windows x86-64

tiffwrite-2025.8.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (820.6 kB view details)

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

tiffwrite-2025.8.0-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (885.1 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ s390x

tiffwrite-2025.8.0-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (962.3 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ppc64le

tiffwrite-2025.8.0-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (858.4 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ i686

tiffwrite-2025.8.0-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (830.7 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARMv7l

tiffwrite-2025.8.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (806.5 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

tiffwrite-2025.8.0-cp310-abi3-macosx_11_0_arm64.whl (682.5 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

tiffwrite-2025.8.0-cp310-abi3-macosx_10_12_x86_64.whl (744.3 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: tiffwrite-2025.8.0.tar.gz
  • Upload date:
  • Size: 24.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.9.3

File hashes

Hashes for tiffwrite-2025.8.0.tar.gz
Algorithm Hash digest
SHA256 0251516a101a6f64de049bb868c6df59193ef28b5aac5a4ae3012235283c2463
MD5 66e74b09d0279eb857ffc943007b9673
BLAKE2b-256 80a08f2920dcfeedfaaf4c612e8d48909fdd47ad9246fe759f09a0b0d1829225

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.8.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 cd5f3a0a841646fb19e80eeaede0bad1027d0c7a63622528b1e5935025d35850
MD5 4602439e5af94b0a3f64379af7b4c1ea
BLAKE2b-256 83ccf19e90e1e152f826fa62b711377a7fbb0af901c8fab668c2fc8bc524d470

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.8.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2ee0ba1c9af5ccba8e505189eca38a40d187bdc80a53f156347a739a82bddd8b
MD5 f818f6fadd097ebb49862844f619fe64
BLAKE2b-256 1844b368c4c85f7311d942c9e39f407dedb47c4b0795165a9644b76c35d42cac

See more details on using hashes here.

File details

Details for the file tiffwrite-2025.8.0-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for tiffwrite-2025.8.0-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 59b03faf6803d28fb4164e6d70f49f96fff404180818b0352f67c286124fcf4a
MD5 bd32b8826d1ebf729ce1348baf25aa55
BLAKE2b-256 7841968016b12a2a3aa0fe8927c66a9e2d1a0c220e6d8f45af742150718a4bd4

See more details on using hashes here.

File details

Details for the file tiffwrite-2025.8.0-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.

File metadata

File hashes

Hashes for tiffwrite-2025.8.0-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 e388657bb773f1a388f184273bddbed9cfbc4a0563ec48f1db90246246d126fb
MD5 fc033ac85ca0ef5ad5ab23c2798b2432
BLAKE2b-256 fcbd138ddfa6efef7de325048dfab3e13f79d61491f2c3db653c914cee12d2cf

See more details on using hashes here.

File details

Details for the file tiffwrite-2025.8.0-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for tiffwrite-2025.8.0-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 4cadd10eec25550ea1a4b25754eadf2f68d1cf74059b6b4efcd65ce2a27f891e
MD5 a22b266457c27bcad579714c13a11e68
BLAKE2b-256 b8283eb821636135d2cd359807c6acfa085abdc79bebb7fa15b91016bc02729c

See more details on using hashes here.

File details

Details for the file tiffwrite-2025.8.0-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for tiffwrite-2025.8.0-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 636dce726cda7ee3eb7c739ea909f435b372f9d404bab752ae36610585be1a36
MD5 c631a861dbeb2b1b75f2626130bc50e0
BLAKE2b-256 acda71f013f44318b35538930a00437d18921b7a2d3e394537ee3dede2a0f3b1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.8.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 07dfb3ad9ac50948379c9ae247db4e25c55281eff7d958538eef5785ec3a0fb5
MD5 74182000e6f8f519cdf209793ffe696a
BLAKE2b-256 9d7a6cb92132e245496fff0a12a577338e4898f1a9f3e8ba0e653183464b6c9f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.8.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a5b58f1c5d2e0530e8b33339ea542d0c02d9c216ba2e07647fef049277ac1c33
MD5 b3057d56b1860a77ef69f2ffc12b2d42
BLAKE2b-256 2fd99a0304156290e0d70d58d3510d0a70aa78e635e156b5f4388706a2020be6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.8.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 f76c1a3b45d780b5e0654db631df10857f4d41ea5dcc121dc5aea365e1c9dec2
MD5 5cd22334990ca138f3e60a1d82940e13
BLAKE2b-256 1e47574c1e5f928897956e07f62c7245314e4e8fd0f2ee0fa400bd1adcb521d5

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