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.5.0.tar.gz (24.2 kB view details)

Uploaded Source

Built Distributions

tiffwrite-2025.5.0-cp310-abi3-win_amd64.whl (531.4 kB view details)

Uploaded CPython 3.10+Windows x86-64

tiffwrite-2025.5.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (779.9 kB view details)

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

tiffwrite-2025.5.0-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (872.2 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ s390x

tiffwrite-2025.5.0-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (856.9 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ppc64le

tiffwrite-2025.5.0-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (814.9 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ i686

tiffwrite-2025.5.0-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (796.4 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARMv7l

tiffwrite-2025.5.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (772.8 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

tiffwrite-2025.5.0-cp310-abi3-macosx_11_0_arm64.whl (648.4 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

tiffwrite-2025.5.0-cp310-abi3-macosx_10_12_x86_64.whl (711.2 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for tiffwrite-2025.5.0.tar.gz
Algorithm Hash digest
SHA256 6a9ae21353b54bc27f9013dfac584d03e9fa0ae7544ac7ec13d60e748e66e1f8
MD5 5387ec672a6def6c4fbfceae97315b86
BLAKE2b-256 f38b7f104133c84ffce34e6f6ac557051cff240cb1e5ce27204f3d7f137c5af6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.5.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 37a26ec91174d1cf289136071a581d5f006ed2fe525c28c817bb96345931d5cd
MD5 a1c866931ab3e0f7f78118e4fa7470e8
BLAKE2b-256 4a101a240ced17102ea89574db19aab2365a5fdbd471ebbe64a0cf283686c30b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.5.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9cfc0483c4951a9ddf63a28e673f8740b0411645ffd2f4947cc0f40cd6d601e1
MD5 f10d5890920fbfcb5c4454682ae49cfd
BLAKE2b-256 51e42e7a8ebdcded85b8fab2b6fbd8bb27c8434724b99a725e928ecb7d653573

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.5.0-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 a6c263f1ecf5b809905547edc75814add9b3bd4c21455bf5ff10fde8e8eeab2d
MD5 52bdbc4baae32e601a1f6a37b51d403c
BLAKE2b-256 ab362838c69366d7d33caca22940db00cd56f56dada01c945ef9f2268e9e3673

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.5.0-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 54b55ebec986a9bc38619bcd140b62354dbdb18d0c495fdf42b4b5bc93862e95
MD5 cd9df586010b46f2a389a6ec8a944e9c
BLAKE2b-256 e1d00cfcba44a7db4f3a59ffd11b22c67ebe4c31510923572d7cf99d4c694229

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.5.0-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 fefa8530f13ee9589a3fa35387e8dbf35313ad8260c870c937fc3902f8405f59
MD5 6576ef74c52f9d1554b4fd11d0da5f8e
BLAKE2b-256 d46468b672c3290eee16b08831da518c2b08a89c9b083b8a117cc976e4c7c7e6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.5.0-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 455af0db0fbf53d19d3d5528d08857c78b07c5f85f7724f4af9cea9b622e6e53
MD5 ab14276953a38f316e4d6ecc3a20a83d
BLAKE2b-256 7e094c95ef737af78474f177b5b5c45cffd862edc8f1993b357357dbdd048a63

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.5.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 dca1c5d0e9e2aab0e0cb023ef59f5beb3e3b1158bcf6f6dd98f42bc66ea735cc
MD5 bdf9fe2640946c80eee78365fc602cb4
BLAKE2b-256 48d4b4a6c1c9ca817a594d5938e1ef0f8a70925aa06f38ff36fe5acf1d61e366

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.5.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6557e8831269d675ed36c8394b71a06cb0bd0f90637099c4c2cbb3d79da977b6
MD5 9302aae162946581828413936436fc98
BLAKE2b-256 2cdd6a01afad880cc8e279ec4e2a7bd33031477b00e15ed3445ea74c6aff0579

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.5.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 a25f467e313627b487be6056a8dfb2eb46f84d5bdf509e5c60ac6cbb9efe852d
MD5 cfed7ff4601692803e0ee0c4447da8dd
BLAKE2b-256 bd7ad15820f4f618709a458161a036242affe9123a16e216c4d0a05ec03e4f30

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page