neu_glance.served_layer

A layer to host: an array, how to show it, and its translation into neuroglancer terms.

ServedLayer is what neu_glance.serve() and neu_glance.Server.add_layer() take. neuroglancer is imported only inside functions (the serve extra).

The volume type comes from ``kind``, never from the dtype. neuroglancer would guess that a uint8 label array is an image, averaging label ids and losing the segment UI.

Exceptions

ServeProblem

The arrays or options given cannot be served as asked.

Classes

ServedLayer

One array to host, and how to show it.

Module Contents

exception neu_glance.served_layer.ServeProblem

Bases: RuntimeError

The arrays or options given cannot be served as asked.

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

class neu_glance.served_layer.ServedLayer

One array to host, and how to show it.

frame is a neu_lib.Frame (voxel size and origin in nm). Without it a crop is placed at nm zero instead of over the volume it came from.

color sets the shader’s single colour, for shaders that have one, such as the probability default (red, with opacity carrying the value); it accepts anything as_hex_color() does. opacity is the layer’s overall opacity, multiplied with the shader’s per-voxel alpha.

channel_axis (a leading, channel-first axis) follows from the array’s rank: 4-D has one, 3-D does not. Passing it is allowed but checked.

classmethod from_array(array: Any, kind: str, *, name: str | None = None, frame: Any = None, voxel_size: Sequence[float] | None = None, origin: Sequence[float] | None = None, channel_axis: bool | None = None, **kwargs) → ServedLayer

An in-memory array. voxel_size/origin build the frame for you.

ServedLayer.from_array(prob, “probability”, voxel_size=(40, 8, 8))

channel_axis follows from the array’s rank (see ServedLayer).

classmethod from_hdf5(path: str, dataset: str | None = None, kind: str | None = None, *, crop: Any = None, name: str | None = None, voxel_size: Sequence[float] | None = None, **kwargs) → ServedLayer

One dataset of an HDF5 file, with the frame it records about itself.

ServedLayer.from_hdf5(“piece.h5”, kind=”segmentation”) ServedLayer.from_hdf5(“gt.h5”, “/z07901”, “segmentation”)

dataset may be omitted when the file holds exactly one 3D+ array. The frame comes from the file’s voxel_size / axes / voxel_offset attributes, as neu-vol to-hdf5 writes them; voxel_size overrides, and is required if the file records none. kind is required, since HDF5 has no standard place to record it. The format is forced to HDF5, whatever the extension.

classmethod from_piece(piece: Any, kind: str | None = None, *, name: str | None = None, **kwargs) → ServedLayer

A neu_lib.Piece — an array that already carries its frame and kind.

piece = neu_vol.read_piece(“gt.h5:/vol_03700”, “segmentation”) layer = ServedLayer.from_piece(piece)

kind and name default to the piece’s own. If the piece’s kind is None, pass one: it is not guessed from the dtype.

classmethod from_source(src: str, kind: str | None = None, *, level: int = 0, crop: Any = None, name: str | None = None, voxel_size: Sequence[float] | None = None, **kwargs) → ServedLayer

Anything readable, addressed as PATH or PATH:/DATASET.

The form the CLI takes. The format is detected, and a trailing :/name selects a dataset in an HDF5 file (only a colon followed by a slash, so s3:// is safe).

classmethod from_volume(volume: str, kind: str | None = None, *, level: int = 0, crop: Any = None, name: str | None = None, voxel_size: Sequence[float] | None = None, **kwargs) → ServedLayer

A box out of a stored volume — zarr, precomputed, an image stack.

ServedLayer.from_volume(“s3://my-bucket/seg_v1”, level=1,

crop=((0, 0, 0), (64, 512, 512)))

kind defaults to what the volume records (precomputed’s info["type"], OME-NGFF’s multiscales type) and is required only where it records nothing. A whole volume is usually too large for memory, so pass crop.

array: Any
property bbox: Any

Where this layer sits, in its frame’s voxels. See piece.

property bounds_nm: Any

Where this layer sits, in nanometres. Also what crop= reads off a layer.

channel_axis: bool | None = None
color: Any = None
frame: Any = None
kind: str = 'image'
name: str | None = None
opacity: float | None = None
property piece: Any

This layer’s array and frame as a neu_lib.Piece, for .bbox, .bounds_nm and .crop().

shader: str | None = None