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

Change how extensions and fallback priorities in Girder interact #1208

Merged
merged 1 commit into from
Jun 16, 2023
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
### Improvements
- Harden the nd2 source to allow it to read more files ([#1207](../../pull/1207))

### Changes
- Change how extensions and fallback priorities in Girder interact ([#1208](../../pull/1208))

## 1.22.4

### Bug Fixes
Expand Down
32 changes: 24 additions & 8 deletions girder/girder_large_image/girder_tilesource.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import os
import re

from girder.constants import AccessType
from girder.exceptions import FilePathException, ValidationException
from girder.models.file import File
Expand Down Expand Up @@ -136,7 +139,7 @@ def loadGirderTileSources():
if key is not None})


def getGirderTileSourceName(item, file=None, *args, **kwargs):
def getGirderTileSourceName(item, file=None, *args, **kwargs): # noqa
"""
Get a Girder tilesource name using the known sources. If tile sources have
not yet been loaded, load them.
Expand All @@ -148,33 +151,46 @@ def getGirderTileSourceName(item, file=None, *args, **kwargs):
"""
if not len(AvailableGirderTileSources):
loadGirderTileSources()
availableSources = AvailableGirderTileSources
if not file:
file = File().load(item['largeImage']['fileId'], force=True)
mimeType = file['mimeType']
try:
localPath = File().getLocalFilePath(file)
except (FilePathException, AttributeError):
localPath = None
extensions = [entry.lower().split()[0] for entry in file['exts'] if entry]
baseName = os.path.basename(file['name'])
properties = {}
if localPath:
properties['_geospatial_source'] = tilesource.isGeospatial(localPath)
sourceList = []
for sourceName in AvailableGirderTileSources:
if not getattr(AvailableGirderTileSources[sourceName], 'girderSource', False):
for sourceName in availableSources:
if not getattr(availableSources[sourceName], 'girderSource', False):
continue
sourceExtensions = AvailableGirderTileSources[sourceName].extensions
sourceExtensions = availableSources[sourceName].extensions
priority = sourceExtensions.get(None, SourcePriority.MANUAL)
fallback = True
if (mimeType and getattr(availableSources[sourceName], 'mimeTypes', None) and
mimeType in availableSources[sourceName].mimeTypes):
fallback = False
priority = min(priority, availableSources[sourceName].mimeTypes[mimeType])
for regex in getattr(availableSources[sourceName], 'nameMatches', {}):
if re.match(regex, baseName):
fallback = False
priority = min(priority, availableSources[sourceName].nameMatches[regex])
for ext in extensions:
if ext in sourceExtensions:
priority = min(priority, sourceExtensions[ext])
fallback = False
if priority >= SourcePriority.MANUAL:
continue
propertiesClash = any(
getattr(AvailableGirderTileSources[sourceName], k, False) != v
getattr(availableSources[sourceName], k, False) != v
for k, v in properties.items())
sourceList.append((propertiesClash, priority, sourceName))
for _clash, _priority, sourceName in sorted(sourceList):
if AvailableGirderTileSources[sourceName].canRead(item):
sourceList.append((propertiesClash, fallback, priority, sourceName))
for _clash, _fallback, _priority, sourceName in sorted(sourceList):
if availableSources[sourceName].canRead(item):
return sourceName


Expand Down
4 changes: 4 additions & 0 deletions sources/ometiff/large_image_source_ometiff/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ class OMETiffFileTileSource(TiffFileTileSource, metaclass=LruCacheMetaclass):
'tiff': SourcePriority.MEDIUM,
'ome': SourcePriority.PREFERRED,
}
mimeTypes = {
'image/tiff': SourcePriority.MEDIUM,
'image/x-tiff': SourcePriority.MEDIUM,
}

# The expect number of pixels that would need to be read to read the worst-
# case tile.
Expand Down
4 changes: 4 additions & 0 deletions sources/tifffile/large_image_source_tifffile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,14 @@ class TifffileFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
extensions = {
None: SourcePriority.LOW,
'scn': SourcePriority.PREFERRED,
'tif': SourcePriority.LOW,
'tiff': SourcePriority.LOW,
}
mimeTypes = {
None: SourcePriority.FALLBACK,
'image/scn': SourcePriority.PREFERRED,
'image/tiff': SourcePriority.LOW,
'image/x-tiff': SourcePriority.LOW,
}

# Fallback for non-tiled or oddly tiled sources
Expand Down