Skip to content

Commit

Permalink
make cloud volume import optional
Browse files Browse the repository at this point in the history
  • Loading branch information
fcollman committed Jan 30, 2024
1 parent 40d27b9 commit aa0b558
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion python/neuroglancer/write_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,21 @@
import struct
from collections.abc import Sequence
from typing import Literal, NamedTuple, Optional, Union, cast
from cloudvolume.datasource.precomputed.sharding import ShardingSpecification, synthesize_shard_files
from logging import warning
try:
from cloudvolume.datasource.precomputed.sharding import (
ShardingSpecification, synthesize_shard_files
)
except ImportError:
class ShardingSpecification:
def __init__(self, *args, **kwargs):
raise NotImplementedError("cloudvolume is not installed")

def synthesize_shard_files(*args, **kwargs):
raise NotImplementedError("cloudvolume is not installed")

warning("cloudvolume is not installed, so sharding is not supported."
"pip install cloud-volume to install")

import numpy as np

Expand Down Expand Up @@ -125,6 +139,7 @@ def __init__(
self.related_annotations = [{} for _ in self.relationships]
self.id_sharding_spec = id_sharding_spec


def get_chunk_index(self, coords):
return tuple(((coords-self.lower_bound) // self.chunk_size).astype(np.int32))

Expand All @@ -140,6 +155,7 @@ def add_point(self, point: Sequence[float], id: Optional[int] = None, **kwargs):

#self.lower_bound = np.minimum(self.lower_bound, point)
self.upper_bound = np.maximum(self.upper_bound, point)
self.kdtree.add(point)
self._add_obj(point, id, **kwargs)

def add_axis_aligned_bounding_box(
Expand Down

0 comments on commit aa0b558

Please sign in to comment.