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.12.0.tar.gz (29.4 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.12.0-cp310-abi3-win_amd64.whl (1.3 MB view details)

Uploaded CPython 3.10+Windows x86-64

tiffwrite-2025.12.0-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.12.0-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.12.0-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.12.0-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (1.6 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ i686

tiffwrite-2025.12.0-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.12.0-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.12.0-cp310-abi3-macosx_11_0_arm64.whl (1.4 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

tiffwrite-2025.12.0-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.12.0.tar.gz.

File metadata

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

File hashes

Hashes for tiffwrite-2025.12.0.tar.gz
Algorithm Hash digest
SHA256 1e52c251780e8cf67e422c2a1293efc9745216fcc81971906e555c54fc1fddd2
MD5 46ac5e1a94f53759637fe04ec00736df
BLAKE2b-256 7568ff1c52325ef1bfb8233ce5be0c7a3d64e1eeab7ae4c9c0350927c009eb48

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.12.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 37577b94ec5060896f9a62f80fb7e524ef4e6d7cebab9f52f79fec364360ad4c
MD5 130384394587bd07797abf635219f901
BLAKE2b-256 8a4600cc07dc9dd3907b80abbcfac4390bcbbd160dbb83296de9e1b6f9145150

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.12.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 75778238a2f9587e625a3ba52f2ad0dc07422cfd318efea45bc57970aee0ce89
MD5 8b1e83a03e927292d630c8f00e199307
BLAKE2b-256 a571b5d2b0ac3abbae9f96236eba04cc7d864c0efa44c5ca09adfc081a3f95f4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.12.0-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 9e2a652914c514132ffd4514f4f2ce95c8a7def6185fdd2454cf75e582ef51c2
MD5 7e921ec3c1d10a81d253702e7311e41a
BLAKE2b-256 2bd945064335150a5f5df2b177fa057d0514fe2af27fcc94d635b7162e0b28b8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.12.0-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 236e0c31911eb137473ea21f44400497c72d27fc46290a0e7c35017dca5d16bd
MD5 64f89a700a25fd190baf0d1e0ef32b95
BLAKE2b-256 8088ee003711869af048dbddcf209d902c719bbaee7f673d23687a015bde81a2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.12.0-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 8cbc6818deb93ce7a146324070931e5469c05876fdcaf2845481dd44925b7713
MD5 d464c7cdc2e484f55b68100c6dd12d89
BLAKE2b-256 93a622079fed2af00303aae846b79e9b9e12b260e17da9566f77d07068e81c94

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.12.0-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 aaa0d6670b52daba7940176f5cffac7dc8c412788b49a1b5c2947585955854f6
MD5 bafbf383bea22600d2b7c678bdff91d4
BLAKE2b-256 604a1d74eded982a88190d93b93d53fcff1468c1c60dc30dd0d57eac95f420ae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.12.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e23331094b43faeb63c665e8661f737cbf24de1fffeac38c394510ba3daa5553
MD5 b547651f09e5f760f50d0f028bfc0bfb
BLAKE2b-256 3c4c96e7143d339155a68b58b477c72d67a8630c6d2528f5c73db5ab122cebbd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.12.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f6b012e9612980f4aad70d515990be151878b16a4f95c683a76149c971b553f8
MD5 e949909766c0f50fe1837da72284c902
BLAKE2b-256 5627bec143b8439f43f89d372fb498ccdee435611ff08c64cd8baa8b2ce9d40b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.12.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 760961d25934b3a37ef90b25f7f68c94bcd3e0c383ab997c0a7d049694ccf36d
MD5 dc0768ba2465fe8e8f26e3caface2577
BLAKE2b-256 6844cf6c02bab416c50767720fe8cb7d8956803defe68d80842263bcef75612a

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