Skip to content

feat: allow pointing directly at mesh and skeleton paths #628

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

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
44 changes: 39 additions & 5 deletions cloudvolume/datasource/precomputed/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import Optional, Union

import os

from .image import PrecomputedImageSource
from .metadata import PrecomputedMetadata
from .mesh import PrecomputedMeshSource
Expand Down Expand Up @@ -58,13 +60,29 @@ def create_precomputed(
use_https=use_https # for parsing redirects
)

readonly = bool(meta.redirected_from)

if meta.info.get("@type", "") == "neuroglancer_skeletons":
info = meta.info
meta = synthetic_meta(cloudpath, config, cache_service)
meta.info["skeletons"] = os.path.basename(cloudpath)
skeleton = PrecomputedSkeletonSource(meta, cache_service, config, readonly, info=info)
else:
skeleton = PrecomputedSkeletonSource(meta, cache_service, config, readonly)

if meta.info.get("@type", "") in ["neuroglancer_legacy_mesh", "neuroglancer_multilod_draco"]:
info = meta.info
meta = synthetic_meta(cloudpath, config, cache_service)
meta.info["mesh"] = os.path.basename(cloudpath)
mesh = PrecomputedMeshSource(meta, cache_service, config, readonly, info=info)
else:
mesh = PrecomputedMeshSource(meta, cache_service, config, readonly)

if mesh_dir:
meta.info['mesh'] = str(mesh_dir)
if skel_dir:
meta.info['skeletons'] = str(skel_dir)

readonly = bool(meta.redirected_from)

if readonly:
print(yellow("""
Redirected
Expand Down Expand Up @@ -99,9 +117,6 @@ def create_precomputed(
lru_bytes=lru_bytes,
)

mesh = PrecomputedMeshSource(meta, cache_service, config, readonly)
skeleton = PrecomputedSkeletonSource(meta, cache_service, config, readonly)

cv = CloudVolumePrecomputed(
meta, cache_service, config,
image, mesh, skeleton,
Expand All @@ -113,6 +128,25 @@ def create_precomputed(

return cv

def synthetic_meta(cloudpath, config, cache_service) -> PrecomputedMetadata:
info = PrecomputedMetadata.create_info(
num_channels=1,
layer_type="segmentation",
data_type='uint8',
encoding="raw",
resolution=[1,1,1],
voxel_offset=[0,0,0],
volume_size=[1,1,1],
)
return PrecomputedMetadata(
os.path.dirname(cloudpath),
config=config,
cache=cache_service,
info=info, provenance=None,
max_redirects=0,
use_https=True # for parsing redirects
)


def register():
register_plugin('precomputed', create_precomputed)
3 changes: 3 additions & 0 deletions cloudvolume/datasource/precomputed/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ def refresh_info(self, max_redirects=10, force_fetch=False):

def parse_rois(self, info) -> List[Bbox]:
"""Parse ROIs from the info file at mip 0."""
if 'scales' not in info:
return None

scale = info['scales'][0]
if 'rois' not in scale:
return None
Expand Down
2 changes: 1 addition & 1 deletion cloudvolume/skeleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,7 @@ def __str__(self):
template.format(attr, buf.shape[0], buf.dtype)
)

return "Skeleton(segid={}, vertices=(shape={}, {}), edges=(shape={}, {}), {}, space='{}' transform={})".format(
return "Skeleton(segid={}, vertices=(shape={}, {}), edges=(shape={}, {}), {}, space='{}', transform={})".format(
self.id,
self.vertices.shape[0], self.vertices.dtype,
self.edges.shape[0], self.edges.dtype,
Expand Down