API reference
Modules for processing tree-like morphology reconstructions.
Module tree
- class treem.Tree[source]
Recursive tree data structure.
- ascendorder()[source]
Iterates tree nodes in ascending order until root is reached.
- Yields:
sequence of tree nodes (generator object).
- forks(iterator=<function Tree.preorder>)[source]
Iterates tree branching points.
- Parameters:
iterator – iterator type (defaults to
Tree.preorder)- Returns:
sequence of tree nodes (generator object).
- level()
Returns node depth.
- levelorder()[source]
Traverses tree in level-order (breadth first).
- Yields:
sequence of tree nodes (generator object).
- postorder()[source]
Traverses tree in post-order (breadth first).
- Yields:
sequence of tree nodes (generator object).
Module morph
- class treem.Node(value=None)[source]
Morphology data storage.
- section(reverse=False)[source]
Iterates through the nodes of the section.
Iteration starts with the current node and procedes until the end of the section.
- Parameters:
reverse (bool) – ascending order if True (defaults to False).
- Yields:
sequence of nodes (generator object).
- sections()[source]
Iterates through the sections in descending order.
Iterations traverse entire branch starting with the current node.
- Yields:
sequence of sections (generator object).
- walk(reverse=False)[source]
Iterates through the tree nodes starting from the current node.
Iteration is terminated when root is reached if reverse is True. If False, full tree is traversed downstream in pre-order.
- Parameters:
reverse (bool) – walk the tree in ascending order if True.
- Returns:
sequence of tree nodes (generator object).
- class treem.Morph(source=None, data=None)[source]
Neuron morphology representation.
- load(source=None, data=None)[source]
Fill-in Morph from source file or data.
- Parameters:
source (str) – source file (swc).
data (NumPy ndarray) – morphology data (N, 7).
- rotate(axis, angle, node=None)[source]
Rotates branch at the node.
Branch is traversed downstream from the given node.
- Parameters:
axis (float[3]) – rotation axis.
angle (float) – rotation angle in degrees.
node (treem.Node) – starting node (defaults to root).
- translate(shift, node=None)[source]
Shifts coordinates of the branch at the given node.
Branch is traversed downstream from the given node.
- Parameters:
shift (float[3]) – translation vector.
node (treem.Node) – starting node (defaults to root).
Module io
SWC data format defintion and services.
- class treem.io.TreemEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]
Extended JSONEncoder to serialize treem objects.
- default(obj)[source]
Implement this method in a subclass such that it returns a serializable object for
o, or calls the base implementation (to raise aTypeError).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)
Module utils
Miscellaneous functions.
Module utils.geom
Utilities for manipulating geometry of morphology reconstructions.
- treem.utils.geom.angle_between(u, v)[source]
Returns angle in radians between two 3D vectors (float[3]).
- treem.utils.geom.fibonacci_sphere(npoints=100)[source]
Samples equally spaced points on a unit sphere.
- Parameters:
npoints (int) – sample size [100].
- Returns:
array of 3D points (NumPy ndarray[3]).
- treem.utils.geom.repair_branch(cmorph, cut, rmorph, rep, force=False, keep_radii=False)[source]
Attempts to extend cut neurite using intact branch.
- Parameters:
cmorph (treem.Morph) – cut morphology.
cut (treem.Node) – cut node, from cmorph.
rmorph (treem.Morph) – repair morphology.
rep (treem.Node) – undamaged branch start node, from rmorph.
force (bool) – force repair if branch is too short.
keep_radii (bool) – do not scale radii of repaired branch.
- Returns:
True if repaired.
- treem.utils.geom.rotation(u, v)[source]
Computes rotation axis and angle for two 3D vectors (float[3]).
- Returns:
axis (NumPy ndarray[3]), angle (float)
rotation axis, rotation angle in radians.
Module utils.plot
Plotting utilities.
- treem.utils.plot.plot_neuron(ax, morph, types=range(1, 5), colors=None, linewidth=1)[source]
Plots neuron morphology.
- Parameters:
ax – matplotlib axes object.
morph (treem.Morph) – neuron morphology.
types (int iterable) – point types to be displayed.
colors (dict) – colors for point types ({pt: colspec}).
linewidth (int) – line width.
- treem.utils.plot.plot_points(ax, morph, ids, types=range(1, 5), show_id=False, markersize=6)[source]
Plots marker points.
- Parameters:
ax – matplotlib axes object.
morph (treem.Morph) – neuron morphology.
ids (int iterable) – list of node IDs.
types (int iterable) – point types to display.
- treem.utils.plot.plot_section(ax, tree, data, **kwargs)[source]
Plots single section.
- Parameters:
ax – matplotlib axes object.
tree (treem.Node) – branch start node.
data (NumPy ndarray) – raw data of morphology Morph.
kwargs – arguments for matplotlib plot().
- treem.utils.plot.plot_tree(ax, tree, data, **kwargs)[source]
Plots entire branch.
- Parameters:
ax – matplotlib axes object.
tree (treem.Node) – branch start node.
data (NumPy ndarray) – raw data of morphology Morph.
kwargs – arguments for matplotlib plot().
Module cli
Command-line interface to package treem.