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.9.1.tar.gz (29.7 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.9.1-cp310-abi3-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.10+Windows x86-64

tiffwrite-2025.9.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.5 MB view details)

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

tiffwrite-2025.9.1-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.6 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ s390x

tiffwrite-2025.9.1-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.7 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ppc64le

tiffwrite-2025.9.1-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (1.5 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ i686

tiffwrite-2025.9.1-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.5 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARMv7l

tiffwrite-2025.9.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.5 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

tiffwrite-2025.9.1-cp310-abi3-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

tiffwrite-2025.9.1-cp310-abi3-macosx_10_12_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for tiffwrite-2025.9.1.tar.gz
Algorithm Hash digest
SHA256 9d512881fe41a2cf88075a48b3995ede5cd4d3378eabc4382baff024c178c277
MD5 4098fa7ac9f46c3b520c631292b2c4bb
BLAKE2b-256 9aca0585387d6b6839b649f8a1e0ad2b60628f61ee5a0a1462f9169f6effdc74

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.9.1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 11491994d0525ac64c31415b0dcf62d6421b237842ef6aa06f17cb2d42cfeaef
MD5 bbee4789b04247ec2edf857bf3a5a2d7
BLAKE2b-256 f55ed2c1833255691d872831f7ac8ab63e06ef921d796731a97002d391640f9b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.9.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 792b81f0e985e0e0643cd4d167fc2e27695f1f1dbc3b920390be555acf2b9b50
MD5 eb44d574c30448532763bf0e4bf63e12
BLAKE2b-256 c09b776cdbbfabc8ad8f757016d545de31346909984b6152478f386f1c5c19f5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.9.1-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 71a80e5f9bbe6e95ff38a6895d565b7649be1be36cb53d504991d8575b382093
MD5 69ff9970af0942eb5845a0062b4f26b2
BLAKE2b-256 6d8505948d17573e8b785e5214ccaa8a352f078680b98463ce5b3f0012a355bf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.9.1-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 9131f17155d4519c8720d64823b3e7d5478d6b7ffde4b1b057a4650d2489f372
MD5 616e1304e438b0e6f8e5bc2891bbf48e
BLAKE2b-256 875bceff534774cd6ad77821e7f6b3838d8dd3a920d660b108f00665fbc64c73

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.9.1-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 9931d09bf67f666c485e75d7315de5046d070be2535d705752955c7f0c4b7eed
MD5 4e5a47e3a5297b7fc9a874260a185c4f
BLAKE2b-256 43f5ce88e6bbee431e1426a8e5aa08db5d1d0829abc6d357e1466ec7fac1008d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.9.1-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 b51546fe13c048d56cfd28b5f2819eca59d20220082fb05a5c5e49db0a8717f1
MD5 73341bdc373978764e5f86906e125846
BLAKE2b-256 32221f01b37cf6c85affaf532293e2bb65bfee5983fc2505c53718d40a26fd48

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.9.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1f1072f82ee1b9502e900dcf4871c81293410ee313a3a5797a34306d1f1c4034
MD5 239749c0815e56df36c3e729d04d5868
BLAKE2b-256 6ce4efdfcec1d5f96d85b9f75cbe4953d144276198d19a6d2c2cf1035e49041f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.9.1-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b0811a34673b932a123409013583f43e9a7a769c4ac147c585299009b3c30a11
MD5 8c767e61f8c2691c5d2443c9e79aac44
BLAKE2b-256 ce3dfacdf399defb6e917d982436c963f9ea40c93718521403d1a94106709349

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.9.1-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 f22b752f91ede6fbed647ec3775511db10d69f6c4ae07ee33e978d9e443e6f39
MD5 ab4aa31e908337f65dabf04f895b09c8
BLAKE2b-256 97936091d66d35c5b85330cbcea86a83647442bb2525deafdb84eca012939ea3

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