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

Uploaded CPython 3.10+Windows x86-64

tiffwrite-2026.1.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.7 MB view details)

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

tiffwrite-2026.1.1-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.8 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ s390x

tiffwrite-2026.1.1-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.9 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ppc64le

tiffwrite-2026.1.1-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (1.8 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ i686

tiffwrite-2026.1.1-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.7 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARMv7l

tiffwrite-2026.1.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.7 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

tiffwrite-2026.1.1-cp310-abi3-macosx_11_0_arm64.whl (1.6 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

tiffwrite-2026.1.1-cp310-abi3-macosx_10_12_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for tiffwrite-2026.1.1.tar.gz
Algorithm Hash digest
SHA256 afdded4318847c9e15e8dac1be2ac3b1dd72cf3fe8c74f1ce45688b742613c2d
MD5 4a3a665e0ee886e5466b82dd69c43604
BLAKE2b-256 b30d494d25ffae3084bef5ec6a57697baae6766075ddb855e02d3f02fe792528

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2026.1.1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 25880f8c5e538c27430ec6d58157b1c1d199e4708cb7b86995968fed9f1ad6dc
MD5 3ce3a2724a2c2c678b04af94832f2869
BLAKE2b-256 7a69c1f35cfa1d4dc97c919dfb5d02760e0b5ebfc113f2b70bfcab5c2997bd7d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2026.1.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 306e09763ff836de20bab2ccefbe78b261fc49e4ad3a95cd32608fe11f8e3b52
MD5 197d019b20faf5d8914212ca4e2e8d0b
BLAKE2b-256 ac1ea462995fbb333c56b24d1fd2cd89bbd68740a89330c4d255e9c1959a279a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2026.1.1-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 a0f65513814a27315640876aa75927c92b354f75bea019bf8034f3c044aa0de0
MD5 0ea4ae177e8136eb94ac053fd55521b5
BLAKE2b-256 9583dbce36208f0285ef91cb003465d2770795b2519bbc5e36013c621df51a13

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2026.1.1-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 983e46b0fc216a58289e8e50a649f4a595a4c0771403bc34476457d61afc5bd4
MD5 7f1628e2870b7868a83f592f81e795e1
BLAKE2b-256 629197f410d6b092ffd88dee7a2561b99e0b968436727481a446de64a59ea4c2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2026.1.1-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 ed18bdf0d05ad1dfa0d7ffd05409647de28760bda55f963cf2052f87ca8b2891
MD5 794b31538264b59272eae2d04d0cc4b3
BLAKE2b-256 f3612fd2a875400d35505e11424167498d06090203e8582b385766687c8a7825

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2026.1.1-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 08a74a7c592afb6a59f211437d02d7773a50ef5176c63cb6f0356eb3f578e877
MD5 14a306dbf94544e0569d1feb9b459066
BLAKE2b-256 f55806c8ed19785d816bd7aaeb993527990f582d4f7df25bfac403461b570ec9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2026.1.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 67c9eb8573cb43dd22b91d7ba370a4b7e2a489403e25a3a8865354c6266aa795
MD5 3ac8fd96ea003a3201478ac6e3b27f6e
BLAKE2b-256 790689570799c885b0117dc160377a89e0084f128284432f409cb51d24bc3fcc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2026.1.1-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 381e17616759008ebb5eb38de301a0229dad42fef8845d828fdf31692639ea76
MD5 2a1dc15071693ddf3f24c1dd302b5a47
BLAKE2b-256 550da7f538a751e49e07b5e4e68b9b7c65482344e080163580a96a111c795e3c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2026.1.1-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 f177cff7538f0f8943e4f93e1d0686847173ef92a18d7100e72f16b99075b025
MD5 e33410b974cba695e904947d269c2fd1
BLAKE2b-256 3f409f9cd50c9a634c7757daa774b6b7a40bfd07e05c0ce2c5168d36f40d0965

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