morphoclass.orientation module¶
Tools for orienting neurons in their 3D embedding vector space.
-
morphoclass.orientation.fit_3d_ray(points)¶ Fit a ray through given points in 3D.
This is done by minimizing the norm of the difference between v=(x, y, z) and the projection of v onto the ray
- Parameters
points (np.ndarray) – Array of shape (N, 3) containing N points in 3D.
- Returns
Spherical coordinates of the point on the unit sphere determining the ray direction. If the fitting fails then None is returned.
- Return type
(theta, phi) or None
-
morphoclass.orientation.fit_tree_pca(tree)¶ Get the normalized tree principal component in spherical coordinates.
- Parameters
tree (tmd.Tree.Tree.Tree) – A TMD tree.
- Returns
The normalized principal component vector in spherical coordinates.
- Return type
(theta, phi)
-
morphoclass.orientation.fit_tree_ray(tree)¶ Fit a ray through the root of the tree.
- Parameters
tree (tmd.Tree.Tree.Tree)) – A TMD tree.
- Returns
Spherical coordinates of the point on the unit sphere determining the ray direction. If the fitting fails then None is returned
- Return type
(theta, phi) or None
-
morphoclass.orientation.get_angle_deg(v1, v2)¶ Compute the angle in degrees between two given vectors.
- Parameters
v1 (np.ndarray) – First vector
v2 (np.ndarray) – Second vector.
- Returns
The angle in degrees between v1 and v2.
- Return type
float
-
morphoclass.orientation.get_angle_rad(v1, v2)¶ Compute the angle in radians between two given vectors.
- Parameters
v1 (np.ndarray) – First vector
v2 (np.ndarray) – Second vector.
- Returns
The angle in radians between v1 and v2.
- Return type
float
-
morphoclass.orientation.get_tree_origin(tree)¶ Find the index of the origin node of a tree.
- Parameters
tree (tmd.Tree.Tree.Tree) – A TMD tree.
- Returns
origin (np.ndarray) – The coordinates of the tree origin.
origin_idx (int) – The index of the origin node.
-
morphoclass.orientation.get_tree_pca(tree, kind='3d', shift_to_origin=False)¶ Compute the PCA components of the given TMD tree.
- Parameters
tree (tmd.Tree.Tree.Tree) – A TMD tree.
kind ({"2d", "3d"}) – The kind of PCA to compute. The 2D PCA only considers the x and y coordinates, while the 3D uses x, y and z.
shift_to_origin (bool) – If true shift the tree root to coordinate origin.
- Returns
mean (np.array) – The mean of tree coordinates.
components (np.array) – The three PCA components of the tree.
explained_variance_ratio (np.array) – The explained variance ratio.
- Raises
ValueError – If the parameter kind has an invalid value. If the tree does not have exactly one root node.
-
morphoclass.orientation.orient_dataset(orient_fn, dataset_dir, output_dir=None, overwrite=False)¶ Orient all samples in a given dataset (not implemented yet).
- Parameters
orient_fn (callable) – The orientation function.
dataset_dir (str or pathlib.Path) – The dataset directory.
output_dir (str or pathlib.Path (optional)) – The output directory. If None an output directory name will be constructed by appending “_oriented” to the dataset directory name.
overwrite (bool (optional)) – If true then the the output directory will be purged in case it already exists.
- Returns
Whether or not the orientation was successful.
- Return type
bool
-
morphoclass.orientation.orient_neuron(orient_fn, neuron, in_place=False)¶ Orient the neuron apicals to point in the y-direction.
- Parameters
orient_fn (callable) – Function that finds the direction of a tree.
neuron – The neuron to orient.
in_place (bool (optional)) – If true modify the given neuron instead of returning a copy.
- Returns
Oriented copy of the original neuron.
- Return type
new_neuron