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

Pynwb tutorial documentation bug #149

Open
MarikeReimer opened this issue Jun 25, 2024 · 4 comments
Open

Pynwb tutorial documentation bug #149

MarikeReimer opened this issue Jun 25, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@MarikeReimer
Copy link

Bug description

I was following the pynwb tutorial to prepare my image data for DANDI Archives:
https://pynwb.readthedocs.io/en/stable/tutorials/domain/images.html#sphx-glr-tutorials-domain-images-py

The Pillow library in their code took issue with our .ims format image data. A workaround with minimal coding exists and it would be nice to share/document it so that troubleshooting is easier for others.

The relevant import statement:
from PIL import Image

The problematic line of code:
img = Image.open("docs/source/figures/logo_pynwb.png") # an example image

Expected behaviour

When executed, this line should return my .ims format image data in a useable form
img = Image.open("MyData.ims") # an example image

Actual behaviour

Image Image.open() believes that my ims file is an HDF5 file
image

How to reproduce

ReproduceErrors.txt is a python script based on the tutorial code that I used for troubleshooting. I can provide an .ims file if needed.

Your personal set up

To reproduce fully, you would need to download the Blender-addon code which created my dandiset. I can share a Zenodo link via email to anyone who is interested.

  • OS: Windows
  • Browser:Chrome

-Development Environment: Visual Studio Code

# paste relevant logs here, if any

The workaround is to use ImageJ to export problematic file types as a sequence of .png files and add them to the appropriate image container with a For loop. That is a stumbling block for new users.

These error messages in particular are unfriendly for new users who usually don't know they can inspect variables while troubleshooting and who may otherwise spend time troubleshooting the OSError:

File "C:\Users\meowm\AppData\Roaming\Python\Python310\site-packages\PIL\Image.py", line 941, in convert
self.load()
File "C:\Users\meowm\AppData\Roaming\Python\Python310\site-packages\PIL\ImageFile.py", line 366, in load
raise OSError(msg)
OSError: cannot find loader for this HDF5 file
[2024-06-25 15:01:24,767][ERROR]: Uncaught exception
Traceback (most recent call last):
File "C:\Users\meowm\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\TestAddon\ClassDefinitions.py", line 453, in execute
holder = self.AddPanelData()
File "C:\Users\meowm\AppData\Roaming\Blender Foundation\Blender\3.6\scripts\addons\TestAddon\ClassDefinitions.py", line 379, in AddPanelData
data=np.array(img.convert("RGB")),
File "C:\Users\meowm\AppData\Roaming\Python\Python310\site-packages\PIL\Image.py", line 941, in convert
self.load()
File "C:\Users\meowm\AppData\Roaming\Python\Python310\site-packages\PIL\ImageFile.py", line 366, in load
raise OSError(msg)
OSError: cannot find loader for this HDF5 file
Error: Python:

@MarikeReimer MarikeReimer added the bug Something isn't working label Jun 25, 2024
@bendichter
Copy link
Member

@MarikeReimer Pillow handles a number of formats, but not .ims. I wouldn't really expect it to, since this appears to be a proprietary sub-format of HDF5 for a specific image acquisition device. It looks like Pillow does support an abstract class that can be used to support custom formats like .ims here. If you want to use Pillow, I would recommend going this route.

There are many proprietary image formats for imaging data (see the Bioformats docs for a sampling), and it's beyond the scope of the tutorials to provide guidance for users to read their own varied data formats. I suppose we could add an explicit note about what formats are supported by Pillow. Would that address your issue sufficiently?

@MarikeReimer
Copy link
Author

MarikeReimer commented Jul 16, 2024 via email

@bendichter
Copy link
Member

Pillow does support TIFF file format, but it looks like you are trying to open a .ims file in these lines:

img = Image.open("MyData.ims") # an example image

@MarikeReimer
Copy link
Author

MarikeReimer commented Jul 16, 2024 via email

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

2 participants