neuron_morphology.morphology module

class neuron_morphology.morphology.Morphology(nodes, node_id_cb, parent_id_cb)[source]

Bases: sphinx.ext.autodoc.importer._MockObject

Methods

__call__(self, \*args, \*\*kw) Call self as a function.
breadth_first_traversal(self, visit[, …]) Apply a function to each node of a connected graph in breadth-first order
depth_first_traversal(self, visit[, …]) Apply a function to each node of a connected graph in depth-first order
get_compartment_surface_area(self, compartment) Calculate the surface area of a single compartment.
get_compartment_volume(self, compartment) Calculate the volume of a single compartment.
get_root(self) Return the first found root node If the input SWC file does not have any root node, it will return None
get_roots_for_analysis(self[, root, node_types]) Returns a list of all trees to be analyzed, based on the supplied root.
get_soma(self) Return one soma node labeled with SOMA If the input SWC file does not have any node labeled with SOMA, it will return None
swap_nodes_edges(self[, merge_cb, …]) Build a new tree whose nodes are the edges of this tree and vice-versa
validate(self[, strict]) Validate the neuron morphology in
build_intermediate_nodes  
children_of  
clone  
euclidean_distance  
get_branch_order_for_node  
get_branch_order_for_segment  
get_branching_nodes  
get_children  
get_children_of_node_by_types  
get_compartment_for_node  
get_compartment_length  
get_compartment_midpoint  
get_compartments  
get_dimensions  
get_leaf_nodes  
get_max_id  
get_node_by_types  
get_non_soma_nodes  
get_number_of_trees  
get_root_for_tree  
get_root_id  
get_roots  
get_roots_for_nodes  
get_segment_length  
get_segment_list  
get_tree_list  
has_type  
is_node_at_beginning_of_segment  
is_node_at_end_of_segment  
is_soma_child  
midpoint  
node_by_id  
parent_of  
breadth_first_traversal(self, visit, neighbor_cb=None, start_id=None)[source]

Apply a function to each node of a connected graph in breadth-first order

Parameters:
visit : callable

Will be applied to each node. Signature must be visit(node). Return is ignored.

neighbor_cb : callable, optional

Will be used during traversal to find the next nodes to be visited. Signature must be neighbor_cb(node id) -> list of node_ids. Defaults to self.child_ids.

start_id : hashable, optional

Begin the traversal from this node. Defaults to self.get_root_id().

Notes

assumes rooted, acyclic

build_intermediate_nodes(self, make_intermediates_cb, set_parent_id_cb)[source]
children_of(self, node)[source]
clone(self)[source]
depth_first_traversal(self, visit, neighbor_cb=None, start_id=None)[source]

Apply a function to each node of a connected graph in depth-first order

Parameters:
visit : callable

Will be applied to each node. Signature must be visit(node). Return is ignored.

neighbor_cb : callable, optional

Will be used during traversal to find the next nodes to be visited. Signature must be neighbor_cb(node_id) -> list of node_ids. Defaults to self.child_ids.

start_id : hashable, optional

Begin the traversal from this node. Defaults to self.get_root_id().

Notes

assumes rooted, acyclic

static euclidean_distance(node1, node2)[source]
get_branch_order_for_node(self, node)[source]
get_branch_order_for_segment(self, segment)[source]
get_branching_nodes(self, node_types=None)[source]
get_children(self, node, node_types=None)[source]
get_children_of_node_by_types(self, node, node_types)[source]
get_compartment_for_node(self, node, node_types=None)[source]
get_compartment_length(self, compartment)[source]
get_compartment_midpoint(self, compartment)[source]
get_compartment_surface_area(self, compartment: Sequence[Dict]) → float[source]

Calculate the surface area of a single compartment. Treats the compartment as a circular conic frustum and calculates its lateral surface area. This is:

pi * (r_1 + r_2) * sqrt( (r_2 - r_1) ** 2 + L ** 2 )
Parameters:
compartment : two-long sequence. Each element is a node and must have

3d position data (“x”, “y”, “z”) and a “radius”

Returns:
The surface area of the sides of the compartment
get_compartment_volume(self, compartment: Sequence[Dict]) → float[source]

Calculate the volume of a single compartment. Treats the compartment as a circular conic frustum and calculates its volume as:

pi * L * (r_1 ** 2 + r_1 * r_2 + r_2 ** 2) / 3
Parameters:
compartment : two-long sequence. Each element is a node and must have

3d position data (“x”, “y”, “z”) and a “radius”

Returns:
The volume of the compartment
get_compartments(self, nodes=None, node_types=None)[source]
get_dimensions(self, node_types=None)[source]
get_leaf_nodes(self, node_types=None)[source]
get_max_id(self)[source]
get_node_by_types(self, node_types=None)[source]
get_non_soma_nodes(self)[source]
get_number_of_trees(self, nodes=None)[source]
get_root(self)[source]

Return the first found root node If the input SWC file does not have any root node, it will return None

Parameters:
morphology: Morphology object
Returns:
Root node object
get_root_for_tree(self, tree_number)[source]
get_root_id(self)[source]
get_roots(self)[source]
get_roots_for_analysis(self, root=None, node_types=None)[source]

Returns a list of all trees to be analyzed, based on the supplied root. These trees are the list of all children of the root, if root is not None, and the root node of all trees in the morphology if root is None.

Parameters:
morphology: Morphology object
root: dict
This is the node from which to count branches under. When root=None,
all separate trees in the morphology are returned.
node_types: list (AXON, BASAL_DENDRITE, APICAL_DENDRITE)
Type to restrict search to
Returns:
Array of Node objects
get_roots_for_nodes(self, nodes)[source]
get_segment_length(self, segment)[source]
get_segment_list(self, node_types=None)[source]
get_soma(self)[source]

Return one soma node labeled with SOMA If the input SWC file does not have any node labeled with SOMA, it will return None

Parameters:
morphology: Morphology object
Returns:
Soma node object
get_tree_list(self)[source]
has_type(self, node_type)[source]
is_node_at_beginning_of_segment(self, node)[source]
is_node_at_end_of_segment(self, node)[source]
is_soma_child(self, node)[source]
static midpoint(node1, node2)[source]
node_by_id(self, node_id)[source]
parent_of(self, node)[source]
swap_nodes_edges(self, merge_cb=None, parent_id_cb=None, make_root_cb=None, start_id=None)[source]

Build a new tree whose nodes are the edges of this tree and vice-versa

Parameters:
merge_cb : callable, optional
parent_id_cb : callable, optional
make_root_cb : callable, optional
start_id : hashable, optional

Notes

assumes rooted, acyclic

validate(self, strict=False)[source]
Validate the neuron morphology in
[bits, radius, resample, type, structure]