Print skeleton as hierarchical tree.
Note: this really only makes sense for small neurons.
PARAMETER | DESCRIPTION |
x | TYPE: TreeNeuron |
print_func | Function to use for printing. Default is `print`.
TYPE: callable DEFAULT: print |
Source code in navis/plotting/flat.py
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545 | def print_skeleton(x, print_func=print, add_props=None):
"""Print skeleton as hierarchical tree.
Note: this really only makes sense for small neurons.
Parameters
----------
x : TreeNeuron
Neuron to print.
print_func : callable, optional
Function to use for printing. Default is `print`.
Returns
-------
None
"""
def _print_tree(node, last=True, header=""):
"""Recursive print function."""
elbow = "└──"
pipe = "│ "
tee = "├──"
blank = " "
line = f"{header}{elbow if last else tee}{node}"
if add_props:
line += f" ({add_props[node]})"
print_func(line)
children = list(x.graph.predecessors(node))
for i, c in enumerate(children):
_print_tree(
c,
header=header + (blank if last else pipe),
last=i == len(children) - 1,
)
if isinstance(add_props, str):
add_props = x.nodes.set_index("node_id")[add_props].to_dict()
elif isinstance(add_props, (list, np.ndarray, tuple)):
if len(add_props) != len(x.nodes):
raise ValueError("Length of add_props must be the same as number of")
add_props = dict(zip(x.nodes.node_id, add_props))
elif not isinstance(add_props, (dict, type(None))):
raise ValueError(
"add_props must be either None, a string, list, tuple or dict."
)
for root in x.root:
_print_tree(root)
|