scverse / squidpy

Spatial Single Cell Analysis in Python
https://squidpy.readthedocs.io/en/stable/
BSD 3-Clause "New" or "Revised" License
434 stars 79 forks source link

New version of ``tifffile`` #526

Closed michalk8 closed 2 years ago

michalk8 commented 2 years ago

Description

.shaped_metadata attribute doesn't seem to exist, although looking at the diffs of previous version, it should be there.

Minimal reproducible example

import squidpy as sq
sq.datasets.visium_fluo_image_crop()

Traceback

```pytb --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) /tmp/ipykernel_103728/2906575399.py in ----> 1 sq.datasets.visium_fluo_image_crop() /opt/projects/helmholtz/squidpy/squidpy/datasets/_utils.py in visium_fluo_image_crop(path, **kwargs) /opt/projects/helmholtz/squidpy/squidpy/datasets/_utils.py in download(self, fpath, **kwargs) 85 logg.error(f"Unable to create directory `{dirname}`. Reason `{e}`") 86 ---> 87 data = self._download(fpath=fpath, backup_url=self.url, **kwargs) 88 89 if self.shape is not None and data.shape != self.shape: /opt/projects/helmholtz/squidpy/squidpy/datasets/_utils.py in _download(self, fpath, backup_url, **kwargs) 168 169 img = ImageContainer() --> 170 img.add_img(fpath, layer="image", library_id=self.library_id, **kwargs) 171 172 return img /opt/projects/helmholtz/squidpy/squidpy/im/_container.py in add_img(self, img, layer, dims, library_id, lazy, chunks, copy, **kwargs) 287 InferDimensions(dims) if isinstance(dims, str) else dims 288 ) --> 289 res: xr.DataArray | None = self._load_img(img, chunks=chunks, layer=layer, copy=copy, dims=dims, **kwargs) 290 291 if res is not None: ~/.miniconda3/envs/cellrank/lib/python3.8/functools.py in _method(*args, **kwargs) 910 def _method(*args, **kwargs): 911 method = self.dispatcher.dispatch(args[0].__class__) --> 912 return method.__get__(obj, cls)(*args, **kwargs) 913 914 _method.__isabstractmethod__ = self.__isabstractmethod__ /opt/projects/helmholtz/squidpy/squidpy/im/_container.py in _(self, img_path, chunks, dims, **_) 361 362 if suffix in (".jpg", ".jpeg", ".png", ".tif", ".tiff"): --> 363 return _lazy_load_image(img_path, dims=dims, chunks=chunks) 364 365 if suffix == ".zarr" or Path(img_path).is_dir(): # can also be a URL /opt/projects/helmholtz/squidpy/squidpy/im/_io.py in _lazy_load_image(fname, dims, chunks) 241 242 fname = str(fname) --> 243 shape, dims, dtype, _ = _infer_dimensions(fname, dims) 244 logg.debug(f"Reshaping to `{shape}` with dimensions `{dims}`") 245 /opt/projects/helmholtz/squidpy/squidpy/im/_io.py in _infer_dimensions(obj, infer_dimensions) 165 166 if isinstance(obj, str): --> 167 shape, dtype = _get_image_shape_dtype(obj) 168 else: 169 shape, dtype = obj.shape, obj.dtype /opt/projects/helmholtz/squidpy/squidpy/im/_io.py in _get_image_shape_dtype(fname) 87 def _get_image_shape_dtype(fname: str) -> tuple[tuple[int, ...], np.dtype]: # type: ignore[type-arg] 88 try: ---> 89 return _infer_shape_dtype(fname) 90 except Image.UnidentifiedImageError as e: 91 logg.warning(e) /opt/projects/helmholtz/squidpy/squidpy/im/_io.py in _infer_shape_dtype(fname) 43 image = TiffFile(fname) 44 try: ---> 45 return tuple(image.shaped_metadata[0]["shape"]), np.dtype(image.pages[0].dtype) 46 except (IndexError, KeyError, TypeError): 47 return (len(image.pages),) + image.pages[0].shape, np.dtype(image.pages[0].dtype) ~/.miniconda3/envs/cellrank/lib/python3.8/site-packages/tifffile/tifffile.py in __getattr__(self, name) 5265 setattr(self, name, value) 5266 return value -> 5267 raise AttributeError( 5268 f'{self.__class__.__name__!r} object has no attribute {name!r}' 5269 ) AttributeError: 'TiffFile' object has no attribute 'shaped_metadata' ```

Version

tifffile==2022.4.22

cgohlke commented 2 years ago

That's a regression in tifffile. Will be fixed in the next version.

michalk8 commented 2 years ago

I've pinned tifffile!=2022.4.22, closing via db22b4d176a8cfba36ae36b63dfd0041cb1e5bcf