CellProfiler / python-bioformats

Read and write life sciences file formats
Other
125 stars 45 forks source link

Unable to load CH5 File #159

Open roshankern opened 2 years ago

roshankern commented 2 years ago

I am trying to analyze a .ch5 (CellH5) file in python. This file opens fine in ImageJ with the Bio Formats plugin, but python-bioformats throws an error when calling bioformats.ImageReader(file.ch5). How can I resolve this error, or is there a better way to analyze .ch5 files with python? The output of the code is below. Thanks!

14:47:09.187 [Thread-0] DEBUG loci.formats.FormatHandler - NDPISReader initializing /home/roshankern/Desktop/NucleusMorphology/phenotypic_profiling/idr_downloads/test.ch5 14:47:09.187 [Thread-0] DEBUG loci.formats.FormatHandler - loci.formats.in.NDPISReader.initFile(/home/roshankern/Desktop/NucleusMorphology/phenotypic_profiling/idr_downloads/test.ch5)


JavaException Traceback (most recent call last) ... JavaException: <Java object at 0x19f14798> During handling of the above exception, another exception occurred: OSError Traceback (most recent call last) ... OSError: [Errno 22] Could not load the file as an image (see log for details): b'/home/roshankern/Desktop/NucleusMorphology/phenotypic_profiling/idr_downloads/test.ch5'

CC @gwaygenomics to keep you in the loop

gwaybio commented 2 years ago

thanks for opening this issue @roshankern ! Indeed, this file format has given us some trouble!

@bethac07 - would you know who can help us track this down? Would it be helpful for Roshan to attach the example file (test.ch5) to this issue?

🤞 this is a simple fix!

bethac07 commented 2 years ago

@gwaygenomics @roshankern a test file would indeed be great. I also hope it's a simple fix but I can't promise that it is so.

roshankern commented 2 years ago

Thank you for the help @bethac07! The test file is located here.

roshankern commented 2 years ago

It seems the cd5 file can be manipulated in python after being opened with the pyimagej library. The code posted below saves the first frame of the .cd5 file in frame_1. Is there any reason why opening through the pyimagej library would be worse than opening with python-bioformats?

from PIL import Image import matplotlib.pyplot as plt import numpy as np

Create an ImageJ2 gateway with the newest available version of ImageJ2.

import imagej ij = imagej.init('/home/roshankern/Desktop/Fiji.app')

Load an image.

path = '/home/roshankern/Desktop/NucleusMorphology/phenotypic_profiling/downloading/test.ch5' jimage = ij.io().open(path)

Convert the image from ImageJ2 to xarray

image = ij.py.from_java(jimage) frame_1 = Image.fromarray(image.values[0, :, :, 0])

bethac07 commented 2 years ago

There is no reason I can think of that it would be inherently worse; in terms of "how long does it take to open X image", I definitely haven't benchmarked it, but I have no reason to believe that they're substantially different and in terms of "days on the calendar until someone can be guaranteed to have it working", probably makes sense to do what's working right now

roshankern commented 2 years ago

Sounds good, thank you for your help!

bethac07 commented 2 years ago

If it's ok, I'd like to keep this open to eventually be able to address the issue of opening it with p-b

roshankern commented 2 years ago

Of course!