diff --git a/django/applications/catmaid/control/tile.py b/django/applications/catmaid/control/tile.py index 5c7c78d13d..dda1414ce7 100644 --- a/django/applications/catmaid/control/tile.py +++ b/django/applications/catmaid/control/tile.py @@ -11,7 +11,7 @@ from django.conf import settings from django.http import HttpRequest, HttpResponse -from catmaid.models import UserRole, TileSourceTypes +from catmaid.models import UserRole, TileSourceTypes, Stack from catmaid.control.common import ConfigurationError, get_request_bool from catmaid.control.authentication import requires_user_role @@ -119,14 +119,31 @@ def get_cloudvolume_tile(project_id, stack_id, scale, height, width, x, y, z, scale_to_fit = False effective_scale = 1.0 voxel_offset = (0, 0, 0) + + # Use a cached info file, if availavle. This avoids fetching the info file + # for every tile. + stack = Stack.objects.get(id=stack_id) + infoKey = 'ngpreInfo' + if stack.metadata and infoKey in stack.metadata: + info = stack.metadata.get(infoKey) + else: + info = None + provenanceKey = 'ngpreProvenance' + if stack.metadata and provenanceKey in stack.metadata: + provenance = stack.metadata.get(provenanceKey) + else: + provenance = None + try: cv = cloudvolume.CloudVolume(basename, use_https=True, parallel=False, - cache=cache, mip=mip, bounded=False, fill_missing=fill_missing) + cache=cache, mip=mip, bounded=False, fill_missing=fill_missing, + info=info, provenance=provenance) cutout = cv[x:(x + width), y:(y + height), z] except cloudvolume.exceptions.ScaleUnavailableError as e: logger.info(f'Need to use extra scaling, because mip level {mip} is not available: {e}') cv_test = cloudvolume.CloudVolume(basename, use_https=True, parallel=False, - cache=cache, bounded=False, fill_missing=fill_missing) + cache=cache, bounded=False, fill_missing=fill_missing, + info=info, provenance=provenance) # Find mip closest to the request min_mip = None min_mip_dist = float('infinity') diff --git a/django/applications/catmaid/models.py b/django/applications/catmaid/models.py index bba5a2b073..f2b8d17af8 100644 --- a/django/applications/catmaid/models.py +++ b/django/applications/catmaid/models.py @@ -157,7 +157,11 @@ class Stack(models.Model): "stack. Supported is the boolean field \"clamp\" which can be set " "\"to \"false\" to disable tile access clamping as well as the 3-tuple " "\"voxelOffset\", which can be used to offset the voxels space of " - "the stack by the respective vector.") + "the stack by the respective vector. Some mirror types support " + "reading custom configuration information from this field. For " + "instance the cloud-volume tile source can cache the 'info' file " + "of a Neuroglancer Precopmuted info file in the 'ngpreInfo' metadata " + "field.") attribution = models.TextField(blank=True, null=True, help_text="Attribution or citation information for this dataset.") canary_location = Integer3DField(default=(0, 0, 0), help_text="Stack space " diff --git a/sphinx-doc/source/tile_sources.rst b/sphinx-doc/source/tile_sources.rst index 2c23493840..f20474af86 100644 --- a/sphinx-doc/source/tile_sources.rst +++ b/sphinx-doc/source/tile_sources.rst @@ -368,6 +368,14 @@ Tile source types are listed by the enumeration integer ID referenced by Currently, only HTTPS mode is supported (i.e. no explicit credentials). + If the dataset is stored in Neuroglancer Precomputed format, this tile source + checks for special entries in the stack's ``metadata`` field: ``ngepreInfo`` + and ``ngepreProvenance``. Both fields act as a cache for the real dataset data + and can speed up tile rendering significantly. The first field is simply the + datasets info file. The second one is the datasets ``provenance`` file, and + can be set to ``{"owners": [], "sources": [], "processing": [], "description": + ""}`` if the file is not available. + 14. Neuroglancer precomputed image blocks *****************************************