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

Conversation

banesullivan-kobold
Copy link
Contributor

@banesullivan-kobold banesullivan-kobold commented Sep 12, 2024

Resolves #1638

@manthey
Copy link
Member

manthey commented Sep 13, 2024

There are some petty formatting complaints from flake8, and a minor change is needed to not break the Girder use of the source, plus we can add a test. You can apply this diff to get CI to pass:

diff --git a/sources/multi/large_image_source_multi/__init__.py b/sources/multi/large_image_source_multi/__init__.py
index da0e48b0..c6838d57 100644
--- a/sources/multi/large_image_source_multi/__init__.py
+++ b/sources/multi/large_image_source_multi/__init__.py
@@ -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.
@@ -434,10 +434,10 @@ class MultiFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
         self._lastOpenSourceLock = threading.RLock()
         # 'c' must be first as channels are special because they can have names
         self._axesList = ['c', 'z', 't', 'xy']
-        if isinstance(path, dict):
+        if isinstance(path, dict) and 'sources' in path:
             self._info = path.copy()
-            self._basePath = "."
-            self._largeImagePath = "."
+            self._basePath = '.'
+            self._largeImagePath = '.'
             try:
                 self._validator.validate(self._info)
             except jsonschema.ValidationError:
diff --git a/test/test_source_multi.py b/test/test_source_multi.py
index fbf74903..8f856b11 100644
--- a/test/test_source_multi.py
+++ b/test/test_source_multi.py
@@ -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': [{

@manthey manthey merged commit 01a52f1 into girder:master Sep 16, 2024
15 checks passed
@banesullivan-kobold
Copy link
Contributor Author

Thank you for taking this over the finish line @manthey!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MultiFileTileSource: pass dict on initialization
2 participants