Skip to content

Commit

Permalink
Merge pull request #1561 from girder/folder-item-images
Browse files Browse the repository at this point in the history
Better handle images that are composed of a folder and an item.
  • Loading branch information
manthey authored Jun 27, 2024
2 parents 8949886 + 43f29d8 commit af42659
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Improvements
- Show a loading spinner on the image display in geojs in girder ([#1559](../../pull/1559))
-

### Bug Fixes
- Fix a compositing error in transformed multi source images ([#1560](../../pull/1560))
Expand Down
49 changes: 45 additions & 4 deletions girder/girder_large_image/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def _updateJob(event):
datetime.timedelta(seconds=30)))


def checkForLargeImageFiles(event):
def checkForLargeImageFiles(event): # noqa
file = event.info
logger.info('Handling file %s (%s)', file['_id'], file['name'])
possible = False
Expand All @@ -178,10 +178,51 @@ def checkForLargeImageFiles(event):
return
try:
ImageItem().createImageItem(item, file, createJob=False)
return
except Exception:
# We couldn't automatically set this as a large image
girder.logger.info(
'Saved file %s cannot be automatically used as a largeImage' % str(file['_id']))
pass
# Check for files that are from folder/image style images. This is custom
# per folder/image format
imageFolderRecords = {
'mrxs': {
'match': r'^Slidedat.ini$',
'up': 1,
'folder': r'^(.*)$',
'image': '\\1.mrxs',
},
'vsi': {
'match': r'^.*\.ets$',
'up': 2,
'folder': r'^_(\.*)_$',
'image': '\\1.vsi',
},
}
for check in imageFolderRecords.values():
if re.match(check['match'], file['name']):
try:
folderId = item['folderId']
folder = None
for _ in range(check['up']):
folder = Folder().load(folderId, force=True)
if not folder:
break
folderId = folder['parentId']
if not folder or not re.match(check['folder'], folder['name']):
continue
imageName = re.sub(check['folder'], check['image'], folder['name'])
parentItem = Item().findOne({'folderId': folder['parentId'], 'name': imageName})
if not parentItem:
continue
files = list(Item().childFiles(item=parentItem, limit=2))
if len(files) == 1:
parentFile = files[0]
ImageItem().createImageItem(parentItem, parentFile, createJob=False)
return
except Exception:
pass
# We couldn't automatically set this as a large image
girder.logger.info(
'Saved file %s cannot be automatically used as a largeImage' % str(file['_id']))


def removeThumbnails(event):
Expand Down
7 changes: 5 additions & 2 deletions girder/girder_large_image/girder_tilesource.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from girder.exceptions import FilePathException, ValidationException
from girder.models.file import File
from girder.models.item import Item
from large_image import tilesource
from large_image import config, tilesource
from large_image.constants import SourcePriority
from large_image.exceptions import TileSourceAssetstoreError, TileSourceError

Expand Down Expand Up @@ -164,6 +164,9 @@ def getGirderTileSourceName(item, file=None, *args, **kwargs): # noqa
properties = {}
if localPath:
properties['_geospatial_source'] = tilesource.isGeospatial(localPath)
ignored_names = config.getConfig('all_sources_ignored_names')
ignoreName = (ignored_names and re.search(
ignored_names, baseName, flags=re.IGNORECASE))
sourceList = []
for sourceName in availableSources:
if not getattr(availableSources[sourceName], 'girderSource', False):
Expand All @@ -183,7 +186,7 @@ def getGirderTileSourceName(item, file=None, *args, **kwargs): # noqa
if ext in sourceExtensions:
priority = min(priority, sourceExtensions[ext])
fallback = False
if priority >= SourcePriority.MANUAL:
if priority >= SourcePriority.MANUAL or (ignoreName and fallback):
continue
propertiesClash = any(
getattr(availableSources[sourceName], k, False) != v
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ class BioformatsFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
extensions = {
None: SourcePriority.FALLBACK,
'czi': SourcePriority.PREFERRED,
'ets': SourcePriority.LOW, # part of vsi
'lif': SourcePriority.MEDIUM,
'vsi': SourcePriority.PREFERRED,
}
Expand Down
1 change: 1 addition & 0 deletions sources/openslide/large_image_source_openslide/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class OpenslideFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
None: SourcePriority.MEDIUM,
'bif': SourcePriority.LOW, # Ventana
'dcm': SourcePriority.LOW, # DICOM
'ini': SourcePriority.LOW, # Part of mrxs
'mrxs': SourcePriority.PREFERRED, # MIRAX
'ndpi': SourcePriority.PREFERRED, # Hamamatsu
'scn': SourcePriority.LOW, # Leica
Expand Down

0 comments on commit af42659

Please sign in to comment.