Skip to content

webknossos.skeleton.skeleton

Classes:

Skeleton

Bases: Group

Representation of the skeleton of an Annotation. It contains metadata to identify the related dataset and is the root-group of sub-groups and trees. See the parent class Group for methods about group and tree handling. To upload a skeleton to webknossos, please create an Annotation() with it.

A small usage example:

annotation = Annotation(
    name="my_annotation", dataset_name="my_dataset", voxel_size=(11, 11, 24)
)
group = annotation.skeleton.add_group("a group")
tree = group.add_tree("a tree")
node_1 = tree.add_node(position=(0, 0, 0), comment="node 1")
node_2 = tree.add_node(position=(100, 100, 100), comment="node 2")

tree.add_edge(node_1, node_2)

Also see this example for a more complex interaction.

Methods:

  • add_graph

    Deprecated, please use add_tree.

  • add_group

    Adds a (sub) group to the current group with the provided name.

  • add_nx_graphs

    A utility to add nx graphs NetworkX graph object to a wk skeleton object. Accepts both a simple list of multiple skeletons/trees or a dictionary grouping skeleton inputs.

  • add_tree

    Adds a tree to the current group. If the first parameter is a string,

  • as_nml_group

    Returns a named tuple representation of this group.

  • flattened_graphs

    Deprecated, please use flattened_trees.

  • flattened_groups

    Returns an iterator of all groups within this group (and its subgroups).

  • flattened_trees

    Returns an iterator of all trees within this group (and its subgroups).

  • from_path

    Deprecated. Use Skeleton.load instead.

  • get_graph_by_id

    Deprecated, please use get_tree_by_id.

  • get_group_by_id

    Returns the group which has the specified group id.

  • get_max_graph_id

    Deprecated, please use get_max_tree_id.

  • get_max_node_id

    Returns the highest node id of all nodes of all trees within this group (and its subgroups).

  • get_max_tree_id

    Returns the highest tree id of all trees within this group (and its subgroups).

  • get_node_by_id

    Returns the node which has the specified node id.

  • get_total_node_count

    Returns the total number of nodes of all trees within this group (and its subgroups).

  • get_tree_by_id

    Returns the tree which has the specified tree id.

  • has_tree_id

    Returns true if this group (or a subgroup) contains a tree with the given id.

  • load

    Loads a .nml file or a .zip file containing an NML (and possibly also volume

  • remove_tree_by_id
  • save

    Stores the skeleton as a zip or nml at the given path.

  • write

    Deprecated. Use Skeleton.save instead.

Attributes:

  • children (Iterator[GroupOrTree]) –

    Returns all (immediate) children (groups and trees) as an iterator.

  • dataset_name (str) –
  • description (Optional[str]) –
  • graphs (Iterator[Tree]) –

    Deprecated, please use trees.

  • groups (Iterator[Group]) –

    Returns all (immediate) group children as an iterator.

  • id (int) –

    Read-only property.

  • name (str) –

    Should not be used with Skeleton, this attribute is only useful for sub-groups. Set to Root.

  • organization_id (Optional[str]) –
  • scale (Tuple[float, float, float]) –

    Deprecated, please use voxel_size.

  • trees (Iterator[Tree]) –

    Returns all (immediate) tree children as an iterator.

  • voxel_size (Vector3) –

children property

children: Iterator[GroupOrTree]

Returns all (immediate) children (groups and trees) as an iterator.

dataset_name instance-attribute

dataset_name: str

description class-attribute instance-attribute

description: Optional[str] = None

graphs property

graphs: Iterator[Tree]

Deprecated, please use trees.

groups property

groups: Iterator[Group]

Returns all (immediate) group children as an iterator. Use flattened_groups if you need also need groups within subgroups.

id property

id: int

Read-only property.

name class-attribute instance-attribute

name: str = field(default='Root', init=False, eq=False, repr=False)

Should not be used with Skeleton, this attribute is only useful for sub-groups. Set to Root.

organization_id class-attribute instance-attribute

organization_id: Optional[str] = None

scale property writable

scale: Tuple[float, float, float]

Deprecated, please use voxel_size.

trees property

trees: Iterator[Tree]

Returns all (immediate) tree children as an iterator. Use flattened_trees if you need also need trees within subgroups.

voxel_size instance-attribute

voxel_size: Vector3

add_graph

add_graph(name: str, color: Optional[Union[Vector4, Vector3]] = None, _enforced_id: Optional[int] = None) -> Tree

Deprecated, please use add_tree.

add_group

add_group(name: str, _enforced_id: Optional[int] = None) -> Group

Adds a (sub) group to the current group with the provided name.

add_nx_graphs

add_nx_graphs(tree_dict: Union[List[Graph], Dict[str, List[Graph]]]) -> None

A utility to add nx graphs NetworkX graph object to a wk skeleton object. Accepts both a simple list of multiple skeletons/trees or a dictionary grouping skeleton inputs.

Arguments: tree_dict (Union[List[nx.Graph], Dict[str, List[nx.Graph]]]): A list of wK tree-like structures as NetworkX graphs or a dictionary of group names and same lists of NetworkX tree objects.

add_tree

add_tree(name_or_tree: Union[str, Tree], color: Optional[Union[Vector4, Vector3]] = None, _enforced_id: Optional[int] = None) -> Tree

Adds a tree to the current group. If the first parameter is a string, a new tree will be added with the provided name and color if specified. Otherwise, the first parameter is assumed to be a tree object (e.g., from another skeleton). A copy of that tree will then be added. If the id of the tree already exists, a new id will be generated.

as_nml_group

as_nml_group() -> Group

Returns a named tuple representation of this group.

flattened_graphs

flattened_graphs() -> Iterator[Tree]

Deprecated, please use flattened_trees.

flattened_groups

flattened_groups() -> Iterator[Group]

Returns an iterator of all groups within this group (and its subgroups).

flattened_trees

flattened_trees() -> Iterator[Tree]

Returns an iterator of all trees within this group (and its subgroups).

from_path staticmethod

from_path(file_path: Union[PathLike, str]) -> Skeleton

Deprecated. Use Skeleton.load instead.

get_graph_by_id

get_graph_by_id(graph_id: int) -> Tree

Deprecated, please use get_tree_by_id.

get_group_by_id

get_group_by_id(group_id: int) -> Group

Returns the group which has the specified group id.

get_max_graph_id

get_max_graph_id() -> int

Deprecated, please use get_max_tree_id.

get_max_node_id

get_max_node_id() -> int

Returns the highest node id of all nodes of all trees within this group (and its subgroups).

get_max_tree_id

get_max_tree_id() -> int

Returns the highest tree id of all trees within this group (and its subgroups).

get_node_by_id

get_node_by_id(node_id: int) -> Node

Returns the node which has the specified node id.

get_total_node_count

get_total_node_count() -> int

Returns the total number of nodes of all trees within this group (and its subgroups).

get_tree_by_id

get_tree_by_id(tree_id: int) -> Tree

Returns the tree which has the specified tree id.

has_tree_id

has_tree_id(tree_id: int) -> bool

Returns true if this group (or a subgroup) contains a tree with the given id.

load staticmethod

load(file_path: Union[PathLike, str]) -> Skeleton

Loads a .nml file or a .zip file containing an NML (and possibly also volume layers). Returns the Skeleton object. Also see Annotation.load if you want to have the annotation which wraps the skeleton.

remove_tree_by_id

remove_tree_by_id(tree_id: int) -> None

save

save(out_path: Union[str, PathLike]) -> None

Stores the skeleton as a zip or nml at the given path.

write

write(out_path: PathLike) -> None

Deprecated. Use Skeleton.save instead.