neurom.morphmath¶
Mathematical and geometrical functions used to compute morphometrics.
Functions
Compute the angle in radians between three 3D points. 

Computes the angle in radians between vectors ‘p1’ and ‘p2’. 

Computes the average distance between a list of points and a given point p0. 

Compute the orthogonal distance between a line and a point. 

Interpolate the radius between two values. 

Returns the list of distances between consecutive points. 

Returns the point p satisfying: p1 + fraction * (p2  p1). 

Compute the path distance from given set of points. 

Find segment by fractional offset. 

Find coordinates by fractional offset. 

Estimate the principal components of the covariance on the given point cloud. 

Compute the euclidian distance between two 3D points. 

Compute the square of the euclidian distance between two 3D points. 

Compute the maximun euclidian distance between any two points in a list of points. 

Calculate the extent of a set of 3D points. 

Compute the scalar projection of v1 upon v2. 

Compute the path distance from given set of points. 

Compute the surface area of a segment. 

Return the length of a segment. 

Return the square of the length of a segment. 

Return the radial distance of a tree segment to a given point. 

Return the mean radius of a segment. 

Compute the taper rate of a segment. 

Compute the volume of a segment. 

Return the mean x coordinate of a segment. 

Return the mean y coordinate of a segment. 

Return the mean z coordinate of a segment. 

Compute the area of a sphere with radius r. 

Compute the taper rate between points p0 and p1. 

Compute vector between two 3D points. 

Compute the vector projection of v1 upon v2. 

neurom.morphmath.
angle_3points
(p0, p1, p2)[source]¶ Compute the angle in radians between three 3D points.
Calculated as the angle between p1p0 and p2p0.
 Parameters
p0 – indexable objects with
p1 – indexable objects with
p2 – indexable objects with
0 (indices) –
1 –
corresponding to 3D cartesian coordinates. (2) –
 Returns
Angle in radians between (p1p0) and (p2p0). 0.0 if p0==p1 or p0==p2.

neurom.morphmath.
angle_between_vectors
(p1, p2)[source]¶ Computes the angle in radians between vectors ‘p1’ and ‘p2’.
Normalizes the input vectors and computes the relative angle between them.
>>> angle_between((1, 0), (0, 1)) 1.5707963267948966 >>> angle_between((1, 0), (1, 0)) 0.0 >>> angle_between((1, 0), (1, 0)) 3.141592653589793

neurom.morphmath.
average_points_dist
(p0, p_list)[source]¶ Computes the average distance between a list of points and a given point p0.

neurom.morphmath.
dist_point_line
(p, l1, l2)[source]¶ Compute the orthogonal distance between a line and a point.
The line is that which passes through the points l1 and l2.
 Parameters
p – iterable indices 0, 1, 2 correspond to cartesian coordinates
l1 – iterable indices 0, 1, 2 correspond to cartesian coordinates
l2 – iterable indices 0, 1, 2 correspond to cartesian coordinates

neurom.morphmath.
interpolate_radius
(r1, r2, fraction)[source]¶ Interpolate the radius between two values.
Calculate the radius that corresponds to a point P that lies at a fraction of the length of a cut cone P1P2 where P1, P2 are the centers of the circles that bound the shape with radii r1 and r2 respectively.
 Parameters
r1 – float Radius of the first node of the segment.
r2 – float Radius of the second node of the segment
fraction – float The fraction at which the interpolated radius is calculated.
 Returns: float
The interpolated radius.
Note: The fraction is assumed from point P1, not from point P2.

neurom.morphmath.
interval_lengths
(points, prepend_zero=False)[source]¶ Returns the list of distances between consecutive points.
 Parameters
points – a list of np.array of 3D points
prepend_zero (bool) – if True, the returned array will start with a zero

neurom.morphmath.
linear_interpolate
(p1, p2, fraction)[source]¶ Returns the point p satisfying: p1 + fraction * (p2  p1).

neurom.morphmath.
path_fraction_id_offset
(points, fraction, relative_offset=False)[source]¶ Find segment by fractional offset.
Find the segment which corresponds to the fraction of the path length along the piecewise linear curve which is constructed from the set of points.
 Parameters
points – an iterable of indexable objects with indices
0 –
1 –
correspoding to 3D cartesian coordinates (2) –
fraction – path length fraction (0.0 <= fraction <= 1.0)
relative_offset – return absolute or relative segment distance
 Returns
(segment ID, segment offset) pair.

neurom.morphmath.
path_fraction_point
(points, fraction)[source]¶ Find coordinates by fractional offset.
Computes the point which corresponds to the fraction of the path length along the piecewise linear curve which is constructed from the set of points.
 Parameters
points – an iterable of indexable objects with indices
0 –
1 –
correspoding to 3D cartesian coordinates (2) –
fraction – path length fraction (0 <= fraction <= 1)
 Returns
The 3D coordinates of the aforementioned point

neurom.morphmath.
pca
(points)[source]¶ Estimate the principal components of the covariance on the given point cloud.
 Input
A numpy array of points of the form ((x1,y1,z1), (x2, y2, z2)…)
 Ouptut
Eigenvalues and respective eigenvectors

neurom.morphmath.
point_dist
(p1, p2)[source]¶ Compute the euclidian distance between two 3D points.
 Parameters
p1 – indexable objects with
p2 – indexable objects with
0 (indices) –
1 –
corresponding to 3D cartesian coordinates. (2) –
 Returns
The euclidian distance between the points.

neurom.morphmath.
point_dist2
(p1, p2)[source]¶ Compute the square of the euclidian distance between two 3D points.
 Parameters
p1 – indexable objects with
p2 – indexable objects with
0 (indices) –
1 –
corresponding to 3D cartesian coordinates. (2) –
 Returns
The square of the euclidian distance between the points.

neurom.morphmath.
polygon_diameter
(points)[source]¶ Compute the maximun euclidian distance between any two points in a list of points.

neurom.morphmath.
principal_direction_extent
(points)[source]¶ Calculate the extent of a set of 3D points.
The extent is defined as the maximum distance between the projections on the principal directions of the covariance matrix of the points.
 Parameter:
points : a 2D numpy array of points
 Returns
the extents for each of the eigenvectors of the cov matrix eigs : eigenvalues of the covariance matrix eigv : respective eigenvectors of the covariance matrix
 Return type
extents

neurom.morphmath.
scalar_projection
(v1, v2)[source]¶ Compute the scalar projection of v1 upon v2.
 Parameters
v1 – iterable
v2 – iterable
0 (indices) –
1 –
corresponding to cartesian coordinates (2) –
 Returns
3vector of the projection of point p onto the direction of v

neurom.morphmath.
section_length
(points)¶ Compute the path distance from given set of points.

neurom.morphmath.
segment_area
(seg)[source]¶ Compute the surface area of a segment.
Approximated as a conical frustum. Does not include the surface area of the bounding circles.

neurom.morphmath.
segment_length
(seg)[source]¶ Return the length of a segment.
Returns: Euclidian distance between centres of points in seg

neurom.morphmath.
segment_length2
(seg)[source]¶ Return the square of the length of a segment.
Returns: Square of Euclidian distance between centres of points in seg

neurom.morphmath.
segment_radial_dist
(seg, pos)[source]¶ Return the radial distance of a tree segment to a given point.
The radial distance is the euclidian distance between the midpoint of the segment and the point in question.
 Parameters
seg – tree segment
pos – origin to which distances are measured. It must have at lease 3
The first 3 components are (components.) –

neurom.morphmath.
segment_radius
(seg)[source]¶ Return the mean radius of a segment.
Returns: arithmetic mean of the radii of the points in seg

neurom.morphmath.
segment_taper_rate
(seg)[source]¶ Compute the taper rate of a segment.
 Returns
The taper rate, defined as the absolute value of the difference in the diameters of the segment’s two points divided by the euclidian distance between them.

neurom.morphmath.
segment_volume
(seg)[source]¶ Compute the volume of a segment.
Approximated as a conical frustum.

neurom.morphmath.
segment_x_coordinate
(seg)[source]¶ Return the mean x coordinate of a segment.
Returns: arithmetic mean of the x coordinates of the points in seg

neurom.morphmath.
segment_y_coordinate
(seg)[source]¶ Return the mean y coordinate of a segment.
Returns: arithmetic mean of the y coordinates of the points in seg

neurom.morphmath.
segment_z_coordinate
(seg)[source]¶ Return the mean z coordinate of a segment.
Returns: arithmetic mean of the z coordinates of the points in seg

neurom.morphmath.
taper_rate
(p0, p1)[source]¶ Compute the taper rate between points p0 and p1.
 Parameters
p0 – iterables with first 4 components containing (x, y, z, r)
p1 – iterables with first 4 components containing (x, y, z, r)
 Returns
The taper rate, defined as the absolute value of the difference in the diameters of p0 and p1 divided by the euclidian distance between them.