webknossos.skeleton.tree
¶
Graph
¶
Graph(name: str, group: Group, skeleton: Skeleton, color: Optional[Vector4] = None, enforced_id: Optional[int] = None)
Bases: Tree
Deprecated, please use Tree
instead.
id
property
¶
id: int
The unique identifier of the tree.
Returns:
-
int
(int
) –A unique identifier for this tree instance.
Note
This is a read-only property that is set during tree creation.
add_node
¶
add_node(position: Vec3IntLike, comment: Optional[str] = None, radius: Optional[float] = None, rotation: Optional[Vector3] = None, inVp: Optional[int] = None, inMag: Optional[int] = None, bitDepth: Optional[int] = None, interpolation: Optional[bool] = None, time: Optional[int] = None, is_branchpoint: bool = False, branchpoint_time: Optional[int] = None, _enforced_id: Optional[int] = None) -> Node
Add a new node to the tree.
Creates a new node at the specified position and adds it to the tree.
Parameters:
-
position
(Vec3IntLike
) –The 3D coordinates (x, y, z) of the node.
-
comment
(Optional[str]
, default:None
) –A text comment associated with the node. Visible in the WEBKNOSSOS UI. Defaults to None.
-
radius
(Optional[float]
, default:None
) –Node radius for visualization. Defaults to None.
-
rotation
(Optional[Vector3]
, default:None
) –3D rotation vector for the node. Defaults to None.
-
inVp
(Optional[int]
, default:None
) –Viewport information. Defaults to None.
-
inMag
(Optional[int]
, default:None
) –Magnification level. Defaults to None.
-
bitDepth
(Optional[int]
, default:None
) –Bit depth for node data. Defaults to None.
-
interpolation
(Optional[bool]
, default:None
) –Whether to use interpolation. Defaults to None.
-
time
(Optional[int]
, default:None
) –Timestamp for the node. Defaults to None.
-
is_branchpoint
(bool
, default:False
) –Whether this node is a branch point. Defaults to False.
-
branchpoint_time
(Optional[int]
, default:None
) –Timestamp for branch point creation. Defaults to None.
-
_enforced_id
(Optional[int]
, default:None
) –Internal use only. Forces a specific node ID. Defaults to None.
Returns:
-
Node
(Node
) –The newly created and added node.
Examples:
# Add a simple node with just position
node1 = tree.add_node(position=(100, 200, 300))
# Add a node with additional properties
node2 = tree.add_node(
position=(150, 250, 350),
comment="Dendrite branch point",
radius=2.5,
is_branchpoint=True
)
get_max_node_id
¶
get_max_node_id() -> int
Get the highest node ID in the tree.
Returns:
-
int
(int
) –The maximum node ID present in the tree. Returns 0 if the tree has no nodes.
get_node_by_id
¶
get_node_by_id(node_id: int) -> Node
Retrieve a node using its unique identifier.
Parameters:
-
node_id
(int
) –The unique identifier of the node to retrieve.
Returns:
-
Node
(Node
) –The node with the specified ID.
Raises:
-
KeyError
–If no node exists with the given ID in this tree.
get_node_positions
¶
get_node_positions() -> ndarray
Get positions of all nodes in the tree.
Returns:
-
ndarray
–np.ndarray: A numpy array of shape (N, 3) containing the 3D positions of all N nodes in the tree. Each row represents a node's (x, y, z) coordinates.
Tree
¶
Tree(name: str, group: Group, skeleton: Skeleton, color: Optional[Vector4] = None, enforced_id: Optional[int] = None)
Bases: Graph
Contains a collection of nodes and edges in a graph structure.
Despite the name, trees may contain cycles. This class inherits from networkx.Graph and provides additional functionality specific to neural annotation tasks.
Parameters:
-
name
(str
) –The name of the tree.
-
group
(Group
) –The group this tree belongs to.
-
skeleton
(Skeleton
) –The skeleton this tree is part of.
-
color
(Optional[Vector4]
, default:None
) –RGBA color values for the tree. Defaults to None.
-
enforced_id
(Optional[int]
, default:None
) –Specific ID to use for the tree. Defaults to None.
Returns:
-
Tree
–A new Tree instance that represents a collection of nodes and edges.
Raises:
-
ValueError
–If the tree name is empty or if the group or skeleton is None.
-
TypeError
–If the color value is not a valid Vector4 type when provided.
Note
It is recommended to create trees using Skeleton.add_tree
or Group.add_tree
instead of instantiating this class directly. This ensures proper parent-child
relationships are maintained.
Examples:
Create a new tree with nodes and edges:
# First create a skeleton (parent object)
skeleton = Skeleton("example_skeleton")
# Add a new tree to the skeleton
tree = skeleton.add_tree("dendrite_1")
# Add nodes with 3D positions
soma = tree.add_node(position=(0, 0, 0), comment="soma")
branch1 = tree.add_node(position=(100, 0, 0), comment="branch1")
branch2 = tree.add_node(position=(0, 100, 0), comment="branch2")
# Connect nodes with edges
tree.add_edge(soma, branch1)
tree.add_edge(soma, branch2)
# Access node positions
positions = tree.get_node_positions() # Returns numpy array of all positions
For additional graph operations, see the networkx documentation.
To create a tree, it is recommended to use Skeleton.add_tree
or
Group.add_tree
. That way, the newly created tree is automatically
attached as a child to the object the method was called on.
id
property
¶
id: int
The unique identifier of the tree.
Returns:
-
int
(int
) –A unique identifier for this tree instance.
Note
This is a read-only property that is set during tree creation.
add_node
¶
add_node(position: Vec3IntLike, comment: Optional[str] = None, radius: Optional[float] = None, rotation: Optional[Vector3] = None, inVp: Optional[int] = None, inMag: Optional[int] = None, bitDepth: Optional[int] = None, interpolation: Optional[bool] = None, time: Optional[int] = None, is_branchpoint: bool = False, branchpoint_time: Optional[int] = None, _enforced_id: Optional[int] = None) -> Node
Add a new node to the tree.
Creates a new node at the specified position and adds it to the tree.
Parameters:
-
position
(Vec3IntLike
) –The 3D coordinates (x, y, z) of the node.
-
comment
(Optional[str]
, default:None
) –A text comment associated with the node. Visible in the WEBKNOSSOS UI. Defaults to None.
-
radius
(Optional[float]
, default:None
) –Node radius for visualization. Defaults to None.
-
rotation
(Optional[Vector3]
, default:None
) –3D rotation vector for the node. Defaults to None.
-
inVp
(Optional[int]
, default:None
) –Viewport information. Defaults to None.
-
inMag
(Optional[int]
, default:None
) –Magnification level. Defaults to None.
-
bitDepth
(Optional[int]
, default:None
) –Bit depth for node data. Defaults to None.
-
interpolation
(Optional[bool]
, default:None
) –Whether to use interpolation. Defaults to None.
-
time
(Optional[int]
, default:None
) –Timestamp for the node. Defaults to None.
-
is_branchpoint
(bool
, default:False
) –Whether this node is a branch point. Defaults to False.
-
branchpoint_time
(Optional[int]
, default:None
) –Timestamp for branch point creation. Defaults to None.
-
_enforced_id
(Optional[int]
, default:None
) –Internal use only. Forces a specific node ID. Defaults to None.
Returns:
-
Node
(Node
) –The newly created and added node.
Examples:
# Add a simple node with just position
node1 = tree.add_node(position=(100, 200, 300))
# Add a node with additional properties
node2 = tree.add_node(
position=(150, 250, 350),
comment="Dendrite branch point",
radius=2.5,
is_branchpoint=True
)
get_max_node_id
¶
get_max_node_id() -> int
Get the highest node ID in the tree.
Returns:
-
int
(int
) –The maximum node ID present in the tree. Returns 0 if the tree has no nodes.
get_node_by_id
¶
get_node_by_id(node_id: int) -> Node
Retrieve a node using its unique identifier.
Parameters:
-
node_id
(int
) –The unique identifier of the node to retrieve.
Returns:
-
Node
(Node
) –The node with the specified ID.
Raises:
-
KeyError
–If no node exists with the given ID in this tree.
get_node_positions
¶
get_node_positions() -> ndarray
Get positions of all nodes in the tree.
Returns:
-
ndarray
–np.ndarray: A numpy array of shape (N, 3) containing the 3D positions of all N nodes in the tree. Each row represents a node's (x, y, z) coordinates.
- Get Help
- Community Forums
- Email Support