class NMLParameters(NamedTuple)Contains common metadata for NML files
Notes:
Setting a task bounding boxes will cause wK to 1) render these visually and 2) prevent data loading from outside them.
Attributes:
namestr - Name of a dataset that the annotation is based on. Will cause wK to open the given skeleton annotation with the referenced dataset.scaleVector3[float] - Voxel scale of the referenced dataset in nanometers.offsetOptional[Vector3[float]] - Deprecated. Kept for backward compatibility.timeOptional[int] - A UNIX timestamp marking the creation time & date of an annotation.editPositionOptional[Vector3[float]] - The position of the wK camera when creating/downloading an annotationeditRotationOptional[Vector3[float]] - The rotation of the wK camera when creating/downloading an annotationzoomLevelOptional[float] - The zoomLevel of the wK camera when creating/downloading an annotationtaskBoundingBoxOptional[IntVector6[int]] - A custom bounding box specified as part of a wK task. Will be rendered in wK.userBoundingBoxesOptional[List[IntVector6[int]]] - A list of custom user-defined bounding boxes. Will be rendered in wK.
class Node(NamedTuple)A webKnossos skeleton node annotation object.
Attributes:
idint - A unique identifierpositionVector3 - 3D position of a node. Format: [x, y, z]radiusOptional[float] - Radius of a node when rendered in wK. Unit: nanometers (nm)rotationOptional[Vector3] - 3D rotation of the camera when the node was annotated. Mostly relevant forFlightmode to resume in the same direction when returning toFlightmode.inVpOptional[int] - Enumeration of the wK UI viewport in which the node was annotated.0: XY plane,1: YZ plane.2: XY plane,3: 3D viewportinMagOptional[int] - wK rendering magnification-level when the node was annotated. Lower magnification levels typically indicate a "zoomed-in" workflow resulting in more accurate annotations.bitDepthOptional[int] - wK rendering bit-depth when the node was annotated. 4bit (lower data quality) or 8bit (regular quality). Lower quality data rendering might lead to less accurate annotations.interpolationOptional[bool] - wK rendering interpolation flag when the node was annotated. Interpolated data rendering might lead to less accurate annotations.timeOptional[int] - A Unix timestamp marking the creation time of the node.
class Edge(NamedTuple)A webKnossos skeleton edge.
Attributes:
sourceint - node id referencetargetint - node id reference
class Tree(NamedTuple)A webKnossos skeleton (tree) object. A graph structure consisting of nodes and edges.
Attributes:
id- intcolorVector4 - RGBAname- strnodes- List[Node]edges- List[Edge]groupIdOptional[int] - group id reference
class Branchpoint(NamedTuple)A webKnossos branchpoint, i.e. a skeleton node with more than one outgoing edge.
Attributes:
idint - Reference to aNodeIDtimeint - Unix timestamp
class Group(NamedTuple)A container to group several skeletons (trees) together. Mostly for cosmetic or organizational purposes.
Attributes:
idint - A unique group identifiernamestr - Name of the group. Will be displayed in wK UIchildrenList[Group] - List of all sub-groups belonging to this parent element for nested structures
class Comment(NamedTuple)A single comment belonging to a skeleton node.
Attributes:
nodeint - Reference to aNodeIDcontentstr - A free text field. Supports Markdown formatting.
class Volume(NamedTuple)A metadata reference to a wK volume annotation. Typically, the volume annotation data is provided in a ZIP file in the same directory as the skeleton annotation.
Attributes:
idint - A unique identifierlocationstr - A path to a ZIP file containing a wK volume annotationfallback_layerOptional[str] - Name of an already existing wK volume annotation segmentation layer (aka "fallback layer")
class NML(NamedTuple)A complete webKnossos skeleton annotation object contain one or more skeletons (trees).
Attributes:
parametersNMLParameters - All the metadata attributes associated with a wK annotation.treesList[Tree] - A list of all skeleton/tree objects. Usually contains the majority of the annotated skeleton information.branchpointsList[Branchpoint] - A list of all branchpoint objects.commentsList[Comment] - A list of all comment objects.groupsList[Group] - A list of all group objects.volumeOptional[Volume] - A reference to any volume data that is part of this annotation.
parse_nml(file: BinaryIO) -> NMLReads a webKnossos NML skeleton file from disk, parses it and returns an NML Python object
Arguments:
fileBinaryIO - A Python file handle
Returns:
NML- A webKnossos skeleton annotation as Python NML object
Example:
with open("input.nml", "rb") as f:
nml = wknml.parse_nml(f, nml)
write_nml(file: BinaryIO, nml: NML)Writes an NML object to a file on disk.
Arguments:
fileBinaryIO - A Python file handlenmlNML - A NML object that should be persisted to disk
Example:
with open("out.nml", "wb") as f:
wknml.write_nml(f, nml)
random_color_rgba() -> Tuple[float, float, float, float]A utility to generate a new random RGBA color.
discard_children_hierarchy(groups: List[Group]) -> List[Group]A utility to flatten the group structure. All sub-groups will become top-level items.
globalize_tree_ids(group_dict: Dict[str, List[nx.Graph]])A utility to in-place re-assign new and globally unqiue IDs to all Tree objects. Starts with ID 1
Arguments:
group_dictDict[str, List[nx.Graph]] - A mapping of group names to a list of trees as NetworkX graph objects
globalize_node_ids(group_dict: Dict[str, List[nx.Graph]])A utility to in-place re-assign new and globally unqiue IDs to all Node objects. Edges are updated accordingly. Starts with ID 1.
Arguments:
group_dictDict[str, List[nx.Graph]] - A mapping of group names to a list of trees as NetworkX graph objects
generate_nml(tree_dict: Union[List[nx.Graph], Dict[str, List[nx.Graph]]], parameters: Dict[str, Any] = {}, globalize_ids: bool = True, volume: Optional[Dict[str, Any]] = None) -> NMLA utility to convert a NetworkX graph object into wK NML skeleton annotation object. Accepts both a simple list of multiple skeletons/trees or a dictionary grouping skeleton inputs.
Arguments:
tree_dictUnion[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.parametersDict[str, Any] - A dictionary representation of the skeleton annotation metadata. SeeNMLParametersfor accepted attributes.globalize_idsbool = True - An option to re-assign new, globally unique IDs to all skeletons. Default:TruevolumeOptional[Dict[str, Any]] = None - A dictionary representation of a reference to a wK volume annotation. SeeVolumeobject for attributes.
Returns:
nmlNML - A wK NML skeleton annotation object
generate_graph(nml: NML) -> Tuple[Dict[str, List[nx.Graph]], Dict[Text, any]]A utility to convert a wK NML object into a NetworkX graph object. Skeletons/Trees are grouped by the provided groups in the NML file.
Arguments:
nmlNML - A wK NML skeleton annotation object
Returns:
A tuple consisting of:
- A dictionary with group names as keys and lists of all respective NML trees as values
- A dictionary representation of the NML metadata parameters. See
NMLParametersfor attributes.
nml_tree_to_graph(tree: Tree) -> nx.GraphA utility to convert a single wK Tree object into a NetworkX graph object.
extract_nodes_and_edges_from_graph(graph: nx.Graph) -> Tuple[List[Node], List[Edge]]A utility to convert a single NetworkX graph object into a list of Node objects and Edge objects.
Return Tuple[List[Node], List[Edge]]: A tuple containing both all nodes and all edges