BioImage-Archive / bia-explorer

Python package for exploring BIA data
Apache License 2.0
2 stars 1 forks source link

Error accessing image due to wrong interal url #3

Closed haesleinhuepf closed 3 months ago

haesleinhuepf commented 3 months ago

Hi all, I'm retrieving an error when accessing this dataset using the API.

To reproduce

from bia_explorer import io, biostudies
accession = 'S-BIAD599'
study = io.load_bia_study(accession)
image = study.images[0]
image.show()

Error:

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
Cell In[1], line 5
      3 study = io.load_bia_study(accession)
      4 image = study.images[0]
----> 5 image.show()

File C:\structure\code\bia-explorer\bia_explorer\io.py:39, in BIAImage.show(self)
     38 def show(self):
---> 39     return self.show_pil()

File C:\structure\code\bia-explorer\bia_explorer\io.py:42, in BIAImage.show_pil(self)
     41 def show_pil(self):
---> 42     return load_pil_image_from_uri(self.uri)

File C:\structure\code\bia-explorer\bia_explorer\io.py:26, in load_pil_image_from_uri(image_uri)
     23 def load_pil_image_from_uri(image_uri):
     25     r = requests.get(image_uri)
---> 26     assert r.status_code == 200
     28     im = Image.open(BytesIO(r.content))
     30     return im

AssertionError: 

Potential solution:

image.uri contains the wrong slashes \ instead of /:

image

This works:

image

Thus, adding image.uri.replace("\\", "/") internally before returning the uri could help.

Alternative solution

Go though the bioimage archive database and correct broken uris.

liviuba commented 3 months ago

Hi @haesleinhuepf ,

Thanks for reporting this!

Some of our images did have an inconsistent path separator. We fixed all broken image representation URIs, please let us know if you have any other issues with this.

Kind regards, Liviu