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

Closed
MarikeReimer opened this issue Jun 25, 2024 · 8 comments
Closed

Pynwb tutorial documentation bug #149

MarikeReimer opened this issue Jun 25, 2024 · 8 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

@bendichter
Copy link
Member

@MarikeReimer it sounds like you were able to fix this on your side. I'll close this for now. Feel free to message this thread of this remains an issues for others.

@MarikeReimer
Copy link
Author

This was only going to be an issue for users with volumetric data, but turned into a non-issues. IMO, it would be best for everyone with that use case to convene in Blender. Also, writing NWB files works better as a button on the NeuroMorphovis Blender addon than as a standalone. @marwan-abdellah Do you have some time to chat about this?

@marwan-abdellah
Copy link

@MarikeReimer Indeed. But I need to get a bit of a context.

@MarikeReimer
Copy link
Author

At an NWB hackathon a few years back, @bendichter had an insight for storing morphology metadata. We recently used it for a Blender-based dendritic spine study: https://pmc.ncbi.nlm.nih.gov/articles/PMC11573899/. His method is broadly useful; adding that functionality to Neuro/VessMorphoVis, would enable exporting via NWB/saving on DANDI Archives.

I used his method to make some example outputs of segmented neurons: This one used an Allen Institute model with NeuroMorphoVis and shows how curve/spline data could be structured:
https://dandiarchive.org/dandiset/001248/draft/files?location=sub-AllenCellTypes-ses-CurveDemo&page=1

The other combines the AI model with one from the MICrONS/NEURD workflows and shows how dendritic spine morphology data could be structured in a SONOTA framework: https://dandiarchive.org/dandiset/001248/draft/files?location=sub-FrankenNeuron-ses-Demo&page=1

A collaboration feels like it could be a big win for everyone. I know I'm not the only one who wants a tool that does this. :)

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