Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bioio-tiff-glob takes precedence over bioio-tifffile, but does not support the image #7

Open
TimMonko opened this issue Oct 9, 2024 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@TimMonko
Copy link

TimMonko commented Oct 9, 2024

Describe the Bug

I have an RGB image that I have been using for tests. It has been working with AICSImage, and now bioio (with bioio-tifffile). If I have bioio-tiff-glob installed, then this results in attempting to read in with bioio-tiff-glob, but the image can't be read. The RGB image in question

Expected Behavior

Either 1. bioio-tiff-glob recognizes that it does not support the image or 2. bioio-tifffile takes precedence since it is less niche in use, perhaps expecting an informed user to input bioio-tiff-glob.Reader if needed.

Reproduction

from bioio import BioImage
import bioio
import bioio_tifffile
from pathlib import Path
bioio.plugin_feasibility_report(r'./resources/RGB.tiff')

outputs this plugin matrix

{'bioio-ome-tiff': PluginSupport(supported=False, error=None),
 'bioio-imageio': PluginSupport(supported=True, error=None),
 'bioio-tiff-glob': PluginSupport(supported=True, error=None),
 'bioio-tifffile': PluginSupport(supported=True, error=None),
 'bioio-ome-zarr': PluginSupport(supported=False, error=None),
 'bioio-sldy': PluginSupport(supported=False, error=None),
 'bioio-czi': PluginSupport(supported=False, error=None),
 'bioio-dv': PluginSupport(supported=False, error=None),
 'bioio-lif': PluginSupport(supported=False, error=None),
 'bioio-nd2': PluginSupport(supported=False, error=None),
 'ArrayLike': PluginSupport(supported=False, error=None)}

this does not work (since it tries to use tiff-glob

file = Path(r'./resources/RGB.tiff')
img = BioImage(file)

error output

{
	"name": "TypeError",
	"message": "Invalid type glob_in - got type <class 'pathlib.WindowsPath'>",
	"stack": "---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[15], line 4
      1 import bioio_tifffile
      3 file = Path(r'./resources/RGB.tiff')
----> 4 img = BioImage(file)
      5 img.dims

File c:\\Users\\timmo\\mambaforge\\envs\
dev-bioio\\Lib\\site-packages\\bioio\\bio_image.py:297, in BioImage.__init__(self, image, reader, reconstruct_mosaic, use_plugin_cache, fs_kwargs, **kwargs)
    287 def __init__(
    288     self,
    289     image: biob.types.ImageLike,
   (...)
    294     **kwargs: Any,
    295 ):
    296     try:
--> 297         self._reader, self._plugin = self._get_reader(
    298             image,
    299             reader,
    300             use_plugin_cache,
    301             fs_kwargs,
    302             **kwargs,
    303         )
    304     except biob.exceptions.UnsupportedFileFormatError:
    305         # When reading from S3 if we failed trying to read
    306         # try reading as an anonymous user otherwise re-raise
    307         # the error
    308         if not str(image).startswith(\"s3://\"):

File c:\\Users\\timmo\\mambaforge\\envs\
dev-bioio\\Lib\\site-packages\\bioio\\bio_image.py:285, in BioImage._get_reader(image, reader, use_plugin_cache, fs_kwargs, **kwargs)
    281 plugin = BioImage.determine_plugin(
    282     image, fs_kwargs=fs_kwargs, use_plugin_cache=use_plugin_cache, **kwargs
    283 )
    284 ReaderClass = plugin.metadata.get_reader()
--> 285 return ReaderClass(image, fs_kwargs=fs_kwargs, **kwargs), plugin

File c:\\Users\\timmo\\mambaforge\\envs\
dev-bioio\\Lib\\site-packages\\bioio_tiff_glob\\reader.py:158, in Reader.__init__(self, glob_in, indexer, scene_glob_character, chunk_dims, dim_order, channel_names, single_file_shape, single_file_dims, fs_kwargs, **kwargs)
    156     file_series = pd.Series(glob_in)
    157 else:
--> 158     raise TypeError(f\"Invalid type glob_in - got type {type(glob_in)}\")
    160 if len(file_series) == 0:
    161     raise ValueError(\"No files found matching glob pattern\")

TypeError: Invalid type glob_in - got type <class 'pathlib.WindowsPath'>"
}

explicitly specifying bioio_tifffile.Reader works

file = Path(r'./resources/RGB.tiff')
img = BioImage(file, reader=bioio_tifffile.Reader)
img.dims

successfuly loads an RGB image

<Dimensions [T: 1, C: 1, Z: 1, Y: 1440, X: 1920, S: 3]>

Environment

  • OS Version: Windows 11
  • bioio-tiff-glob Version: [e.g. 0.5.0]
@TimMonko TimMonko added the bug Something isn't working label Oct 9, 2024
TimMonko added a commit to TimMonko/napari-bioio that referenced this issue Oct 9, 2024
@toloudis
Copy link

toloudis commented Oct 10, 2024

Thanks for reporting this.

I believe we should convert this TypeError to be the equivalent of UnsupportedFileFormatError in order to make this behave as expected.

@toloudis
Copy link

Also Reader._is_supported_image should check for a properly glob-able path.

@BrianWhitneyAI
Copy link
Contributor

@TimMonko I think this is partially resolved. A recent check of the plugin feasibility has

{'bioio-tifffile': PluginSupport(supported=True, error=None),
 'bioio-tiff-glob': PluginSupport(supported=True, error=None),
 'ArrayLike': PluginSupport(supported=False, error=None)}

Indicating that tifffile is now the primary. Let me know if you see the same thing! going to look into the details...

@TimMonko
Copy link
Author

TimMonko commented Dec 17, 2024

Edit: See next comment. This comment does not use #9

@BrianWhitneyAI, doesn't seem to be for me. What in the feasibility report tells you which is supposed to be the primary reader? Just going from top-to-bottom? If so, then tiff-glob is still taking precedence over any other plugin (bioio version 1.1.0).

That same image has the following plugin feasibility.

{'bioio-ome-tiff': PluginSupport(supported=False, error=None),
 'bioio-imageio': PluginSupport(supported=True, error=None),
 'bioio-tiff-glob': PluginSupport(supported=True, error=None),
 'bioio-tifffile': PluginSupport(supported=True, error=None),
 'bioio-ome-zarr': PluginSupport(supported=False, error=None),
 'bioio-czi': PluginSupport(supported=False, error=None),
 'bioio-lif': PluginSupport(supported=False, error=None),
 'bioio-nd2': PluginSupport(supported=False, error=None),
 'ArrayLike': PluginSupport(supported=False, error=None)}

BUT, it tries to read with bioio-tiff-glob and gets an error.
BioImage.determine_plugin(RGB_path):
PluginEntry(entrypoint=EntryPoint(name='bioio-tiff-glob', value='bioio_tiff_glob', group='bioio.readers'), metadata=<class 'bioio_tiff_glob.reader_metadata.ReaderMetadata'>, timestamp=1734403975.5136013)

If I specify bioio-imageio.Reader or bioio-tifffile.Reader it works.

Not sure why, but the error is different in this install (just copying a small part of the traceback:
ValueError: Length of values (0) does not match length of index (4)"

bioio.plugins.dump_plugins():

bioio-ome-zarr
  Author  : Not Specified
  Version : 1.0.1
  License : MIT License
  Date    : 2024-12-13 13:35:06.050469
  Supported Extensions : .zarr
bioio-nd2
  Author  : Not Specified
  Version : 1.0.0
  License : MIT License
  Date    : 2024-12-13 13:35:05.899621
  Supported Extensions : .nd2
bioio-tiff-glob
  Author  : Not Specified
  Version : 1.0.0
  License : MIT License
  Date    : 2024-12-16 20:52:55.513601
  Supported Extensions : .tiff
bioio-tifffile
  Author  : Not Specified
  Version : 1.0.0
  License : MIT License
  Date    : 2024-12-13 13:35:09.781657
  Supported Extensions : tif, tiff
bioio-lif
  Author  : Not Specified
  Version : 1.0.0
  License : MIT License
  Date    : 2024-12-13 13:35:12.998235
  Supported Extensions : .lif
bioio-imageio
  Author  : Not Specified
  Version : 1.0.0
  License : MIT License
  Date    : 2024-12-13 13:35:05.444297
  Supported Extensions : 264, 265, 3fr, 3g2, A64, IMT, MCIDAS, PCX, SPIDER, XVTHUMB, a64, adp, amr, amv, apng, arw, asf, avc, avi, avs, avs2, bay, bif, bmp, cdg, cgi, cif, ct, dcr, dib, dip, dng, dnxhd, dv, dvd, erf, exr, fff, gif, icb, if, iiq, ism, jif, jfif, jng, jp2, jpg, mov, mp4, mpo, msp, pdf, pngppm, ps, zif
bioio-czi
  Author  : Not Specified
  Version : 1.0.1
  License : MIT License
  Date    : 2024-12-13 13:35:12.960038
  Supported Extensions : .czi
bioio-ome-tiff
  Author  : Not Specified
  Version : 1.0.1
  License : MIT License
  Date    : 2024-12-13 13:35:06.013810
  Supported Extensions : .ome.tiff, .tiff, ome.tif, .tif

@TimMonko
Copy link
Author

Checking out #9... Appears to fix this particular issue.
bioio.plugin_feasibility_report(RGB_path):

{'bioio-ome-tiff': PluginSupport(supported=False, error=None),
 'bioio-imageio': PluginSupport(supported=True, error=None),
 'bioio-tiff-glob': PluginSupport(supported=False, error="Reader does not support the image: 'Unknown path'."),
 'bioio-tifffile': PluginSupport(supported=True, error=None),
 'bioio-ome-zarr': PluginSupport(supported=False, error=None),
 'bioio-czi': PluginSupport(supported=False, error=None),
 'bioio-lif': PluginSupport(supported=False, error=None),
 'bioio-nd2': PluginSupport(supported=False, error=None),
 'ArrayLike': PluginSupport(supported=False, error=None)}

BioImage.determine_plugin(RGB_path):

Attempted file (C:/Users/timmo/Downloads/RGB.tiff) load with reader: <class 'bioio_tiff_glob.reader.Reader'> failed with error: Reader does not support the image: 'Unknown path'.

PluginEntry(entrypoint=EntryPoint(name='bioio-tifffile', value='bioio_tifffile', group='bioio.readers'), metadata=<class 'bioio_tifffile.reader_metadata.ReaderMetadata'>, timestamp=1734118509.7816575)

@BrianWhitneyAI
Copy link
Contributor

@TimMonko Yep, #9 should be good to go for your particular issue. Looking into this issue closer, we ordered plugins with the same file extension by the install date however this is done by the entry point which can cause some issues since it can get out of sync with your currently installed packages. If you set up a new environment and run the necessary Python in a location outside of one of the bioio-plugin repos then you'll see wherever plugin has been most recently installed at the top priority.

@BrianWhitneyAI BrianWhitneyAI self-assigned this Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants