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

Uploaded Source

Built Distributions

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

Uploaded CPython 3.10+ Windows x86-64

tiffwrite-2024.10.7-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (739.1 kB view details)

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

tiffwrite-2024.10.7-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.7-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (805.9 kB view details)

Uploaded CPython 3.10+ manylinux: glibc 2.17+ ppc64le

tiffwrite-2024.10.7-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (755.9 kB view details)

Uploaded CPython 3.10+ manylinux: glibc 2.17+ i686

tiffwrite-2024.10.7-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (753.7 kB view details)

Uploaded CPython 3.10+ manylinux: glibc 2.17+ ARMv7l

tiffwrite-2024.10.7-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (740.2 kB view details)

Uploaded CPython 3.10+ manylinux: glibc 2.17+ ARM64

tiffwrite-2024.10.7-cp310-abi3-macosx_11_0_arm64.whl (602.8 kB view details)

Uploaded CPython 3.10+ macOS 11.0+ ARM64

tiffwrite-2024.10.7-cp310-abi3-macosx_10_12_x86_64.whl (661.2 kB view details)

Uploaded CPython 3.10+ macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: tiffwrite-2024.10.7.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.7.tar.gz
Algorithm Hash digest
SHA256 58f9568c81f41c61e75cf66d7f5c857309b3cc22af5a73c84421c344faae5727
MD5 b79117ef02cc7855c95af548c9944332
BLAKE2b-256 ea8526ce77e6e3795c7741bd5cf0eb0741bf1c99480ed5fe59f79cc3045edd9c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2024.10.7-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 fe6cfedd1c4a0428fbd7908b90ce1e7553631d53356f1c4641c985d561995aec
MD5 d8ea6dc13b702936d86b13caa4bd6b27
BLAKE2b-256 3b99ad1451d9c55b5967ab6b5430a397bb7b5bc4dc1bd0d1891fcd3805b171ab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2024.10.7-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9b094ddc8ebac50c737e7f9047699e040c30c400606e3d8f0436f4b6cb8dba84
MD5 4f97c2c02dcf1d48dd03089a15e8a43f
BLAKE2b-256 4231d1aa2240eca1a41801928812a1f10d380369c807511d7de792e36f4e31d8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2024.10.7-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 f2ecf24fbed35a21c5ecca3da528e68d0516aa0730f075302dfb7834232f3e9b
MD5 e80b9142a688434319a4742291401e29
BLAKE2b-256 57efd680a08700fe8c609e6a73479461225ccb130538802ca851bea8061ef137

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2024.10.7-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 dde8178b44e03386372cea7cfe3e2b024ea7f0986332353a531ccb232cbc3ff3
MD5 6ea9ac40e7dc693bbedf39a17f9db552
BLAKE2b-256 88debbdac5f5bd66940bec77ebd50e67bf7fca174a384cf43b397867b46d0812

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2024.10.7-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 565a31429450d52d46c8a42b3ebb2310036a188f52fbb98845ca1ac9f7b16ecd
MD5 fab5f42e5fb85eba5fbe18b519be03c5
BLAKE2b-256 b5b1fb61de63b6ee1d28eee2f9359e835a003a77db640b68ad335869f84af264

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2024.10.7-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 1a9cfed36ac9c8d15d7267cf481eaf9065860c18a0af954ba8bfc1725f7c427a
MD5 c28e1ad99f05b10aa2af737c31ad720c
BLAKE2b-256 9130dc6ced27ac07d8388e21db196d92699985b80e5543a3ef2affe550dc95f2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2024.10.7-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e63e4736b814723a08af8f12e52d71c99e25a0cddbcbfff22700eca2d95daee2
MD5 3ae4fcb5ded8fcfbd58924f31eab2958
BLAKE2b-256 313077a822cbb376041ba40d9b145b772ac36c40e0955b0ee473e91d8a16bc57

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2024.10.7-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 55015ab3717956c69f8cab007819e43b92185ec983b4e20a8f05eb442a26156c
MD5 ffcd1016c3e89450b70357867d929697
BLAKE2b-256 3a3735ce5a3a1df497d5c8f00a0e36b6955499e37cdbc11ebd6926fa373cd906

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2024.10.7-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 fc75fd2536e10a5ef908a8c83e7c440c8670c8816017f2cc50546b4a935bdbdf
MD5 f705634f1790c94a148dcbe2984e0f99
BLAKE2b-256 7d4f0656cbdcd54cba7b1e60a7a6c6b542f97bb8cbb573bc3c25842fb439caa3

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