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-2026.5.0.tar.gz (35.3 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.0-cp310-abi3-win_arm64.whl (1.7 MB view details)

Uploaded CPython 3.10+Windows ARM64

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

Uploaded CPython 3.10+Windows x86-64

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

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tiffwrite-2026.5.0-cp310-abi3-manylinux_2_34_x86_64.whl (2.2 MB view details)

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

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

Uploaded CPython 3.10+macOS 11.0+ ARM64

tiffwrite-2026.5.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.5.0.tar.gz.

File metadata

  • Download URL: tiffwrite-2026.5.0.tar.gz
  • Upload date:
  • Size: 35.3 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.0.tar.gz
Algorithm Hash digest
SHA256 9760fe86eedf0646f282cf8e5c337b20f43c6a2264db38a180c604eca19bffec
MD5 d2c87fc99a5e42daecc34ed55fe299f6
BLAKE2b-256 e60055dc9118973faaca1aec1acb1cff9613d1f7003c344c040dca055d7e4779

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2026.5.0-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 55a5a5c778baa23d94a0d2abe823b59a6a4368c12cbe526c71125343807587e6
MD5 4b10f505d51bb90bcf8fd377c6df77dc
BLAKE2b-256 dc75e62ec4bb9301f9d099c767efa58706825f1b6b67a7f25486527f9c4b2563

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2026.5.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 dea6d1ad76c1b41fc61e5685ed0c5e5ea42721fbb1aefef179df3d109097e15b
MD5 1189e76cd303107f39ea0c42b5f3371a
BLAKE2b-256 927a68114a7bfd5ce2709e542fff5fea460adafb07e4fc8e261edcb8efddf1a1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2026.5.0-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 8b4993a28c27912f0e8c241801cd0f41bbffacc9e6e04afd3c0ecd2b5aac1e0c
MD5 7a2d864c838927af746533fc94a4ec17
BLAKE2b-256 377432bdee9a5555d4fdd6e73e4b708e267401e35e99eb8d4f1468e9ca4756c1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2026.5.0-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 42a23785182d06bd0c30951eff53fdaa8cf30b13acff61b2687b598158af3ab2
MD5 ee61ee2791e7dd76474cb22218499a05
BLAKE2b-256 e85a23122ee10f3245d818ea92c3931a36f42333a3d58900e471de43106ea1d1

See more details on using hashes here.

File details

Details for the file tiffwrite-2026.5.0-cp310-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for tiffwrite-2026.5.0-cp310-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 ebee0f7bd0daebcfaae21b66a689bffc0128bc00f184db3d16b7757c5392e1cc
MD5 55a286592f9b2c1e074fba4971780e7f
BLAKE2b-256 ba4325eedbb2ed761507511415731db18957261bda82bdf9203d5a8ad93e3121

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2026.5.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1cd234e2355978a8846f23364a07792dedb07f2ef3e3d05174dd4eaccb847e88
MD5 0ee781aafd243c82765397ec850aab55
BLAKE2b-256 4ec1bb744165a36493ba87377d3c76791788391a18cbfd5f2e8d58458b95c3d2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2026.5.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 32cb3f81aaa82d8501b12a310a32d1f687fbee2517b9c67d49e7666673d7ce6f
MD5 59641d9dc6a471c732bdc6428c0bd3fb
BLAKE2b-256 b9587bd0be001e9c2f36348c385670d3dcdcc52e0dbc4d4e0e4b545a314f927b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2026.5.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 790efa00cac31613ba8b74d19dba29925bb4b68031a46a12e7b144e7a232e025
MD5 44a2dcca4e1fee1f7b6d43f66f287cc1
BLAKE2b-256 a5390032cf87389714149d3db525cfc625feab3a827bd6893d69e57c465b284a

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