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

Uploaded Source

Built Distributions

tiffwrite-2024.11.0-cp310-abi3-win_amd64.whl (480.8 kB view details)

Uploaded CPython 3.10+ Windows x86-64

tiffwrite-2024.11.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (721.4 kB view details)

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

tiffwrite-2024.11.0-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (808.6 kB view details)

Uploaded CPython 3.10+ manylinux: glibc 2.17+ s390x

tiffwrite-2024.11.0-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (790.0 kB view details)

Uploaded CPython 3.10+ manylinux: glibc 2.17+ ppc64le

tiffwrite-2024.11.0-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (741.3 kB view details)

Uploaded CPython 3.10+ manylinux: glibc 2.17+ i686

tiffwrite-2024.11.0-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (730.5 kB view details)

Uploaded CPython 3.10+ manylinux: glibc 2.17+ ARMv7l

tiffwrite-2024.11.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (711.5 kB view details)

Uploaded CPython 3.10+ manylinux: glibc 2.17+ ARM64

tiffwrite-2024.11.0-cp310-abi3-macosx_11_0_arm64.whl (586.3 kB view details)

Uploaded CPython 3.10+ macOS 11.0+ ARM64

tiffwrite-2024.11.0-cp310-abi3-macosx_10_12_x86_64.whl (649.0 kB view details)

Uploaded CPython 3.10+ macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for tiffwrite-2024.11.0.tar.gz
Algorithm Hash digest
SHA256 a907c4abc8a736e5cadb87333beb22514f9f2f2a859efdd103cb10f926860e8f
MD5 caf21f6ec70b335a4f2abaac932b9b7a
BLAKE2b-256 dfb0046f9fc024c456c747e10bf4d3fcaff5bdb1694a03f697b17c048c195f59

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2024.11.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 09a064de8cd098bf11d40c24418d87c524f466ba489b316341aa3251667732b1
MD5 34fd88a85190f880da8f486ff4c98a6e
BLAKE2b-256 3c5deec61f166e1005ed0e205534722a8e0972d8bce7730481c96b4ce6202d64

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2024.11.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 42e13e8f718843424452d88df146f925d2ca901b500f1e861b70fb947c2da307
MD5 27d3775671574131cdd6db5888852abc
BLAKE2b-256 0ec251c4e40d025ccc67f78866b8163bc8ea72ad472b689e11768fd35309966d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2024.11.0-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 e983b0dd2c7c48e87803f7b13def4596022c49d7d694a07fe0b6277e285250da
MD5 277256f2e9f485a463761ac83796295d
BLAKE2b-256 6bb707b6027802c92a786dd88a2c1d4b43a0df439fce924074fcf21fb66da857

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2024.11.0-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 50ff9c904c347f1bace48c336cf38dc1582c2036e0f369abb0fdf5212f96486c
MD5 19a8cae286a3413b0f475f106a6477c8
BLAKE2b-256 ce16b514c627a574dccb8b4aef3d6f43b5e2080ec27ab0b28b1231b8b5a064f6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2024.11.0-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 7d55b3ec3aa5ff1e3298911aa2969be08f24b88367686f7ced3d6d15e4b6d68f
MD5 28904370f3c176220ae200be3cf61df9
BLAKE2b-256 a561baf765020007444d4043277f4c35168f28d29a20b3449f0b3cfe03fb7749

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2024.11.0-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 c04320de0d1d4dec7afb0aa0fd3927f1ab3aec72b8dbda4d0182cc5131bd9b7f
MD5 d60eb4cf262be4fb063167d17068f5cb
BLAKE2b-256 f9ee217a3d4ac5c6c337d028f3a37d392ffb0a8b67b8e45fbbbe186917b59abf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2024.11.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 80f5557d2928c0eb0d87a691b5dbb0f5f38c31a430622c1d6f6de0f30e6fa027
MD5 6217c74667b2e7e1c4695d22b4980266
BLAKE2b-256 a0c16885b69400af93a1978688a4a0b42c604873092c4d86d8fc15b6df31833f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2024.11.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 35faed37581a7115e18972e2d29f63d4fdb8cbe181362424127bd85b2e564a04
MD5 52fff6b8d560faee7392abe71d8a034d
BLAKE2b-256 ef14639169df4ad3c9bb5d0c3e1006cccd877341f1d62d9fa8065ed3c9ca7c75

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2024.11.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 6cab0fa21df57fe84d9467d73920ccb272dd582116f96917b4ba33af4a7e8601
MD5 8f1077e5449b5a94b83999d21eec4b86
BLAKE2b-256 8b31ae335c24fc56cc560d5f30e9daf5591928c38160f5ba31d39072b421feab

See more details on using hashes here.

Supported by

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