Skip to content

Commit

Permalink
Merge pull request #1421 from girder/tifffile-missing-data
Browse files Browse the repository at this point in the history
Better missing data detection from tifffile
  • Loading branch information
manthey authored Jan 4, 2024
2 parents ed5e963 + 5cd1c21 commit adac24a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Remove NaN values from band information ([#1414](../../pull/1414))
- Add a singleBand option to the multi-source specification ([#1416](../../pull/1416))
- Allow better detection of multiple file dicom ([#1417](../../pull/1417))
- Better missing data detection from tifffile ([#1421](../../pull/1421))

### Changes
- Remove an unused parameter in a private method ([#1419](../../pull/1419))
Expand Down
18 changes: 14 additions & 4 deletions sources/tifffile/large_image_source_tifffile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
pass


class checkForMissingDataHandler(logging.Handler):
def emit(self, record):
msg = record.getMessage()
if 'Missing data are zeroed' in msg or 'OME series expected ' in msg:
raise TileSourceError(record.getMessage())


def _lazyImport():
"""
Import the tifffile module. This is done when needed rather than in the
Expand All @@ -41,8 +48,13 @@ def _lazyImport():
tifffile = None
msg = 'tifffile module is too old.'
raise TileSourceError(msg)
logging.getLogger('tifffile.tifffile').setLevel(logging.ERROR)
logging.getLogger('tifffile').setLevel(logging.ERROR)
# The missing data handler consumes most warnings, but throws if a
# warning about missing data occurs
# The tifffile.tifffile logger is in older versions of tifffile
logging.getLogger('tifffile.tifffile').setLevel(logging.WARNING)
logging.getLogger('tifffile.tifffile').addHandler(checkForMissingDataHandler())
logging.getLogger('tifffile').setLevel(logging.WARNING)
logging.getLogger('tifffile').addHandler(checkForMissingDataHandler())


def et_findall(tag, text):
Expand Down Expand Up @@ -498,8 +510,6 @@ def getTile(self, x, y, z, pilImageAllowed=False, numpyAllowed=False, **kwargs):
if sidx not in self._zarrcache:
if len(self._zarrcache) > 10:
self._zarrcache = {}
if self.frames > 1:
series.keyframe.nodata = None
za = zarr.open(series.aszarr(), mode='r')
hasgbs = hasattr(za[0], 'get_basic_selection')
self._zarrcache[sidx] = (za, hasgbs)
Expand Down

0 comments on commit adac24a

Please sign in to comment.