diff --git a/CHANGELOG.md b/CHANGELOG.md index cbcaea1a6..46965f0b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/sources/tifffile/large_image_source_tifffile/__init__.py b/sources/tifffile/large_image_source_tifffile/__init__.py index 4bf1e8ec2..c0e16d382 100644 --- a/sources/tifffile/large_image_source_tifffile/__init__.py +++ b/sources/tifffile/large_image_source_tifffile/__init__.py @@ -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 @@ -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): @@ -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)