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

Uploaded Source

Built Distributions

tiffwrite-2024.10.8-cp310-abi3-win_amd64.whl (485.5 kB view details)

Uploaded CPython 3.10+ Windows x86-64

tiffwrite-2024.10.8-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (739.7 kB view details)

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

tiffwrite-2024.10.8-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (821.2 kB view details)

Uploaded CPython 3.10+ manylinux: glibc 2.17+ s390x

tiffwrite-2024.10.8-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (807.6 kB view details)

Uploaded CPython 3.10+ manylinux: glibc 2.17+ ppc64le

tiffwrite-2024.10.8-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (757.1 kB view details)

Uploaded CPython 3.10+ manylinux: glibc 2.17+ i686

tiffwrite-2024.10.8-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (755.2 kB view details)

Uploaded CPython 3.10+ manylinux: glibc 2.17+ ARMv7l

tiffwrite-2024.10.8-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (741.1 kB view details)

Uploaded CPython 3.10+ manylinux: glibc 2.17+ ARM64

tiffwrite-2024.10.8-cp310-abi3-macosx_11_0_arm64.whl (603.7 kB view details)

Uploaded CPython 3.10+ macOS 11.0+ ARM64

tiffwrite-2024.10.8-cp310-abi3-macosx_10_12_x86_64.whl (661.9 kB view details)

Uploaded CPython 3.10+ macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for tiffwrite-2024.10.8.tar.gz
Algorithm Hash digest
SHA256 e3cfeb28f8c28d777cdeea204d1508ece89ef09d432d1b7e204aadef3292bcb2
MD5 3c72c315ff16e0caac9761f4b531083b
BLAKE2b-256 06521d06826a5cbc0facbdb86c9f08450386d3a08a23e2a84d7a7c01cb23ce90

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2024.10.8-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 45afec6c24a2f201b935d516a9322ea86f02062a95a7f82e9f953574f5d0fe2d
MD5 5f343d2093c9c6db9e7d642b2149a1e3
BLAKE2b-256 073873321806446783086ac347ed18c67e8c35a651b8c235422aa553dbb45537

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2024.10.8-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c6d5af6735042ed19424901dec45fbf3f386dfbc27ff0e6a5d218c314076c93e
MD5 4022098a9944df0fa0c81319cb4b8e40
BLAKE2b-256 f00e72fa4bba64c3e2b75485ea3b2012eadfaf5f6025028d688761eda6bbfdea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2024.10.8-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 81d009f66fd4a6c3a231e41259421f8bcfe79086432c3db25493673c9c4a0719
MD5 0e361b8cd1b494fb02357b1d8b7888cc
BLAKE2b-256 b2aa884e59c94d44cef012e40d1fded9deb7652125b81f00ba40dd624f5be4e3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2024.10.8-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 190f0caee775b0d8be29c5c6f453bf9a99d8997784c5923bdd77bfb57114419b
MD5 b3bb1136b875c19ca67004e388f07a83
BLAKE2b-256 35321c1dde2a360042404e6b95b5aedb7176ed34e67d490e678e2430376279f3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2024.10.8-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 e6bb41771d5745480517db35afbe46c8b97a9f07fbab1ce6052031f6e1053d96
MD5 68689b427065d82ededf96ad4b3e971f
BLAKE2b-256 f2fb1c531f0ac499024744dec44980272c8992a82e9592b805cb733fb6ccd7d4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2024.10.8-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 7010f8866b26ea10a47bf83417c252d422be8a9f17ad2d188dcc91f2784d8047
MD5 ebce6648b94ad42a7e55c25297ea5685
BLAKE2b-256 8edcf201ef23fe13d502e7b11b883be7cd043bdf89c453b748ee53f820744152

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2024.10.8-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 149095b2305d203926a1ede06ce963c9996fd14949ff2a9351ba3c3cf802c157
MD5 73c059d672417ae4d5b035798f02533c
BLAKE2b-256 bbe48e07e3312fa68f470b20ae8eab416db224207920fad8af5260cdc204a4e5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2024.10.8-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 afa43a83bb3361d339a23c6a2eac1453ce97848d15384bcfb9b0d8ae549ce284
MD5 28957654fcd5500a397ca58e414566e7
BLAKE2b-256 63f1b5f8bdc30611da97a68ef561748ac3d0e77adafa69b79993a697181b6407

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tiffwrite-2024.10.8-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 7c607c3e0ebd7e0ed8454d479037c19ceec3b70702df8e66f2379a160dec7864
MD5 a8bc0482dd9c7c71071164c42b30ec9e
BLAKE2b-256 f814d4c715f55eb4d54409e21daa8c8c80700011c9710ab362d219d9a4883205

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