- make zstd block include content size so fiji can actually read it

- add compression level argument
- remove shape argument
- some more pytest tests
This commit is contained in:
Wim Pomp
2024-10-11 18:52:49 +02:00
parent 1197806a6f
commit 4d31933a38
8 changed files with 171 additions and 89 deletions

View File

@@ -1,14 +1,28 @@
from itertools import product
from pathlib import Path
import numpy as np
import pytest
from tifffile import imread
from tiffwrite import IJTiffFile
def test_single(tmp_path: Path) -> None:
path = tmp_path / 'test.tif'
with IJTiffFile(path, (3, 4, 5)) as tif:
for c, z, t in product(range(3), range(4), range(5)):
tif.save(np.random.randint(0, 255, (64, 64)), c, z, t)
assert path.exists()
@pytest.mark.parametrize('dtype', ('uint8', 'uint16', 'uint32', 'uint64',
'int8', 'int16', 'int32', 'int64', 'float32', 'float64'))
def test_single(tmp_path: Path, dtype) -> None:
with IJTiffFile(tmp_path / 'test.tif', dtype=dtype) as tif:
a0, b0 = np.meshgrid(range(100), range(100))
a0[::2, :] = 0
b0[:, ::2] = 1
tif.save(a0, 0, 0, 0)
tif.save(b0, 1, 0, 0)
a1, b1 = np.meshgrid(range(100), range(100))
a1[:, ::2] = 0
b1[::2, :] = 1
tif.save(a1, 0, 0, 1)
tif.save(b1, 1, 0, 1)
t = imread(tmp_path / 'test.tif')
assert t.dtype == np.dtype(dtype), "data type does not match"
assert np.all(np.stack(((a0, b0), (a1, b1))) == t), "data does not match"