neu_glance.sources

Layers built from something on a store: a volume, or a precomputed annotation source.

The only module in this package that reads a store, so neu_glance.state and neu_glance.layers stay pure and work for locally served sources that have no store.

Two choices here fail silently if made wrong:

  • The source scheme (precomputed:// or zarr://) comes from detect_backend(), not from the path.

  • Volume or annotation source. Both are precomputed:// with an info at the root, and an annotation layer pointed at a volume loads and draws nothing. Only the @type tells them apart, so read_annotation_info() checks it.

Attributes

Exceptions

SourceProblem

A named volume or annotation source could not be used as a layer source.

Functions

annotation_layer(source, *[, name, shader, ...]) → tuple[dict, dict]

One annotation layer for a precomputed annotation source, plus its frame.

annotation_source_extent(info) → tuple[tuple, tuple] | None

(extent_zyx, offset_zyx) from an annotation source's declared bounds.

annotation_source_voxel_size(info) → tuple | None

Level-0 voxel size in nm, zyx, from the source's dimensions.

end_layers(source, *, linked_segmentation[, shader, info]) → list[dict]

The presyn and postsyn layers of a synapse source (END_LAYERS).

layer_volume(layer) → str | None

The precomputed volume a state's layer reads, as a location: the source without

read_annotation_info(source) → dict

The info of a precomputed annotation source, refusing anything else.

read_segment_properties(volume, *[, info]) → dict

Everything a volume's segment_properties carries, in ONE read.

segment_boxes(volume, segment_ids, *[, lod, mesh_dir, ...]) → dict[str, tuple[tuple, tuple]]

{segment_id: (lo_zyx, hi_zyx)} in nanometres, from each segment's mesh.

segment_ids(volume, names, *[, info]) → list[str]

Segment ids for names, in order. Raises on a name the source does not carry.

segment_labels(volume, *[, info]) → dict[str, str]

{segment_id: label} from a volume's segment_properties subresource.

segment_tags(volume, *[, info]) → dict[str, tuple]

{segment_id: (tag, ...)}, tags resolved from their vocabulary indices.

segments_with_meshes(volume, segment_ids, *[, ...]) → list[str]

The subset of segment_ids whose meshes are actually in the store, in order.

select_segments(volume, *[, tags, any_tags, without, ...]) → list[str]

Segment ids matching a tag and/or label query.

volume_extent(volume, fmt) → tuple[tuple, tuple] | None

(extent_zyx, offset_zyx) in level-0 voxels, or None if not determinable.

volume_layer(volume, *[, kind, name, segments, ...]) → tuple[dict, dict]

One layer for volume, plus what its metadata says about the frame.

Module Contents

exception neu_glance.sources.SourceProblem

Bases: RuntimeError

A named volume or annotation source could not be used as a layer source.

Initialize self. See help(type(self)) for accurate signature.

neu_glance.sources.annotation_layer(source: str, *, name: str | None = None, shader: str | None = None, linked_segmentation: str | None = None, filter_by_segmentation: bool = True, filter_relationships: Sequence[str] | None = None, controls: Mapping[str, Any] | None = None, info: Mapping[str, Any] | None = None) → tuple[dict, dict]

One annotation layer for a precomputed annotation source, plus its frame.

linked_segmentation names a segmentation layer in the same state. Without it the source’s relationships index does nothing: neuroglancer only uses a relationship once it is bound to a layer whose selected segments it can read, and otherwise draws every annotation.

Every relationship is bound; filter_relationships chooses which ones restrict the view, e.g. only body_pre for the selected body’s outputs. Each can be toggled in the layer’s Annotations tab.

neu_glance.sources.annotation_source_extent(info: Mapping[str, Any]) → tuple[tuple, tuple] | None

(extent_zyx, offset_zyx) from an annotation source’s declared bounds.

Lets an annotations-only link open framed on its data, as volume_extent() does for a volume.

neu_glance.sources.annotation_source_voxel_size(info: Mapping[str, Any]) → tuple | None

Level-0 voxel size in nm, zyx, from the source’s dimensions.

dimensions is {axis: [scale, unit]} in SI units (metres). None if absent or not in metres.

neu_glance.sources.end_layers(source: str, *, linked_segmentation: str, shader: str | None = None, info: Mapping[str, Any] | None = None) → list[dict]

The presyn and postsyn layers of a synapse source (END_LAYERS).

A layer filtered on both relationships draws both ends of every synapse touching the selected bodies, so the partners’ ends come too; these show only the ends that lie on the selected bodies.

neu_glance.sources.layer_volume(layer: Mapping[str, Any]) → str | None

The precomputed volume a state’s layer reads, as a location: the source without neuroglancer’s scheme (precomputed://s3://b/v or s3://b/v|neuroglancer-precomputed: -> s3://b/v). None for any other kind of source.

neu_glance.sources.read_annotation_info(source: str) → dict

The info of a precomputed annotation source, refusing anything else.

neu_glance.sources.read_segment_properties(volume: str, *, info: Mapping[str, Any] | None = None) → dict

Everything a volume’s segment_properties carries, in ONE read.

Returns {"ids", "labels", "tags", "numbers", "vocabulary"}: ids as strings, labels parallel to them, tags resolved from indices to strings, and each numeric property under its own name. Pass the result to select_segments() to query it without re-reading. Properties are paired with ids by position, so a length mismatch raises.

neu_glance.sources.segment_boxes(volume: str, segment_ids: Sequence[Any], *, lod: int | None = None, mesh_dir: str | None = None, threads: int = 8, skip_missing: bool = True) → dict[str, tuple[tuple, tuple]]

{segment_id: (lo_zyx, hi_zyx)} in nanometres, from each segment’s mesh.

For neu_glance.movie.animate.Timeline.frame_on(). Bounds come from the mesh rather than a coarse level of the segmentation, where a thin arbor can shrink or vanish and the box would be wrong. lod=None reads the coarsest level of detail, which is small and bounds the object just as well. Sharded sources and a source’s own transform are handled, so the result is in nm.

skip_missing drops a segment with no mesh; a structurally broken source still raises.

neu_glance.sources.segment_ids(volume: str, names: Sequence[str], *, info: Mapping[str, Any] | None = None) → list[str]

Segment ids for names, in order. Raises on a name the source does not carry.

A mistyped name raises (with close matches suggested) rather than being dropped. Labels are not unique in this format, so a name matching several segments also raises.

neu_glance.sources.segment_labels(volume: str, *, info: Mapping[str, Any] | None = None) → dict[str, str]

{segment_id: label} from a volume’s segment_properties subresource.

Lets code name segments ("LAL(L)") rather than ids. The format pairs ids and values by position, so arrays of different lengths raise rather than mislabel segments.

neu_glance.sources.segment_tags(volume: str, *, info: Mapping[str, Any] | None = None) → dict[str, tuple]

{segment_id: (tag, ...)}, tags resolved from their vocabulary indices.

neu_glance.sources.segments_with_meshes(volume: str, segment_ids: Sequence[Any], *, mesh_dir: str | None = None, threads: int = 32) → list[str]

The subset of segment_ids whose meshes are actually in the store, in order.

One segment with no mesh hangs a render indefinitely. Neuroglancer waits for its mesh chunk forever, so the viewer never reports ready and the capture stalls at N-1 / N chunks. segment_properties lists every segment, including unmeshed ones, so filter a set through this before rendering it.

One existence check per body (cheap for unsharded meshes). A sharded source has no per-body object to check, so every id is returned unchecked.

neu_glance.sources.select_segments(volume: str, *, tags: Sequence[str] | None = None, any_tags: Sequence[str] | None = None, without: Sequence[str] | None = None, label: str | None = None, limit: int | None = None, order_by: str | None = 'voxels', properties: Mapping | None = None) → list[str]

Segment ids matching a tag and/or label query.

  • tags: all must be present;

  • any_tags: at least one must be;

  • without: none may be (e.g. fragment, truncated);

  • label: a regular expression, searched (not anchored) in the label.

Conditions combine with “and”, so tags=["side:L"], label=r"^KC" is left-side KCs. No match returns an empty list; an unknown tag raises. limit keeps the largest by order_by (voxels); order_by=None keeps the source’s order. Sets can be very large (thousands of bodies), so check the count before rendering.

neu_glance.sources.volume_extent(volume: str, fmt: str) → tuple[tuple, tuple] | None

(extent_zyx, offset_zyx) in level-0 voxels, or None if not determinable.

Precomputed answers from the root info; zarr opens the level-0 array once.

neu_glance.sources.volume_layer(volume: str, *, kind: str | None = None, name: str | None = None, segments: Sequence[int] | None = None, opacity: float | None = None, bounds: bool = False) → tuple[dict, dict]

One layer for volume, plus what its metadata says about the frame.

kind ("image" or "segmentation") overrides what the volume records; without it the recorded kind decides, defaulting to image. bounds draws the volume’s bounding box, which neuroglancer shows by default.

neu_glance.sources.ANNOTATION_TYPE = 'neuroglancer_annotations_v1'
neu_glance.sources.END_LAYERS