pymaid.union_neurons

pymaid.union_neurons(*x, limit=1, base_neuron=None, track=False, non_overlap='raise')[source]

Generate the union of a set of neurons.

This implementation works by iteratively merging nodes in neuron A and B that are closer than given threshold. This requires neurons to have a certain amount of overlap.

Parameters:
  • *x (CatmaidNeuron/List) – Neurons to be merged.

  • limit (int, optional) – Max distance [microns] for nearest neighbour search.

  • base_neuron (skeleton_ID | CatmaidNeuron, optional) – Neuron to use as template for union. Node IDs of this neuron will survive. If not provided, the first neuron in the list is used as template!

  • track (bool, optional) – If True, will add new columns to node/connector table of union neuron to keep track of original node IDs and origin: node_id_before, parent_id_before, origin_skeleton

  • non_overlap ("raise" | "stitch" | "skip", optional) – Determines how to deal with non-overlapping fragments. If “raise” will raise an exception. If “stitch” will try stitching the fragments using a minimum spanning tree (see pymaid.stitch_neurons()).

Returns:

Union of all input neurons.

Return type:

core.CatmaidNeuron

See also

stitch_neurons()

If you want to stitch neurons that do not overlap.

Examples

>>> # Get a single neuron
>>> n = pymaid.get_neuron(16)
>>> # Prune to its longest neurite
>>> backbone = n.prune_by_longest_neurite(inplace=False)
>>> # Remove longest neurite and keep only fine branches
>>> branches = n.prune_by_longest_neurite(n=slice(1, None), inplace=False)
>>> # For this exercise we have to make sure skeleton IDs are unique
>>> branches.skeleton_id = 17
>>> # Now put both back together using union
>>> union = pymaid.union_neurons(backbone, branches, limit=2)