AllenCellModeling/aicsimageio

Latest version of aicsimageio cannot read some czi images

christinab12 opened this issue · 5 comments

Hi there,

System and Software

  • aicsimageio Version: 4.11.0
  • Python Version: 3.9
  • Operating System: MacOS

Description

With the new version of aicsimageio I cannot open some czi files, while others work (I still haven't figured out what distinguishes between the ones that open and the ones that don't).

Expected Behavior

I'm using napari-aicsimageio for my own napari plugin, which is dependent on aicsimageio. With v.4.9.4 when I drag and drop these czi files they are read normally.

Reproduction

pip install napari-organoid-counter
Open napari.
Drag and drop czi file.

Unfortunately, I cannot share the data, but this is the relevant part of the error:
`~/opt/anaconda3/envs/noc-test/lib/python3.9/site-packages/napari_aicsimageio/core.py in ?(path='../merged_stack_B2.czi', in_memory=None)
238
239 # Open file and get data
--> 240 img = AICSImage(path)
241

~/opt/anaconda3/envs/noc-test/lib/python3.9/site-packages/aicsimageio/aics_image.py in ?(self=<class 'aicsimageio.aics_image.AICSImage'> instance, image='../merged_stack_B2.czi', reader=None, reconstruct_mosaic=True, fs_kwargs={}, **kwargs={})
281
282 # Init and store reader
--> 283 self._reader = ReaderClass(image, fs_kwargs=fs_kwargs, **kwargs)
284

~/opt/anaconda3/envs/noc-test/lib/python3.9/site-packages/aicsimageio/readers/ome_tiff_reader.py in ?(self=<OmeTiffReader [Image-is-in-Memory: False]>, image='../merged_stack_B2.czi', chunk_dims=['Z', 'Y', 'X', 'S'], clean_metadata=True, fs_kwargs={}, **kwargs={})
200 # many series
201 if tiff.is_micromanager and not isinstance(self._fs, LocalFileSystem):
--> 202 log.warning(
203 "Remote reading (S3, GCS, HTTPS, etc.) of multi-image "

~/opt/anaconda3/envs/noc-test/lib/python3.9/site-packages/tifffile/tifffile.py in ?(self=<class 'tifffile.tifffile.TiffFile'> instance, arg=<fsspec.implementations.local.LocalFileOpener object>, mode=None, name=None, offset=None, size=None, _multifile=True, _useframes=None, _parent=None, **kwargs={'is_mmstack': False})
3140 setattr(self, key, bool(value))
3141 else:
-> 3142 raise TypeError(f'unexpected keyword argument: {key}')
3143

TypeError: unexpected keyword argument: is_mmstack
`

the is_mmstack indicates that you probably need to install the latest tifffile version. Also make sure the latest aicspylibczi is installed.

The issue you are getting is coming from the ome_tiff_reader for reading OME TIFF files, is that expected for your CZIs? Given this I think it would be useful to know the outcome of the following two scenarios if you are able to test them out:

  • Reading the file with the reader parameter specified as the CZI reader (like reader=aicsimageio.readers.czi_reader) at version 4.11.0
  • Reading the file with the reader parameter specified as the CZI reader (like reader=aicsimageio.readers.czi_reader) at version 4.9.4

Beyond that, the issue you are seeing is a known one with OME TIFF & TIFF files described in #495 (specifically this comment). If using the OME TIFF reader instead of the CZI reader is expected then raising the tifffile version should help.

Thanks @toloudis @SeanLeRoy for your fast replies.

I see now, I think then the problem could then be that I am, in a previous step, saving this image as a tiff and then reading and converting to a czi file using the following code snippet:

from aicsimageio.writers.ome_tiff_writer import OmeTiffWriter
from aicsimageio import AICSImage
from aicsimageio import types

# code where merged_stack numpy array is created and xres, yres are computed

OmeTiffWriter.save(merged_stack, 
                            "merged_stack.tiff",
                            dim_order="YX",
                            physical_pixel_sizes=types.PhysicalPixelSizes(None, yres, xres))
AICSImage("merged_stack.tiff").save("merged_stack.czi")

I tried what you suggested above:

  • For both 4.9.4 and 4.11 this:
from aicsimageio import AICSImage, readers
img=AICSImage("merged_stack.czi", reader=readers.CziReader)

gives the error aicsimageio.exceptions.UnsupportedFileFormatError: CziReader does not support the image

  • But in 4.9.4 this works:
from aicsimageio import AICSImage, readers
img=AICSImage("merged_stack_C4.czi")
  • And in 4.11 the same command gives again the mmstack error.
    As you suggested @SeanLeRoy, raising to the latest tifffile version works, albeit the OME TIFF reader is being used to read the file instead of the CZI reader!

Aha, here is the problem. aicsimageio can only save to OME-TIFF via the AICSImage.save function. Even if you used a .czi file extension, the file still was saved to tiff, which explains why the call stack ended up using tifffile when you tried to load it.

aicsimageio only writes to "open" file formats such as OME-TIFF or OME-Zarr. You can't write a czi file with this library.

ok, many thanks for the clarification, I will then close this issue now!