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

Prioritize tile sinks #1478

Merged
merged 1 commit into from
Mar 21, 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

## 1.27.5

### Features
- Zarr tile sink ([#1446](../../pull/1446))

### Improvements
- Prioritize tile sinks ([#1478](../../pull/1478))
- Add a dependency to the zarr source to read more compression types ([#1480](../../pull/1480))

### Bug Fixes
Expand Down
11 changes: 8 additions & 3 deletions large_image/tilesource/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import uuid
from importlib.metadata import entry_points
from pathlib import PosixPath
from typing import Dict, List, Optional, Tuple, Type, Union
from typing import Dict, List, Optional, Tuple, Type, Union, cast

from .. import config
from ..constants import NEW_IMAGE_PATH_FLAG, SourcePriority
Expand Down Expand Up @@ -86,11 +86,14 @@ def getSortedSourceList(
properties = {
'_geospatial_source': isGeospatial(pathOrUri),
}
isNew = str(pathOrUri).startswith(NEW_IMAGE_PATH_FLAG)
sourceList = []
for sourceName in availableSources:
sourceExtensions = availableSources[sourceName].extensions
priority = sourceExtensions.get(None, SourcePriority.MANUAL)
fallback = True
if isNew and getattr(availableSources[sourceName], 'newPriority', None) is not None:
priority = min(priority, cast(SourcePriority, availableSources[sourceName].newPriority))
if (mimeType and getattr(availableSources[sourceName], 'mimeTypes', None) and
mimeType in availableSources[sourceName].mimeTypes):
fallback = False
Expand Down Expand Up @@ -130,7 +133,8 @@ def getSourceNameFromDict(
there is no such source.
"""
sourceList = getSortedSourceList(availableSources, pathOrUri, mimeType, *args, **kwargs)
for _clash, _fallback, _priority, sourceName in sorted(sourceList):
for entry in sorted(sourceList):
sourceName = entry[-1]
if availableSources[sourceName].canRead(pathOrUri, *args, **kwargs):
return sourceName
return None
Expand Down Expand Up @@ -217,7 +221,8 @@ def canReadList(
sourceList = getSortedSourceList(
AvailableTileSources, pathOrUri, mimeType, *args, **kwargs)
result = []
for _clash, _fallback, _priority, sourceName in sorted(sourceList):
for entry in sorted(sourceList):
sourceName = entry[-1]
result.append((sourceName, AvailableTileSources[sourceName].canRead(
pathOrUri, *args, **kwargs)))
return result
Expand Down
4 changes: 4 additions & 0 deletions large_image/tilesource/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ class TileSource(IPyLeafletMixin):
nameMatches: Dict[str, SourcePriority] = {
}

# If a source supports creating new tiled images, specify its basic
# priority based on expected feature set
newPriority: Optional[SourcePriority] = None

# When getting tiles for otherwise empty levels (missing powers of two), we
# composite the tile from higher resolution levels. This can use excessive
# memory if there are too many missing levels. For instance, if there are
Expand Down
1 change: 1 addition & 0 deletions sources/vips/large_image_source_vips/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class VipsFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
mimeTypes = {
None: SourcePriority.FALLBACK,
}
newPriority = SourcePriority.MEDIUM

_tileSize = 256

Expand Down
1 change: 1 addition & 0 deletions sources/zarr/large_image_source_zarr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class ZarrFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
'zarray': SourcePriority.PREFERRED,
'db': SourcePriority.MEDIUM,
}
newPriority = SourcePriority.HIGH

_tileSize = 512
_minTileSize = 128
Expand Down
3 changes: 1 addition & 2 deletions test/test_source_vips.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ def testNewAndWriteMinSize(tmp_path):
def testNewAndWriteJPEG(tmp_path):
imagePath = datastore.fetch('sample_image.ptif')
source = large_image.open(imagePath)
# Update this if it doesn't direct to vips source
out = large_image.new()
out = large_image_source_vips.new()
for tile in source.tileIterator(
format=large_image.constants.TILE_FORMAT_NUMPY,
region=dict(right=4000, bottom=2000),
Expand Down