filippocastelli / pyometiff

OME-TIFF IO in python
GNU General Public License v3.0
18 stars 4 forks source link

Error while reading #11

Closed arnaudbore closed 7 months ago

arnaudbore commented 7 months ago

Hello,

Thank you for this really nice package. I was trying to read one of my files and I get a "list index out of range error".

These data have been saved in TIFF using ImSpector Pro 7.0.

Thank you for your help. Arnaud

PS: I can also share some data if needed.

img_array, metadata, xml_metadata = reader.read()
Key not found: list index out of range
Key not found: list index out of range
key not found list index out of range
Key not found: list index out of range
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Cell In[8], line 1
----> 1 img_array, metadata, xml_metadata = reader.read()

File ~/.virtualenvs/microscopy/lib/python3.10/site-packages/pyometiff/omereader.py:40, in OMETIFFReader.read(self)
     38 def read(self) -> (np.ndarray, dict, str):
     39     self.array, self.omexml_string = self._open_tiff(self.fpath)
---> 40     self.metadata = self.parse_metadata(self.omexml_string)
     41     return self.array, self.metadata, self.omexml_string

File ~/.virtualenvs/microscopy/lib/python3.10/site-packages/pyometiff/omereader.py:166, in OMETIFFReader.parse_metadata(self, omexml_string)
    163     metadata["ObjMag"] = None
    165 # get channel names
--> 166 metadata["Channels"] = self._parse_channels(metadata["SizeC"], self.ox, self.imageseries)
    167 # for c in range(metadata["SizeC"]):
    168 #     channel_names.append(
    169 #         self.ox.image(self.imageseries).Pixels.Channel(c).Name
    170 #     )
    171 
    172 #     self.ox.image(self.imageseries).Pixels.Channel(c).
    173 metadata = self._remove_none_or_empty_dict(metadata)

File ~/.virtualenvs/microscopy/lib/python3.10/site-packages/pyometiff/omereader.py:180, in OMETIFFReader._parse_channels(cls, sizeC, ox, imageseries)
    178 channels_dict = {}
    179 for c in range(sizeC):
--> 180     channel_obj = ox.image(imageseries).Pixels.Channel(c)
    181     channel_name = channel_obj.Name
    182     channel_dict = {}

File ~/.virtualenvs/microscopy/lib/python3.10/site-packages/pyometiff/omexml.py:1032, in OMEXML.Pixels.Channel(self, index)
   1030 def Channel(self, index=0):
   1031     """Get the indexed channel from the Pixels element"""
-> 1032     channel = self.node.findall(qn(self.ns['ome'], "Channel"))[index]
   1033     return OMEXML.Channel(channel)

IndexError: list index out of range
filippocastelli commented 7 months ago

Hi Arnaud, Thank you so much for opening the issue. there seems to be an issue with the interpretation of the number of channels

It would be very helpful if you could share the file so I can debug it sorry for the inconvenience

arnaudbore commented 7 months ago

Here it is: https://box.criugm.qc.ca/f/06b1b55f6de44c7c9ff7/?dl=1 Please tell me when you have downloaded it.

filippocastelli commented 7 months ago

got it! I've released a new version of pyometiff where the bug should be fixed. try updating with pip install --upgrade pyometiff

i'll close the issue for now, feel free to open another one if you still encounter problems