Skip to content

Commit

Permalink
Cloud-volume tile source: allow caching of info and provenance data
Browse files Browse the repository at this point in the history
The content of both files can be stored in the stack's metadata field
within the `ngreInfo` and `ngpreProvenance` entries. This can speed up
tile rendering significantly.
  • Loading branch information
tomka committed Aug 6, 2024
1 parent ffe464e commit 1135d92
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
23 changes: 20 additions & 3 deletions django/applications/catmaid/control/tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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')
Expand Down
6 changes: 5 additions & 1 deletion django/applications/catmaid/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
8 changes: 8 additions & 0 deletions sphinx-doc/source/tile_sources.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
*****************************************

Expand Down

0 comments on commit 1135d92

Please sign in to comment.