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.0.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.0-cp310-abi3-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.10+Windows x86-64

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

Uploaded CPython 3.10+macOS 11.0+ ARM64

tiffwrite-2025.9.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.9.0.tar.gz.

File metadata

  • Download URL: tiffwrite-2025.9.0.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.0.tar.gz
Algorithm Hash digest
SHA256 6149b93d1e72ffd3aa36d9d27d6b261e032fb4045d96480270f13074d9291aea
MD5 38b433039ba2b43a0fd9c755cd4e7e12
BLAKE2b-256 29cb963c7d1d56d42421bfb920e6f2d834d590921db2a815ee36b8381287f5e1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.9.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 445c89f914f6d0b99813dff23c5b19b90c72dbc29638d4fdb454baf95a5f913c
MD5 32d3dd9f3302909d3acb12cd88cf2b26
BLAKE2b-256 6951fc0013621046e06939da8b986d8731b027f54ae19ed9b10a6fbb482955ab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.9.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1495a247477f4db351b54f8f043aed9ba3ecc7d7c180464950fa7ac1cf875152
MD5 e300267d88e3a47ccd6c98730b452f78
BLAKE2b-256 ec13899bd912f881314bcc1cbab08124d17c6e1ce15c28819d0002b497fe8354

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.9.0-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 79b9d436441983bf0e05392de1cd682e1cd4069b81fe62d31991259202c5931a
MD5 9b0836583f5f2e06a73ebdee59fb86df
BLAKE2b-256 f2d401d6be2265db6c748d2a5734f6cc381633137e213e0b4b9067029d55644b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.9.0-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 6bc8f97cb1301916216b3d7cf9167e5aae890c300aea835815b3ef834374df4f
MD5 4b129e41137195f8bed2a48244510ab3
BLAKE2b-256 7e421fc19db97ea63588c0c944d4e49b011ed7e1f8e2b9bf959df2ea25a3dc7c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.9.0-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 77793a789909d5562add955350003fd059d7af7c21e0cc7d3509309af46b8540
MD5 238b0ca7651bf012bf2ba9adcf945eb6
BLAKE2b-256 ad3693c85ac62a53eb31443fc87c4d1abca393239f282098d1ecc1f0ee3b830b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.9.0-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 d73e23e4803fcec18773f329eb33b36591128b66e00e963b58eda973fc6d91ad
MD5 c727ac2ff9008d13a55f1abbf89f5f2e
BLAKE2b-256 89c2c46b7706683476446fc9c28b480c67cb93a14f06d4360e2b7a3e61d2faa6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.9.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 80cd4487d7e02b695ad40583a75af0a48694d9b10f8f4466f80b26035a092ab2
MD5 149cddc27974ef0b72fe9d21f2930939
BLAKE2b-256 fbe0d95052da648ff395d5868ab52adf0416fb875b282c4b609a2ab740d0bad5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.9.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8bc8823b8f34379a5a4e9420240acdff6cab9093646b0b731118eda68dc38cec
MD5 d719adf7695139ecb9c134532a44a8ce
BLAKE2b-256 96355209676545ed7586956bf3737f2b49852210349393b19bc82f21d5c42455

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2025.9.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 a5fa3ac1b0d686eb3ceaee5bf6d1e872341979d337a61072c796c9ea7eac3e7c
MD5 4e02bf0310b42018edcd81be0c9c84cf
BLAKE2b-256 44f76f85c917d20f6b8bf4a4da5b063384f33c935b737c669258620eab547e39

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