- python: remove deprecated shape argument

- rust: make frame argument to save more generic
This commit is contained in:
Wim Pomp
2024-10-17 13:45:32 +02:00
parent 76046b762e
commit 19c17a798d
6 changed files with 128 additions and 66 deletions

View File

@@ -14,36 +14,35 @@ makes that very hard anyway.
- Colormaps
- Extra tags, globally or frame dependent.
# Python
## Installation
pip install tiffwrite
```pip install tiffwrite```
or
- install [rust](https://rustup.rs/)
- install [rust](https://rustup.rs/)
- ``` pip install tiffwrite@git+https://github.com/wimpomp/tiffwrite ```
pip install tiffwrite@git+https://github.com/wimpomp/tiffwrite
# Usage
## Write an image stack
## 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.
- 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, shape, dtype='uint16', colors=None, colormap=None, pxsize=None, deltaz=None,
### 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)
- 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.
- 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.
@@ -51,22 +50,24 @@ or
- 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().
- 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
## 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
### Write one frame at a time
from tiffwrite import IJTiffFile
import numpy as np
@@ -76,20 +77,34 @@ or
for t in range(10):
tif.save(np.random.randint(0, 10, (32, 32)), c, z, t)
## Saving multiple tiffs simultaneously
### 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]):
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)
## 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.
# 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.