From 84f66ea088b0edce56d5bbe7d020a1e5022e17a7 Mon Sep 17 00:00:00 2001 From: David Manthey Date: Fri, 2 Apr 2021 12:52:34 -0400 Subject: [PATCH] Handle more OME Tiff variations. Ultimately it would be better to refactor this to handle the specification properly. --- .../large_image_source_ometiff/__init__.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/sources/ometiff/large_image_source_ometiff/__init__.py b/sources/ometiff/large_image_source_ometiff/__init__.py index 8249d7ca4..ef6931678 100644 --- a/sources/ometiff/large_image_source_ometiff/__init__.py +++ b/sources/ometiff/large_image_source_ometiff/__init__.py @@ -197,9 +197,14 @@ def _parseOMEInfo(self): # noqa len(self._omebase['TiffData']) == 1) and (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.get( - 'Plane', self._omebase.get('Channel')) + if (not len(self._omebase['TiffData']) or + self._omebase['TiffData'][0] == {} or + int(self._omebase['TiffData'][0].get('PlaneCount', 0)) == 1): + planes = copy.deepcopy(self._omebase.get( + 'Plane', self._omebase.get('Channel'))) + for idx, plane in enumerate(planes): + plane['IndexC'] = idx + self._omebase['TiffData'] = planes elif (int(self._omebase['TiffData'][0].get('PlaneCount', 0)) == len(self._omebase.get('Plane', self._omebase.get('Channel', [])))): planes = copy.deepcopy(self._omebase.get('Plane', self._omebase.get('Channel'))) @@ -219,7 +224,6 @@ def _parseOMEInfo(self): # noqa raise TileSourceException( 'OME Tiff contains frames that contain multiple planes') except (KeyError, ValueError, IndexError): - print('B') raise TileSourceException('OME Tiff does not contain an expected record') def getMetadata(self): @@ -239,7 +243,8 @@ def getMetadata(self): break except Exception: pass - if len(set(channels)) != len(channels): + if len(set(channels)) != len(channels) and ( + len(channels) <= 1 or len(channels) > len(result['frames'])): channels = [] # Standardize "TheX" to "IndexX" values reftbl = OrderedDict([