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

Cache read_tiff calls to speed up restyling #891

Merged
merged 1 commit into from
Jul 22, 2022
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 @@ -11,6 +11,7 @@
- When converting girder images locally, prefer mount paths ([886](../../pull/886))
- Store the id of job results for easier post-job work ([887](../../pull/887))
- Harden style compositing of partial tiles ([889](../../pull/889))
- Cache read_tiff calls to speed up restyling ([891](../../pull/891))

### Changes
- Be more consistent in source class name attribute assignment ([884](../../pull/884))
Expand Down
8 changes: 7 additions & 1 deletion sources/tiff/large_image_source_tiff/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import math
import os

import cachetools
import numpy
import PIL.Image
import tifftools
Expand Down Expand Up @@ -48,6 +49,11 @@
pass


@cachetools.cached(cache=cachetools.LRUCache(maxsize=10))
def _cached_read_tiff(path):
return tifftools.read_tiff(path)


class TiffFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
"""
Provides tile access to TIFF files.
Expand Down Expand Up @@ -264,7 +270,7 @@ def _initWithTiffTools(self): # noqa
self.levels = max(1, int(math.ceil(math.log(max(
dir0.imageWidth / dir0.tileWidth,
dir0.imageHeight / dir0.tileHeight)) / math.log(2))) + 1)
info = tifftools.read_tiff(self._largeImagePath)
info = _cached_read_tiff(self._largeImagePath)
frames = []
associated = [] # for now, a list of directories
curframe = -1
Expand Down