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

Support dict with MultiFileTileSource #1641

Merged
merged 3 commits into from
Sep 16, 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
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 @@
_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 @@
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)

Check warning on line 445 in sources/multi/large_image_source_multi/__init__.py

View check run for this annotation

Codecov / codecov/patch

sources/multi/large_image_source_multi/__init__.py#L443-L445

Added lines #L443 - L445 were not covered by tests
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