nGauge Modules Reference

class ngauge.Neuron.Neuron

A class representing a Neuron, i.e., an object represented by a complete SWC file.

add_branch(toadd)
Parameters

toadd (TracingPoint) – A point to add as a new branch to this Neuron

Return type

None

add_soma_points(toadd)
Parameters

toadd (list of TracingPoint) – An array of soma points to add to this Neuron

Raises

AttributeError – Raised if x, y, z, r are not numeric

Return type

None

all_branch_angles()

Creates a list with angles of all the branch points in a neuron in degrees between [0, 180]

Parameters

n (either Neuron or TracingPoint) – starting point for gathering branch point angles

Returns

all branch angles

Return type

list

Example:
>>> neuron = from_swc("Example1.swc")
>>> neuron.all_branch_angles()
[90.8386644299175, 83.62062979155719, 83.62062979155719, 109.47122063449069]
all_branch_orders()

Creates a list with all the branch orders of all bifurcation points in neuron

Returns

list with all branch orders

Return type

list of int

Example:
>>> neuron = from_swc("Example1.swc")
>>> neuron.all_branch_orders()
    [3,3,2,1]
all_branch_points()
Returns

all_neurites_tortuosities()

Creates a sorted list of the log(tortuosity) values of all the neurites in the input

Returns

all log(tortuosity) values for neurites sorted least to greatest

Return type

list

Example:
>>> neuron = from_swc("Example1.swc")
>>> neuron.all_neurites_tortuosities()
[0.04134791479135339,
 0.05300604176745361,
 0.14956195330433844,
 0.15049238421642142,
 0.18919849587081047]
all_path_angles()

Calculates the path angle for all nodes in a neuron, starting at the node after the root node.

Returns

all the path angles in a neuron

Return type

list of float

Note

branch points, as there are then multiple new branches diverging, will have multiple path angles angles added to returned list

Example:
>>> neuron = from_swc("Example1.swc")
>>> neuron.all_path_angles()
   [114.0948425521107,
     114.0948425521107,
     82.17876449350037,
     162.28452765633213,
     65.9051574478893,
     132.87598866663572,
     88.65276496096037,
     172.50550517788332]
all_segment_lengths()

Creates sorted list of all segment lengths in a neuron`

Returns

all segment lengths sorted by least to greatest distance

Return type

list(float)

Example:
>>> neuron = from_swc("Example1.swc")
>>> lengths = all_segment_lengths(neuron)
>>> type(lengths)
<class 'list'>
>>> lengths
[1.0,
 1.4177446878757824,
 1.445683229480096,
 1.5,
 1.5,
 1.5,
 1.5,
 2.449489742783178,
 2.449489742783178]
arbor_dist()
Returns

The distance from the soma_centroid() to the positional average of all branch TracingPoints

Return type

float

average_thickness()

Determines average radius in microns across all neurites

Returns

average radius in microns

Return type

float

Example:
>>> neuron = from_swc("Example1.swc")
>>> avg_thickness(neuron)
1.0
avg_branch_angle()

Determines the average branch point angle in degrees between [0, 180]

Returns

average branch angle

Return type

float

Example:
>>> neuron = from_swc("Example1.swc")
>>> neuron.avg_branch_angle()
91.88778616188064
branch_angles_histogram(bins=20)
Creates a histogram (an array of counts and an array of edges) of all branch angles with

default of 20 bins between [0, 180] degrees

Parameters

bins (int) – number of bins for histogram to have

Returns

histogram of all branch angles

Return type

tuple of two numpy.array, one with counts and one with edge values

Example:
>>> neuron = from_swc("Example1.swc")
>>> neuron.branch_angles_histogram()
(array([0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0]),
 array([  0.,   9.,  18.,  27.,  36.,  45.,  54.,  63.,  72.,  81.,  90.,
        99., 108., 117., 126., 135., 144., 153., 162., 171., 180.]))
branch_angles_x_branch_orders(bins=20)
Creates a 2D histogram of branch angles as a function of branch orders (across all branch

points) with default bins of 20 and range 0 to max branch order by 0 to 180 degrees

Parameters

bins (int) – number of bins for histogram to have

Returns

2D histogram of branch angles as a function of branch orders

Return type

tuple of three numpy.array, respectively histogram, x edges, and y edges

Example:
>>> neuron = from_swc("Example1.swc")
>>> neuron.branch_angles_x_branch_orders()
(array([[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 2., 1., 0., 1., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.]]),
 array([0.  , 0.15, 0.3 , 0.45, 0.6 , 0.75, 0.9 , 1.05, 1.2 , 1.35, 1.5 ,
        1.65, 1.8 , 1.95, 2.1 , 2.25, 2.4 , 2.55, 2.7 , 2.85, 3.  ]),
 array([  0.,   9.,  18.,  27.,  36.,  45.,  54.,  63.,  72.,  81.,  90.,
         99., 108., 117., 126., 135., 144., 153., 162., 171., 180.]))
branch_angles_x_path_distances(bins=20, maxDist=None)
Creates a 2D histogram of branch angles as a function of path distances to the soma in

microns (across all branch points) with default bins of 20

Parameters
  • bins (int) – number of bins for histogram to have

  • maxDist (float) – maximum distance for the histogram, by default selects the maximum distance

Returns

2D histogram of branch angles as a function of path distances

Return type

tuple of three numpy.array, respectively histogram, x edges, and y edges

Example:
>>> neuron = from_swc("Example1.swc")
>>> neuron.branch_angles_x_path_distances()
(array([[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 2., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.]]),
 array([0.        , 0.24747449, 0.49494897, 0.74242346, 0.98989795,
        1.23737244, 1.48484692, 1.73232141, 1.9797959 , 2.22727038,
        2.47474487, 2.72221936, 2.96969385, 3.21716833, 3.46464282,
        3.71211731, 3.95959179, 4.20706628, 4.45454077, 4.70201526,
        4.94948974]),
 array([  0.,   9.,  18.,  27.,  36.,  45.,  54.,  63.,  72.,  81.,  90.,
         99., 108., 117., 126., 135., 144., 153., 162., 171., 180.]))
branch_order_counts()
Creates list from 0, K with K being the max branch order in the neuron and each i in the

list being the number of bifurcation points with that branch order

Returns

number of bifurcation points for each branch order value

Return type

list of int

Example:
>>> neuron = from_swc("Example1.swc")
>>> neuron.branch_order_counts()
[0, 0, 4]
branch_order_histogram(bins=20)
Creates a histogram (an array of counts and an array of edges) of all

branch orders with a default of 20 bins between [0, 180] degrees

Parameters

bins (int) – number of bins for histogram to have

Returns

histogram of all branch orders

Return type

tuple two numpy.array, one with counts and one with edge values

Example:
>>> neuron = from_swc("Example1.swc")
>>> neuron.branch_order_histogram()
(array([0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 0, 0, 2, 0, 1, 0, 0, 0, 1, 1]),
 array([  0.,   9.,  18.,  27.,  36.,  45.,  54.,  63.,  72.,  81.,  90.,
        99., 108., 117., 126., 135., 144., 153., 162., 171., 180.]))
branches

A list of TracingPoint which are the roots of branches in this Neuron

center_soma()

Performs a translate() such that the soma is located at the origin (0,0,0)

Returns

Nothing

Return type

None

euclidean_distances_to_soma_histogram(bins=20)

Creates a histogram (an array of counts and an array of edges) of the Euclidean distance of each branch point and tip to the soma with default of 20 bins between 0 and maximum length

Parameters

bins (int) – number of bins for histogram to have

Returns

histogram of euclidean distances

Return type

tuple of two numpy.array, one with counts and one with edge values

Example:
>>> neuron = from_swc("Example1.swc")
>>> neuron.euclidean_distances_to_soma_histogram()
(array([0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 1, 0, 0, 1, 1]),
 array([0.   , 0.225, 0.45 , 0.675, 0.9  , 1.125, 1.35 , 1.575, 1.8  ,
        2.025, 2.25 , 2.475, 2.7  , 2.925, 3.15 , 3.375, 3.6  , 3.825,
        4.05 , 4.275, 4.5  ]))
static from_swc(fname, force_format=True)
Parameters

fname (str containing a file path) – A SWC file to import

Returns

A new neuron created from fname

Return type

Neuron

static from_swc_text(data, force_format=True)
Parameters

fname – Import a SWC object from a text object

Returns

A new neuron created from data

Return type

Neuron

get_main_branch(strahler=True)
Returns

The longest branch from the Neuron

Note

Returns None if there are no branches in this Neuron

Parameters

strahler – Default True. Determines if a strahler-order mechanism should be used to determine main branch

Return type

int

iter_all_points(exclude_soma=False)
Parameters

exclude_soma (bool) – Select if soma TracingPoint objects should be included

Returns

An iteration of all TracingPoint in this Neuron

Return type

iterable of TracingPoint

max_branch_angle()

Determines the maximal branch point angle in degrees between [0, 180]

Returns

maximal branch angle

Return type

float

Example:
>>> neuron = from_swc("Example1.swc")
>>> neuron.max_branch_angle()
109.47122063449069
max_branching_order()
Returns

The maximum branch order achieved by any of the child nodes

Return type

int

max_partition_asymmetry(within=1)
Parameters

within (int) – The minimum branching order to include

Returns

The maximum partition asymmetry within a given number of nodes

Note

Returns None if there are no branches registered in this Neuron

Return type

float

max_path_angle()

Determines the maximal path angle across a neuron in degrees between [0, 180]

Returns

maximal path angle

Return type

float

Example:
>>> neuron = from_swc("Example1.swc")
>>> neuron.max_path_angle()
172.50550517788332
max_tortuosity()

Determines the 99.5 percentile of log(tortuosity) across all neurites in a neuron

Returns

99.5 percentile of log(tortuosity)

Return type

float

Example:
>>> neuron = from_swc("Example1.swc")
>>> neuron.max_tortuosity(neuron)
0.1884243736377227
median_path_angle()

Determines the median path angle across a neuron in degrees between [0, 180]

Returns

median path angle

Return type

float

Example:
>>> neuron = from_swc("Example1.swc")
>>> neuron.median_path_angle()
114.0948425521107
median_tortuosity()

Determines the medial log(tortuosity) accross all neurites in a neuron

Returns

median log(tortuosity)

Return type

float

Example:
>>> neuron = from_swc("Example1.swc")
>>> neuron.median_tortuosity(neuron)
0.14956195330433844
metadata

An empty attribute to store metadata from the SWC file

min_branch_angle()

Determines the minimal branch point angle in degrees between [0, 180]

Returns

minimal branch angle

Return type

float

Example:
>>> neuron = from_swc("Example1.swc")
>>> neuron.min_branch_angle()
83.62062979155719
min_partition_asymmetry(within=1)
Parameters

within (int) – The minimum branching order to include

Returns

The minimum partition asymmetry within a given number of nodes

Note

Returns None if there are no branches registered in this Neuron

Return type

float

path_angle_x_branch_order(bins=20)
Creates a 2D histogram of path angles as a function of branch orders (across all nodes)

with default bins of 20

Parameters

bins (int) – number of bins for histogram to have

Returns

2D histogram of path angles as a function of branch orders

Return type

tuple of three numpy.array, respectively histogram, x edges, and y edges

Note

bifurcation nodes will have multiple values in histogram associated with them due to multiple path angles

Example:
>>> neuron = from_swc("Example1.swc")
>>> neuron.path_angle_x_branch_order()
(array([[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 1.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 2.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 2.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 1.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 1.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 1.]]),
 array([  0.,   9.,  18.,  27.,  36.,  45.,  54.,  63.,  72.,  81.,  90.,
         99., 108., 117., 126., 135., 144., 153., 162., 171., 180.]),
 array([0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1. , 1.1, 1.2,
        1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2. ]))
path_angle_x_path_distance(bins=20, maxDist=None)
Creates a 2D histogram of path angles as a function of path distances to the soma in microns

(across all nodes) with default bins of 20

Parameters
  • bins (int) – number of bins for histogram to have

  • maxDist (float) – maximum distance for the calculation of the histogram

Returns

2D histogram of path angles as a function of path distances

Return type

tuple of three numpy.array, respectively histogram, x edges, and y edges

Note

bifurcation nodes will have multiple values in histogram associated with them due to multiple path angles

Example:
>>> neuron = from_swc("Example1.swc")
>>> neuron.path_angle_x_path_distance()
(array([[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 1., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 1., 0., 1., 0.,
         0., 0., 0., 1.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0.,
         0., 0., 1., 0.]]),
 array([0.        , 0.24747449, 0.49494897, 0.74242346, 0.98989795,
        1.23737244, 1.48484692, 1.73232141, 1.9797959 , 2.22727038,
        2.47474487, 2.72221936, 2.96969385, 3.21716833, 3.46464282,
        3.71211731, 3.95959179, 4.20706628, 4.45454077, 4.70201526,
        4.94948974]),
 array([  0.,   9.,  18.,  27.,  36.,  45.,  54.,  63.,  72.,  81.,  90.,
         99., 108., 117., 126., 135., 144., 153., 162., 171., 180.]))
path_angles_histogram(bins=20)
Creates a histogram (an array of counts and an array of edges) of all path angles with

default of 20 bins between [0, 180] degrees

Parameters

bins (int) – number of bins for histogram to have

Returns

histogram of all path angles

Return type

tuple two numpy.array, one with counts and one with edge values

Example:
>>> neuron = from_swc("Example1.swc")
>>> neuron.path_angles_histogram()
(array([0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 0, 0, 2, 0, 1, 0, 0, 0, 1, 1]),
 array([  0.,   9.,  18.,  27.,  36.,  45.,  54.,  63.,  72.,  81.,  90.,
        99., 108., 117., 126., 135., 144., 153., 162., 171., 180.]))
path_distances_to_soma_histogram(bins=20)
Creates a histogram (an array of counts and an array of edges) of the path length of

each branch point and tip to the soma with default of 20 bins between 0 and maximum length

Parameters

bins (int) – number of bins for histogram to have

Returns

histogram of all path distances

Return type

tuple of two numpy.array, one with counts and one with edge values

Example:
>>> neuron = from_swc("Example1.swc")
>>> neuron.path_distance_to_soma_histogram()
(array([0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 4, 0, 0, 0, 2]),
 array([0.        , 0.31975865, 0.6395173 , 0.95927595, 1.27903459,
        1.59879324, 1.91855189, 2.23831054, 2.55806919, 2.87782784,
        3.19758649, 3.51734513, 3.83710378, 4.15686243, 4.47662108,
        4.79637973, 5.11613838, 5.43589703, 5.75565568, 6.07541432,
        6.39517297]))
persistence_diagram(f=<function Neuron.<lambda>>)
Parameters

f (callable( TracingPoint )) – The distance function to calculate a persistance diagram

Returns

A persistance diagram

Return type

tuple of list, representing the X and Y axis

plot(fig=None, ax=None, axis='z', color='blue', linewidth=1)

Draws this Neuron as a figure

Parameters
  • ax (matplotlib.pyplot.axis) – A matplotlib axis object to draw upon

  • fig (matplotlib.pyplot.figure) – A matplotlib figure object to draw upon

  • color (matplotlib color descriptor) – The color to render the line drawing

  • axis (str) – The axis to perform the 3D to 2D projection upon

Note

If no value for ax or fig is supplied, a new one will be generated

Note

The returned matplotlib objects can be manipulated further to generate custom figures

Returns

a matplotlib Figure object which has been rendered.

rotate(x=0, y=0, z=0)

Rotates all points within this Neuron

Parameters
  • x (numeric) – The rotation angle about the x axis

  • y (numeric) – The rotation angle about the y axis

  • z (numeric) – The rotaion angle about the z axis

Returns

Nothing

Return type

None

scale(dx=1, dy=1, dz=1)

Scales the coordinates of all points within this Neuron

Parameters
  • dx (numeric) – The scale along the x axis

  • dy (numeric) – The scale along the y axis

  • dz (numeric) – The scale along the z axis

Returns

Nothing

Return type

None

segment_length_histogram(bins=20)
Creates a histogram (an array of counts and an array of edges) of all euclidean segment lengths

with default of 20 bins between 0 and maximum segment length

Parameters

bins (int) – number of bins for histogram to have

Returns

histogram of all segment lengths

Return type

tuple of two numpy.array, one with counts and one with edge values

Example:
>>> neuron = from_swc("Example1.swc")
>>> neuron.segment_length_histogram()
(array([0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 4, 0, 0, 0, 0, 0, 0, 2]),
 array([0.        , 0.12247449, 0.24494897, 0.36742346, 0.48989795,
        0.61237244, 0.73484692, 0.85732141, 0.9797959 , 1.10227038,
        1.22474487, 1.34721936, 1.46969385, 1.59216833, 1.71464282,
        1.83711731, 1.95959179, 2.08206628, 2.20454077, 2.32701526,
        2.44948974]))
slice_perimeters()
Returns

The perimeter of each soma slice in this Neuron

Return type

dict mapping z-values to float

slice_surface_areas()
Returns

The surface area of each soma slice in this Neuron

Return type

dict mapping z-values to float

soma_centroid()
Returns

The location of the centroid, found from the average of all soma coordinates

Return type

tuple of float (x, y, z)

soma_layers

A dict of lists of TracingPoint which define the layers of a volumetrically-traced soma

soma_surface_area()
Raises

ValueError – If the soma has 0 or 1 layers currently registered

Returns

The total surface area produced by the same model as is used in soma_volume()

Note

This may yield low accuracy if there are few Z-slices traced or if the tracing is incomplete

Return type

float

soma_volume()
Returns

The total volume of this Neuron soma by approximating each slice as a extruded polygon

Note

This may yield low accuracy if there are few Z-slices traced

Return type

dict mapping z-values to float

thickness_histogram(bins=30)
Creates a histogram (an array of counts and an array of edges) of all nodes’ radii, soma

excluded, with default of 30 bins between 0 and maximum radii

Parameters

bins (int) – number of bins for histogram to have

Returns

histogram of all thicknesses

Return type

tuple of two numpy.array, one with counts and one with edge values

Example:
>>> neuron = from_swc("Example1.swc")
>>> neuron.thickness()
(array([ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
         0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0, 10]),
 array([0.        , 0.03333333, 0.06666667, 0.1       , 0.13333333,
        0.16666667, 0.2       , 0.23333333, 0.26666667, 0.3       ,
        0.33333333, 0.36666667, 0.4       , 0.43333333, 0.46666667,
        0.5       , 0.53333333, 0.56666667, 0.6       , 0.63333333,
        0.66666667, 0.7       , 0.73333333, 0.76666667, 0.8       ,
        0.83333333, 0.86666667, 0.9       , 0.93333333, 0.96666667,
        1.        ]))
thickness_x_branch_order(bins=20)

Creates 2D histogram of neurite radii as a function of branch orders (across all nodes)

Returns

2D histogram of thickness as a function of branch orders

Return type

tuple of three numpy.array, respectively histogram, x edges, and y edges

Example:
>>> neuron = from_swc("Example1.swc")
>>> neuron.thickness_x_branch_order()
(array([[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 6.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 4.]]),
 array([0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1. , 1.1, 1.2,
        1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2. ]),
 array([0.  , 0.05, 0.1 , 0.15, 0.2 , 0.25, 0.3 , 0.35, 0.4 , 0.45, 0.5 ,
        0.55, 0.6 , 0.65, 0.7 , 0.75, 0.8 , 0.85, 0.9 , 0.95, 1.  ]))
thickness_x_path_distance(bins=20)
Creates 2D histogram of neurite radii as a function of path distances to the soma in microns

(across all nodes)

Parameters

n (Neuron) – neuron

Returns

2D histogram of thickness as a function of path distances

Return type

tuple of three numpy.array, respectively histogram, x edges, and y edges

Example:
>>> neuron = from_swc("Example1.swc")
>>> neuron.thickness_x_path_distance()
(array([[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 1.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 1.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 2.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 4.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
         0., 0., 0., 2.]]),
 array([0.        , 0.31975865, 0.6395173 , 0.95927595, 1.27903459,
        1.59879324, 1.91855189, 2.23831054, 2.55806919, 2.87782784,
        3.19758649, 3.51734513, 3.83710378, 4.15686243, 4.47662108,
        4.79637973, 5.11613838, 5.43589703, 5.75565568, 6.07541432,
        6.39517297]),
 array([0.  , 0.05, 0.1 , 0.15, 0.2 , 0.25, 0.3 , 0.35, 0.4 , 0.45, 0.5 ,
        0.55, 0.6 , 0.65, 0.7 , 0.75, 0.8 , 0.85, 0.9 , 0.95, 1.  ]))
total_bif_nodes()
Returns

The total number of bifurcation nodes contained in this Neuron

Return type

int

total_branch_nodes()

Redirects to total_bif_nodes

total_child_nodes()
Returns

The total number of child nodes contained in this Neuron

Return type

int

total_depth(percentile=None)
Returns

The depth of the smallest bounding box required to encapsulate this Neuron

Return type

numeric, inherited from z

total_dim(dim, percentile=None)
Parameters

dimstr describing what dim to perform the analysis on

Returns

the span of all coordinates in the direction dim

Rtype numeric, inherited from coordinatesnumeric, inherited from coordinates

total_height(percentile=None)
Returns

The height of the smallest bounding box required to encapsulate this Neuron

Return type

numeric, inherited from y

total_root_branches()
Returns

The total number of branch roots contained in this Neuron

Return type

int

total_tip_nodes()
Returns

The total number of child nodes contained in this Neuron

Return type

int

total_volume()
Returns

The volume of the smallest bounding box required to encapsulate this Neuron

Return type

float

total_width(percentile=None)
Returns

The width of the smallest bounding box required to encapsulate this Neuron

Return type

numeric, inherited from x

translate(dx=0, dy=0, dz=0)

Translates all points within this Neuron

Parameters
  • dx (numeric) – The translation along the x axis

  • dy (numeric) – The translation along the y axis

  • dz (numeric) – The translation along the z axis

Returns

Nothing

Return type

None

class ngauge.TracingPoint.TracingPoint(x, y, z, r, t, children=None, fid=None, parent=None)

A class which defines a (X,Y,Z,R,T) tuple representing one point of a SWC file.

Raises

AttributeError – Raised on inproper typing of constructor variables

Returns

A new TracingPoint

Return type

TracingPoint

add_child(toadd)

Add a child node to a given TracingPoint

Parameters

toadd (TracingPoint) – Node to add

Raises

AttributeError – Raised if type(toadd) != TracingPoint

Returns

None

angle(a, b)

Determines the angle between two paths in degrees between [0, 180]

Parameters
  • self – point connected to both a and b

  • a (TracingPoint) – one child of branching point

  • b (TracingPoint) – other child of branching point

Returns

angle

Return type

float

Example 1 - Create TracingPoint objects:
>>> from src.morpho import TracingPoint as t
>>> p1 = t(0, 0, 0, 1, 1)
>>> p2 = t(1, 0, 1, 1, 1)
>>> ba = t(1, 0, 0, 1, 1)
>>> ba.angle(p1, p2)
90.0
Example 2 - TracingPoints in a Neuron object:
>>> neuron = from_swc("Example1.swc")
>>> ba = neuron.branches[0].children[0]
>>> p1 = ba.children[0]
>>> p2 = ba.children[1]
>>> ba.angle(p1, p2)
109.47122063449069
branching_order()
Returns

The branching order of this node

Return type

int

children

Stores a list of all child nodes of this TracingPoint

euclidean_dist(other)
Parameters

other (TracingPoint) – A second node

Returns

The euclidean distance to a node other

Return type

float

euclidean_to_ends()
Returns

The euclidean distance to each node as defined in get_tip_nodes()

Return type

list of float

farthest_tip()

TODO

file_id

Stores the id used to load this TracingPoint from the SWC file

get_all_nodes()
Returns

An array of all nodes (inclusive) below this node

Return type

list of TracingPoint

get_all_segments()
Returns

The start and end point of each not-bifurcated segment

Note

By definition, all points will be either a bifurcation or leaf points

Return type

set of TracingPoint

get_bifurcation_nodes()
Returns

An array of TracingPoints representing all bifurcation points

Return type

list of TracingPoint

get_path_to_root()
Returns

An array of nodes required to traverse to the root node (i.e. parent == None)

Return type

list of TracingPoint

get_tip_nodes()
Returns

An array of TracingPoints representing the tip nodes

Return type

list

is_bif()
Returns

True if node is a bifurcation point

Return type

bool

is_root()
Returns

True if node is a root (parent is None)

Return type

bool

is_tip()
Returns

True if node is a tip

Return type

bool

neurite_tortuosity()
Determine the log(tortuosity) of a neurite - tortuosity defined as the ratio between the path

length (each segment’s length combined) and the Euclidean distance from the root and tip node

Returns

the log(tortuosity)

Return type

float

Example:
>>> neuron = from_swc("Example1.swc")
>>> dq = neuron.get_tip_nodes()
>>> dq[0]
TracingPoint(x=-3.0, y=3.0, z=1.5, r=1.0, t=3, parent=TracingPoint(x=-2.0, y=2.0, z=1.0, r=1.0, t=3, children=[{ 2, truncated }], parent={...}))
>>> dq[0].neurite_tortuosity()
0.04134791479135339
next_bif_point()
Returns

The next node in the tree, which is a bifurcation

Note

Returns the root of the tree if there are no bifurcation nodes

Note

Returns self if no parent node is present

Return type

TracingPoint

parent

Stores a symbolic link to the parent node of this TracingPoint

partition_asymmetry()
Note

Formula: abs(n1-n2)/(n1+n2-2) (R. Scorcioni, et al. 2008)

Note

Returns 0 if n1 == n2

Returns

The partition asymmetry of this node

Return type

float

path_dist_to_child(other)
Returns

The path distance required to traverse the tree from self to other

Return type

float

path_dist_to_ends()
Returns

The path distance to each node defined in get_tip_nodes()

Return type

list of float

path_dist_to_root()
Note

Uses result from get_path_to_root()

Returns

The path distance between self and the root node

Return type

float

plot(ax=None, fig=None, color='blue', axis='z', linewidth=1)

Draws this TracingPoint as a figure

Parameters
  • ax (matplotlib.pyplot.axis) – A matplotlib axis object to draw upon

  • fig (matplotlib.pyplot.figure) – A matplotlib figure object to draw upon

  • color (matplotlib color descriptor) – The color to render the line drawing

  • axis (str) – The axis to perform the 3D to 2D projection upon

Note

If no value for ax or fig is supplied, a new one will be generated

Note

The returned matplotlib objects can be manipulated further to generate custom figures

Returns

a matplotlib Figure object which has been rendered.

r

Stores the radius of the TracingPoint

select_nodes(select_func)
Parameters

select_func (function) – A function to perform the selection from

Returns

All nodes x (inclusive) for which select_func(x) evaluates to a truthy value

Return type

list of TracingPoint

static slice_perimeter(points)
Parameters

points (list of TracingPoint) – A set of points which form an arbitrary polygon

Note

All points must be in the same z-plane (all z attributes are equal)

Note

Returns 0.0 if len(points) < 2

Returns

The perimeter defined by points

Return type

float

static slice_surface_area(points)
Parameters

points (list of TracingPoint) – A set of points which form an arbitrary polygon

Note

All points must be in the same z-plane (all z attributes are equal)

Note

Returns 0.0 if len(points) < 3

Returns

The surface area bound by points

Return type

float

t

Stores the type value of the TracingPoint

total_bif_nodes()
Returns

The total number of bifurcation points below this TracingPoint

Return type

int

total_child_nodes()
Returns

The recursive count of all children-of-children

Return type

int

total_children()
Returns

The count of all child nodes

Return type

int

total_depth()
Returns

the depth of the smallest box which encloses the branch

Return type

numeric, inherited from self.z

total_height()
Returns

the height of the smallest box which encloses the branch

Return type

numeric, inherited from self.y

total_tip_nodes()
Returns

The total number of tip nodes below this TracingPoint

Return type

int

total_volume()
Returns

the volume of the smallest box which encloses the branch

Return type

numeric, inherited from total_width(), total_height(), and total_depth()

total_width()
Returns

the width of the smallest box which encloses the branch

Return type

numeric, inherited from self.x

x

Stores the x coordinate of the TracingPoint

y

Stores the y coordinate of the TracingPoint

z

Stores the z coordinate of the TracingPoint

Provides mathematical functions used in the nGauge package

ngauge.util.abs_dot(a, b)
Parameters
  • a (tuple of numeric) – A tuple representing a vector

  • b (tuple of numeric) – A tuple representing a vector

Returns

The absolute value dot product of a and b (see dot())

Return type

numeric

ngauge.util.abs_dot_3d(a, b)
Parameters
  • a (tuple of numeric) – A 3-dimensional tuple representing a vector

  • b (tuple of numeric) – A 3-dimensional tuple representing a vector

Returns

The absolute value dot product of a and b (see dot())

Return type

numeric

ngauge.util.dot(a, b)
Parameters
  • a (tuple of numeric) – A tuple representing a vector

  • b (tuple of numeric) – A tuple representing a vector

Returns

The dot product of a and b

Return type

numeric

ngauge.util.f_function_map(di, dp, smat=None)

Work in progress

ngauge.util.load_default_smat()

Work in progress

ngauge.util.rotation_matrix(a, b, c)

Creates a standard rotation matrix of three angles for rotation calculations

Parameters
  • a (numeric) – The first rotation angle

  • b (numeric) – The second rotation angle

  • c (numeric) – The third rotation angle

Returns

The rotation matrix

Return type

numpy.array (3x3)

ngauge.util.tangent_from_points(list_of_points)

Returns a tangent vector from a list of points