Skip to content

Commit

Permalink
Prioritize tile sinks
Browse files Browse the repository at this point in the history
This makes it so `large_image.new()` will pick our preferred sink (zarr
over vips, since it is more capable).
  • Loading branch information
manthey committed Mar 20, 2024
1 parent 71d1068 commit 5f48857
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## 1.27.5

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

### Improvements
- Prioritize tile sinks ([#1478](../../pull/1478))

### Bug Fixes
- Fix an issue with single band on multi source with non uniform sources ([#1474](../../pull/1474))
- Allow alternate name axes in the multi source schema ([#1476](../../pull/1476))
Expand Down
9 changes: 7 additions & 2 deletions large_image/tilesource/__init__.py
Original file line number Diff line number Diff line change
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):
priority = min(priority, 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 @@ -40,6 +40,7 @@ class ZarrFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
'zattrs': 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 @@ -169,8 +169,7 @@ def testNewAndWriteMinSize():
def testNewAndWriteJPEG():
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

0 comments on commit 5f48857

Please sign in to comment.