diff --git a/ndbioimage/__init__.py b/ndbioimage/__init__.py index 5293485..5fe28f0 100755 --- a/ndbioimage/__init__.py +++ b/ndbioimage/__init__.py @@ -21,8 +21,8 @@ import yaml from numpy.typing import ArrayLike, DTypeLike from ome_types import OME, from_xml, model, ureg from pint import set_application_registry -from tiffwrite import IFD, IJTiffFile # noqa -from tqdm.auto import tqdm, trange +from tiffwrite import FrameInfo, IJTiffParallel +from tqdm.auto import tqdm from .jvm import JVM, JVMException from .transforms import Transform, Transforms @@ -50,14 +50,14 @@ class ReaderNotFoundError(Exception): pass -class TransformTiff(IJTiffFile): +class TransformTiff(IJTiffParallel): """ transform frames in a parallel process to speed up saving """ def __init__(self, image: Imread, *args: Any, **kwargs: Any) -> None: self.image = image super().__init__(*args, **kwargs) - def compress_frame(self, frame: tuple[int, int, int]) -> tuple[IFD, tuple[list[int], list[int]]]: - return super().compress_frame(np.asarray(self.image(*frame)).astype(self.dtype)) + def parallel(self, frame: tuple[int, int, int]) -> tuple[FrameInfo]: + return (np.asarray(self.image(*frame)), 0, 0, 0), class DequeDict(OrderedDict): @@ -398,6 +398,13 @@ class Imread(np.lib.mixins.NDArrayOperatorsMixin, ABC): def __str__(self) -> str: return str(self.path) + # @property + # def __array_interface__(self) -> dict[str, Any]: + # return dict(shape=tuple(self.shape), typestr=self.dtype.str, version=3, data=self.tobytes()) + + def tobytes(self) -> bytes: + return self.flatten().tobytes() + def __array__(self, dtype: DTypeLike = None, copy: bool = None) -> np.ndarray: if copy is False: raise ValueError("`copy=False` isn't supported. A copy is always created.") @@ -1054,7 +1061,7 @@ class Imread(np.lib.mixins.NDArrayOperatorsMixin, ABC): n[i] = (n[i],) shape = [len(i) for i in n] - with TransformTiff(self, fname.with_suffix('.tif'), shape, pixel_type, + with TransformTiff(self, fname.with_suffix('.tif'), pixel_type, pxsize=self.pxsize_um, deltaz=self.deltaz_um, **kwargs) as tif: for i, m in tqdm(zip(product(*[range(s) for s in shape]), product(*n)), # noqa total=np.prod(shape), desc='Saving tiff', disable=not bar): diff --git a/ndbioimage/transforms.py b/ndbioimage/transforms.py index 7f79c42..6415650 100644 --- a/ndbioimage/transforms.py +++ b/ndbioimage/transforms.py @@ -214,7 +214,7 @@ class Transforms(dict): for file in bead_files: with Imread(file) as im: n_channels = max(n_channels, im.shape['c']) - with IJTiffFile(tiffile, (n_channels, 1, len(bead_files))) as tif: + with IJTiffFile(tiffile) as tif: for t, file in enumerate(bead_files): with Imread(file) as im: with Imread(file).with_transform() as jm: diff --git a/pyproject.toml b/pyproject.toml index bccb715..dbd5f39 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "ndbioimage" -version = "2024.9.2" +version = "2024.10.0" description = "Bio image reading, metadata and some affine registration." authors = ["W. Pomp "] license = "GPLv3" @@ -16,7 +16,7 @@ numpy = ">=1.20.0" pandas = "*" tifffile = "*" czifile = "2019.7.2" -tiffwrite = "*" +tiffwrite = ">=2024.10.4" ome-types = ">=0.4.0" pint = "*" tqdm = "*"