bioio-devs / bioio

Image reading, metadata management, and image writing for Microscopy images in Python
https://bioio-devs.github.io/bioio/OVERVIEW.html
BSD 3-Clause "New" or "Revised" License
32 stars 3 forks source link

Surface more information during reader/plugin selection #26

Closed SeanLeRoy closed 1 month ago

SeanLeRoy commented 10 months ago

See the original issue here for more information from aicsimageio. In short, it would be useful in some use cases to provide more information about what BioImage (previously AICSImage) is doing under the hood during reader selection.

Originally submitted by @tlambert03

toloudis commented 10 months ago

I wonder if it would be enough to have: get_all_readers_for_given_file(filepath) then loop over readers, try each one, get some string message back about why it didn't work.

SeanLeRoy commented 10 months ago

The difference between what it does now and what you are proposing being that currently we stop at the first reader that works but it would be ideal to see all working readers? That seems doable & easy to implement

tlambert03 commented 10 months ago

If I recall correctly, the main issue was about surfacing why something didn't work (not just that it didn't work). The Bioformats reader is particularly tough because it requires a java runtime, so even if you have bioformats_jarinstalled, but don't have openjdk or the like, then you'll get an error, but the implementation as it was in aicsimageio didn't surface that issue, it just said:

>>> rdr = AICSImage.determine_reader('/Users/talley/Downloads/coupe shg stack_0001.oir')

AICSImage does not support the image:
 '/Users/talley/Downloads/coupe shg stack_0001.oir'. File extension suggests 
format: 'oir'. Install extra format dependency with: `pip install bioformats_jar`. 

when in fact the real issue was only surfaced if you manually went in and tried to instantiate a bioformats reader:

>>> im = BioformatsReader('/Users/talley/Downloads/coupe shg stack_0001.oir')

RuntimeError:
BioformatsReader requires a java executable to be available
in your environment. If you are using conda, you can install
with `conda install -c conda-forge scyjava`.

Note: you may need to reactivate your conda environment after
installing opendjk. If you still have this error, try:

# mac and linux:
export JAVA_HOME=$CONDA_PREFIX

# windows:
set JAVA_HOME=%CONDA_PREFIX%\Library

so, the crux of that issue was more about surfacing useful error messages. Without it, would probably bang their head against a wall saying "I DID install bioformats_jar darn it!"

tlambert03 commented 10 months ago

but, I'd need to familiarize myself with whatever equivalent you have for determine_reader here to have a suggestion

evamaxfield commented 10 months ago

I wonder if we need better logging / path tracing then?

We should have different errors for ReaderInitError vs UnsupportedFileFormatError?

BrianWhitneyAI commented 1 month ago

@tlambert03 @evamaxfield @SeanLeRoy @toloudis I am returning to this now and wanted to define a couple of specific changes to make as this issue seems mostly a discussion.

Possible features to add:

evamaxfield commented 1 month ago

@BrianWhitneyAI those all sound great to me!