Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better missing data detection from tifffile #1421

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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