Skip to content

webknossos.dataset

AgglomerateAttachment

AgglomerateAttachment(
    properties: AttachmentProperties, path: UPath
)

Bases: Attachment

container_name class-attribute instance-attribute

container_name = 'agglomerates'

data_format instance-attribute

data_format: Literal[Zarr3, HDF5]

name instance-attribute

name: str = name

path instance-attribute

path: UPath = path

type_name class-attribute instance-attribute

type_name = 'agglomerate'

create classmethod

create(
    path: str | PathLike | UPath,
    graph: AgglomerateGraph,
    *,
    segmentation_dtype: DTypeLike = "uint32"
) -> AgglomerateAttachment

Create and write a Zarr v3 agglomerate attachment from a networkx graph.

The graph must have: - Integer node labels (segment IDs, 1-based) - 'position' node attribute: Vec3Int (x, y, z) - 'affinity' edge attribute: float

Connected components become agglomerates.

The AgglomerateAttachment will be created at path.

segmentation_dtype must match the dtype of the corresponding segmentation layer.

Returns an AgglomerateAttachment usable directly with seg_layer.attachments.add_attachment_as_copy(attachment).

create_and_add_to classmethod

create_and_add_to(
    layer: SegmentationLayer,
    name: str,
    graph: AgglomerateGraph,
) -> AgglomerateAttachment

Create a Zarr v3 agglomerate attachment from a networkx graph and add it to a segmentation layer.

name is the attachment name.

The graph must have: - Integer node labels (segment IDs, 1-based) - 'position' node attribute: Vec3Int (x, y, z) - 'affinity' edge attribute: float

Connected components become agglomerates.

Returns the added AgglomerateAttachment.

from_path_and_name classmethod

from_path_and_name(
    path: str | PathLike | UPath,
    name: str,
    *,
    data_format: AttachmentDataFormat,
    dataset_path: str | PathLike | UPath | None = None
) -> Self

to_graph

to_graph() -> AgglomerateGraph

Read the agglomerate attachment from disk and reconstruct an AgglomerateGraph.

Returns an AgglomerateGraph with: - Integer node labels (segment IDs, 1-based) - 'position' node attribute: Vec3Int (x, y, z) - 'affinity' edge attribute: float

AgglomerateGraph

Bases: Graph

Typed networkx Graph for agglomerate data. Node labels are segment IDs (integers, 1-based).

add_affinity_edge

add_affinity_edge(
    u: int, v: int, *, affinity: float
) -> None

Add an undirected edge between two segment IDs with an affinity score.

add_segment

add_segment(segment_id: int, *, position: Vec3Int) -> None

Add a segment node with a (x, y, z) position.

to_agglomerate_graph_data

to_agglomerate_graph_data(
    segmentation_dtype: DTypeLike = dtype("uint32"),
) -> AgglomerateGraphData

Convert to an AgglomerateGraphData (flat numpy-array representation).

Returns an AgglomerateGraphData with: - segments: segment IDs, segmentation_dtype (uint32 or uint64) - positions: [x, y, z] per segment, dtype int64 - edges: [source, target] segment ID pairs, segmentation_dtype (uint32 or uint64) - affinities: affinity per edge, dtype float32