Skip to content

Commit

Permalink
Read more OME Tiff files.
Browse files Browse the repository at this point in the history
  • Loading branch information
manthey committed Sep 15, 2020
1 parent 1adba5c commit 3e24804
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
24 changes: 17 additions & 7 deletions sources/ometiff/large_image_source_ometiff/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -182,37 +182,47 @@ def _checkForOMEZLoop(self, largeImagePath):
info['Image']['Pixels']['PlanesFromZloop'] = 'true'
info['Image']['Pixels']['SizeZ'] = str(zloop)

def _parseOMEInfo(self):
def _parseOMEInfo(self): # noqa
if isinstance(self._omeinfo['Image'], dict):
self._omeinfo['Image'] = [self._omeinfo['Image']]
for img in self._omeinfo['Image']:
if isinstance(img['Pixels'].get('TiffData'), dict):
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 isinstance(self._omebase.get('Plane'), dict):
self._omebase['Plane'] = [self._omebase['Plane']]
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)
self._omebase['TiffData'] = planes
if isinstance(self._omebase['TiffData'], dict):
self._omebase['TiffData'] = [self._omebase['TiffData']]
if len({entry.get('UUID', {}).get('FileName', '')
for entry in self._omebase['TiffData']}) > 1:
raise TileSourceException('OME Tiff references multiple files')
if (len(self._omebase['TiffData']) != int(self._omebase['SizeC']) *
int(self._omebase['SizeT']) * int(self._omebase['SizeZ']) or
len(self._omebase['TiffData']) != len(
self._omebase.get('Plane', self._omebase['TiffData']))):
raise TileSourceException('OME Tiff contains frames that contain multiple planes')
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):
Expand Down
3 changes: 2 additions & 1 deletion sources/tiff/large_image_source_tiff/tiff_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 3e24804

Please sign in to comment.