Skip to content

Commit

Permalink
Merge pull request #1641 from banesullivan-kobold/multi-source-dict
Browse files Browse the repository at this point in the history
Support dict with MultiFileTileSource
  • Loading branch information
manthey authored Sep 16, 2024
2 parents 6196d27 + f75e84f commit 01a52f1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
13 changes: 11 additions & 2 deletions sources/multi/large_image_source_multi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ class MultiFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
_defaultTileSize = 256
_maxOpenHandles = 6

def __init__(self, path, **kwargs):
def __init__(self, path, **kwargs): # noqa
"""
Initialize the tile class. See the base class for other available
parameters.
Expand All @@ -434,7 +434,16 @@ def __init__(self, path, **kwargs):
self._lastOpenSourceLock = threading.RLock()
# 'c' must be first as channels are special because they can have names
self._axesList = ['c', 'z', 't', 'xy']
if not os.path.isfile(self._largeImagePath):
if isinstance(path, dict) and 'sources' in path:
self._info = path.copy()
self._basePath = '.'
self._largeImagePath = '.'
try:
self._validator.validate(self._info)
except jsonschema.ValidationError:
msg = 'File cannot be validated via multi-source reader.'
raise TileSourceError(msg)
elif not os.path.isfile(self._largeImagePath):
try:
possibleYaml = self._largeImagePath.split('multi://', 1)[-1]
self._info = yaml.safe_load(possibleYaml)
Expand Down
16 changes: 16 additions & 0 deletions test/test_source_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,22 @@ def testTilesFromMultiString():
large_image_source_multi.open('invalid' + sourceString)


def testTilesFromMultiDict():
sourceString = {'sources': [{
'sourceName': 'test', 'path': '__none__', 'params': {'sizeX': 10000, 'sizeY': 10000}}]}
source = large_image_source_multi.open(sourceString)
tileMetadata = source.getMetadata()
assert tileMetadata['tileWidth'] == 256
assert tileMetadata['tileHeight'] == 256
assert tileMetadata['sizeX'] == 10000
assert tileMetadata['sizeY'] == 10000
assert tileMetadata['levels'] == 7
utilities.checkTilesZXY(source, tileMetadata)

with pytest.raises(Exception):
large_image_source_multi.open({'invalid': True})


def testTilesFromNonschemaMultiString():
sourceString = json.dumps({
'sources': [{
Expand Down

0 comments on commit 01a52f1

Please sign in to comment.