From c8b84c13f98c075204ba6c5adc05f1b7d51a10a9 Mon Sep 17 00:00:00 2001 From: David Manthey Date: Wed, 29 Jul 2020 16:02:54 -0400 Subject: [PATCH] Read more OME Tiff files. --- .../ometiff/large_image_source_ometiff/__init__.py | 14 +++++++++----- .../tiff/large_image_source_tiff/tiff_reader.py | 3 ++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/sources/ometiff/large_image_source_ometiff/__init__.py b/sources/ometiff/large_image_source_ometiff/__init__.py index 1e1e29333..830d974ed 100644 --- a/sources/ometiff/large_image_source_ometiff/__init__.py +++ b/sources/ometiff/large_image_source_ometiff/__init__.py @@ -114,7 +114,7 @@ def __init__(self, path, **kwargs): self._omeLevels = [omebylevel.get(key) for key in range(max(omebylevel.keys()) + 1)] if base._tiffInfo.get('istiled'): self._tiffDirectories = [ - TiledTiffDirectory(largeImagePath, int(entry['TiffData'][0]['IFD'])) + TiledTiffDirectory(largeImagePath, int(entry['TiffData'][0].get('IFD', 0))) if entry else None for entry in self._omeLevels] else: @@ -190,16 +190,20 @@ def _parseOMEInfo(self): img['Pixels']['TiffData'] = [img['Pixels']['TiffData']] if isinstance(img['Pixels'].get('Plane'), dict): img['Pixels']['Plane'] = [img['Pixels']['Plane']] + if isinstance(img['Pixels'].get('Channels'), dict): + img['Pixels']['Channels'] = [img['Pixels']['Channels']] try: self._omebase = self._omeinfo['Image'][0]['Pixels'] if ((not len(self._omebase['TiffData']) or len(self._omebase['TiffData']) == 1) and - len(self._omebase['Plane'])): + (len(self._omebase.get('Plane', [])) or + len(self._omebase.get('Channel', [])))): if not len(self._omebase['TiffData']) or self._omebase['TiffData'][0] == {}: - self._omebase['TiffData'] = self._omebase['Plane'] + self._omebase['TiffData'] = self._omebase.get( + 'Plane', self._omebase.get('Channel')) elif (int(self._omebase['TiffData'][0].get('PlaneCount', 0)) == - len(self._omebase['Plane'])): - planes = copy.deepcopy(self._omebase['Plane']) + len(self._omebase.get('Plane', self._omebase.get('Channel', [])))): + planes = copy.deepcopy(self._omebase.get('Plane', self._omebase.get('Channel'))) for idx, plane in enumerate(planes): plane['IFD'] = plane.get( 'IFD', int(self._omebase['TiffData'][0].get('IFD', 0)) + idx) diff --git a/sources/tiff/large_image_source_tiff/tiff_reader.py b/sources/tiff/large_image_source_tiff/tiff_reader.py index f11231571..2fbc3d747 100644 --- a/sources/tiff/large_image_source_tiff/tiff_reader.py +++ b/sources/tiff/large_image_source_tiff/tiff_reader.py @@ -133,7 +133,8 @@ def __init__(self, filePath, directoryNum, mustBeTiled=True, subDirectoryNum=0, self._open(filePath, directoryNum, subDirectoryNum) self._loadMetadata() config.getConfig('logger').debug( - 'TiffDirectory %d:%d Information %r', directoryNum, subDirectoryNum, self._tiffInfo) + 'TiffDirectory %d:%d Information %r', + directoryNum, subDirectoryNum or 0, self._tiffInfo) try: if validate: self._validate()