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.

Installation

pip install tiffwrite

or

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 or not to show a progress bar.
  • args, kwargs: arguments to be passed to IJTiffFile, see below.

Write one frame at a time

with IJTiffFile(file, shape, dtype='uint16', colors=None, colormap=None, pxsize=None, deltaz=None,
                timeinterval=None, **extratags) as tif:
some loop:
    tif.save(frame, c, z, t)
  • file: string; filename of the new tiff file.

  • shape: iterable; shape (C, Z, T) of data to be written in file.

  • dtype: string; cast data to dtype before saving, only (u)int8, (u)int16 and float32 are supported.

  • 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.

  • extratags: other tags to be saved, example: Artist='John Doe', Tag4567=[400, 500] or Copyright=Tag('ascii', 'Made by me'). See tiff_tag_registry.items().

  • 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

shape = (3, 5, 10)  # channels, z, time
with IJTiffFile('fileA.tif') as tif_a, IJTiffFile('fileB.tif') as tif_b:
    for c in range(shape[0]):
        for z in range(shape[1]):
            for t in range(shape[2]):
                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)

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

Uploaded Source

Built Distributions

tiffwrite-2024.10.6-cp310-abi3-win_amd64.whl (485.4 kB view details)

Uploaded CPython 3.10+ Windows x86-64

tiffwrite-2024.10.6-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (739.0 kB view details)

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

tiffwrite-2024.10.6-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (818.4 kB view details)

Uploaded CPython 3.10+ manylinux: glibc 2.17+ s390x

tiffwrite-2024.10.6-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (806.0 kB view details)

Uploaded CPython 3.10+ manylinux: glibc 2.17+ ppc64le

tiffwrite-2024.10.6-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (757.3 kB view details)

Uploaded CPython 3.10+ manylinux: glibc 2.17+ i686

tiffwrite-2024.10.6-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (753.5 kB view details)

Uploaded CPython 3.10+ manylinux: glibc 2.17+ ARMv7l

tiffwrite-2024.10.6-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (739.5 kB view details)

Uploaded CPython 3.10+ manylinux: glibc 2.17+ ARM64

tiffwrite-2024.10.6-cp310-abi3-macosx_11_0_arm64.whl (602.2 kB view details)

Uploaded CPython 3.10+ macOS 11.0+ ARM64

tiffwrite-2024.10.6-cp310-abi3-macosx_10_12_x86_64.whl (661.1 kB view details)

Uploaded CPython 3.10+ macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for tiffwrite-2024.10.6.tar.gz
Algorithm Hash digest
SHA256 75d47c67d232e566238517fb99552b9cb3e2dcd5769b1fb65f7f2b587c1998a8
MD5 a3f454cd338e9fae58ed9d59c5546ba3
BLAKE2b-256 dc8268eb774b3ec602c34a260531afdf25acc0555f633ab18bbaa34456af1861

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2024.10.6-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 2dca267210280225fc82bb717109f3041f18484c0eb640cde72909ac15bdf73e
MD5 81f35acce5a940d3c1891b9e2845d6e6
BLAKE2b-256 7af907848a5c126de7a36602791369c510a98981aa96a5b19fd7a3d1ff182525

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2024.10.6-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f32f4c2f3535fa8d9d487715be1b266a6989cca7fbae3e2bcd992a1bac139e48
MD5 9038c29124ddc9823f646d3e64e5363a
BLAKE2b-256 8c67ef481d91eba7881c10ae20aa31e5f4cef409f64b717d2c0f42b028fff7f2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2024.10.6-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 cfcf8df113244be03c8ee9f29f7afd709361b571ba02be8c5819319458c9cf58
MD5 e0012225c6b988c3c1bfe09099a45db2
BLAKE2b-256 a3e324485c1ebd214898e44e215241361a1b51faf65f98214b2b80ff3fb0f9d3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2024.10.6-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 fd92811a93103d0aa075b4cf463110bda8b754accedb326a4bf0d16de031c56e
MD5 abbe179e35876d82ec70620af8eed0ba
BLAKE2b-256 48b4e709006a88703d26bb997f68d1b81c6130dcac7a8a0f3b72814b935e44a5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2024.10.6-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 cabb6e523b582260600b375ad0aac5992eb4609d57727a85810661de32fe22f4
MD5 bd3f662f22db5e7cd089f65d625fe002
BLAKE2b-256 e6c53e2cec3504dd7d76558cbc7dc44a679eb26ea5b088e9d45dc37663469d68

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2024.10.6-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 1659b13b4eed16cf8d9881ee1d9aecc64ef341ff7d11eeb9eb8e7fb26f61d4f1
MD5 9e22c3e0bbf8fd2029a17bd618867976
BLAKE2b-256 0fb0b4e4c50e4b67a8da834abbc2ddd23963f3871d3a5bf6fbe210ef22bbd944

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2024.10.6-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c8a1c763df537d08fd8eb3357fb06c6ee166d215b36458b9228edcb92a893419
MD5 0d9b8dad22b8e114fcda5b1cd7ea0001
BLAKE2b-256 f9fe6397b402c2446ebb736afe7094a04797a6eff97cd87b71cdb40f8e9202b2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2024.10.6-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 03511e5fe4df8d103ec0f01db05c6ca39a900020eee64c9fca56a6bc7ff51c0e
MD5 17a6f84106ed5529a9e3c035e9f6ff4f
BLAKE2b-256 62e62cea4b1656109e17f7db675faf1da2c816e8c987907295519e729326276d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2024.10.6-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 e654d8841ebcd5c03c61bbd22d79315497d7bcba3a27cc2823ba8c71daa36d2e
MD5 a38e0cbed75e74136beefe7560022897
BLAKE2b-256 a68c98347e4bfb6cfbe97f8ec990ad3b0faec0f9067114448a3b1996ace3f194

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