Write BioFormats/ImageJ compatible tiffs with zstd compression in parallel.
Project description
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file tiffwrite-2024.10.9.tar.gz
.
File metadata
- Download URL: tiffwrite-2024.10.9.tar.gz
- Upload date:
- Size: 33.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac12b4ade042d33b593f6428207f9bb37874bb60930e7feaf486d16287cf3d4b |
|
MD5 | ffd191a3fb0f0dc8b4c02a8be4daf760 |
|
BLAKE2b-256 | 2cdbb0f7897dd7ae89c3fb5dd07f24c5d599eab25bcfe794b4d0355016f954d5 |
File details
Details for the file tiffwrite-2024.10.9-cp310-abi3-win_amd64.whl
.
File metadata
- Download URL: tiffwrite-2024.10.9-cp310-abi3-win_amd64.whl
- Upload date:
- Size: 483.1 kB
- Tags: CPython 3.10+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3d9c3a57877b5a20217335286f81ec690174074017bcd33acdff664798c96ef |
|
MD5 | 4151d5fe53eb30bfe07460adc508d187 |
|
BLAKE2b-256 | 42e9e7e0422f8f272ed14759b8d54c7c9f78e7a05be6801a800437e5ff3f7abb |
File details
Details for the file tiffwrite-2024.10.9-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: tiffwrite-2024.10.9-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 721.0 kB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12f91a7f1fd92c55babd2aa480d28842d3027e8c17d4f2ee5ea88a4240dfcfac |
|
MD5 | 79f7369b69e3182f05b06f093beb1548 |
|
BLAKE2b-256 | 376414f6f70a37f846253597e3bdd33f2dd177bc3c57e1238219b25ab55a347b |
File details
Details for the file tiffwrite-2024.10.9-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
.
File metadata
- Download URL: tiffwrite-2024.10.9-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
- Upload date:
- Size: 809.1 kB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ s390x
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19f7b6bc9319dfd95561be7e85fe0cfc6a743746b3fa6d7bff2c6003477cbc63 |
|
MD5 | 419f919246eee9c6bc8ab9069c3fc2e9 |
|
BLAKE2b-256 | 6ef679e127b76362643e30cb3dec665cef4dd41e39c4db285748a33ad7f70786 |
File details
Details for the file tiffwrite-2024.10.9-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
.
File metadata
- Download URL: tiffwrite-2024.10.9-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
- Upload date:
- Size: 790.0 kB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ ppc64le
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2681e2eabc8551fe5df6f6274cc660da3491c65230afd0006a4e75b3231b287c |
|
MD5 | c328796fc038520635a18e0517b17f05 |
|
BLAKE2b-256 | b558cd6acb8c3bcaf538452f927e70407d71717fa5f920b91d1f25c0ed971660 |
File details
Details for the file tiffwrite-2024.10.9-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
.
File metadata
- Download URL: tiffwrite-2024.10.9-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
- Upload date:
- Size: 741.6 kB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19f6140ac1bf31bbebb1acccd100c09ef00e5e60008cba0cd57237300daeb7bf |
|
MD5 | e6745a7ef400956bc8c17b440a1de8ef |
|
BLAKE2b-256 | 0feca5c72e553efb1330fc96796a9bb921bfbb48091751892b2e3beddd5848ab |
File details
Details for the file tiffwrite-2024.10.9-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
.
File metadata
- Download URL: tiffwrite-2024.10.9-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
- Upload date:
- Size: 730.4 kB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ ARMv7l
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 954c691ffa9ea87aec42ed032153d7611f80c19b81fe568a23c9f9eebc998c39 |
|
MD5 | 373209024a5d74d625b3d7e50f57a939 |
|
BLAKE2b-256 | 5a7d67378889253a4026b40b520ca21116965c4fa4699c97deff68e6a0c6dfc1 |
File details
Details for the file tiffwrite-2024.10.9-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
.
File metadata
- Download URL: tiffwrite-2024.10.9-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 711.8 kB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04c7070b702cf5368a2025e382d01692e986eea6a2dbfe8abca1a6d68c6cce3b |
|
MD5 | 019990f68196288954963745b40be63f |
|
BLAKE2b-256 | d3d15416ef823bd944c15f814bb6141079cda9bbee0985bfa191c97a207522fd |
File details
Details for the file tiffwrite-2024.10.9-cp310-abi3-macosx_11_0_arm64.whl
.
File metadata
- Download URL: tiffwrite-2024.10.9-cp310-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 587.7 kB
- Tags: CPython 3.10+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8cae9f9c10dbce6c5c2cd7096adc2e14685a6fd1907dea478b355b2ec98c7b0e |
|
MD5 | 7b287326889e4603250420f067ca6b63 |
|
BLAKE2b-256 | d472582991ad94b716aeb1e20a4b7f501096b4d5f74655658506be98f9c51cfb |
File details
Details for the file tiffwrite-2024.10.9-cp310-abi3-macosx_10_12_x86_64.whl
.
File metadata
- Download URL: tiffwrite-2024.10.9-cp310-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 648.8 kB
- Tags: CPython 3.10+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd228880f3c9cbefe4ed4a4bd14faefdd386344f40410370775d43eb871ef159 |
|
MD5 | ea2ee8a5dad21fb0f021f44a365c35e4 |
|
BLAKE2b-256 | 0046d42ef75f32ffe129f495fde5877bf6bd8c5b888ef308689abf10de99d804 |