neuron_morphology.transforms.affine_transform

Module Contents

Classes

AffineTransform Handles transformations to a pia/wm aligned coordinate frame.

Functions

affine_from_transform_translation(transform: Optional[Any] = None, translation: Optional[Any] = None, translate_first: bool = False) Create affine from linear transformation and translation.
rotation_from_angle(angle: float, axis: int = 2) Create an affine matrix from a rotation about a specific axis.
affine_from_translation(translation: Any) Create an affine translation.
affine_from_transform(transform: Any) Create affine transformation.
class neuron_morphology.transforms.affine_transform.AffineTransform(affine: Optional[Any] = None)

Bases: neuron_morphology.transforms.transform_base.TransformBase

Handles transformations to a pia/wm aligned coordinate frame.

classmethod from_dict(cls, affine_dict: Dict[str, float])

Create an AffineTransform from a dict with keys and values.

Parameters:
affine_dict: keys and values corresponding to the following
[[tvr_00 tvr_01 tvr_02 tvr_09]

[tvr_03 tvr_04 tvr_05 tvr_10] [tvr_06 tvr_07 tvr_08 tvr_11] [0 0 0 1]]

Returns:
AffineTransform object
classmethod from_list(cls, affine_list: List[float])

Create an Affine Transform from a list

Parameters:
affine_list: list of tvr values corresponding to:
[[tvr_00 tvr_01 tvr_02 tvr_09]

[tvr_03 tvr_04 tvr_05 tvr_10] [tvr_06 tvr_07 tvr_08 tvr_11] [0 0 0 1]]

Returns:
AffineTransform object
to_dict(self)

Create dictionary defining the transformation.

Returns:
Dict with keys and values corresponding to the following:
[[tvr_00 tvr_01 tvr_02 tvr_09]

[tvr_03 tvr_04 tvr_05 tvr_10] [tvr_06 tvr_07 tvr_08 tvr_11] [0 0 0 1]]

to_list(self)

Create a list defining the transformation.

Returns:
List with values corresponding to the following:
[[tvr_00 tvr_01 tvr_02 tvr_09]

[tvr_03 tvr_04 tvr_05 tvr_10] [tvr_06 tvr_07 tvr_08 tvr_11] [0 0 0 1]]

transform(self, vector: Any)

Apply this transform to (3,) point or (n,3) array-like of points.

Parameters:
vector: a (3,) array-like point or a (n,3) array-like array

of points to be transformed

Returns:
numpy.ndarray with same shape as input
_get_scaling_factor(self)

Calculate the scaling factor from the affine matrix.

Returns:
Scaling factor: 3rd root of the determinant.
transform_morphology(self, morphology: Morphology, clone: bool = False, scale_radius: bool = True)

Apply this transform to all nodes in a morphology.

Parameters:
morphology: a Morphology loaded from an swc file
clone: make a new object if True
scale_radius: apply radius scaling if True
Returns:
A Morphology
neuron_morphology.transforms.affine_transform.affine_from_transform_translation(transform: Optional[Any] = None, translation: Optional[Any] = None, translate_first: bool = False)

Create affine from linear transformation and translation.

Affine transformation of vector x -> Ax + b in 3D: [A, b

0, 0, 0, 1]

A is a 3x3 linear tranformation b is a 3x1 translation

Parameters:
transform: linear transformation (3, 3) array-like
translation: linear translation (3,) array-like
translate_first: apply the translation before the transform
Returns:
(4, 4) numpy.ndarray affine matrix
neuron_morphology.transforms.affine_transform.rotation_from_angle(angle: float, axis: int = 2)

Create an affine matrix from a rotation about a specific axis.

Parameters:
angle: rotation angle in radians
axis: axis to rotate about, 0=x, 1=y, 2=z (default z axis)
Returns:
(3, 3) numpy.ndarray rotation matrix
neuron_morphology.transforms.affine_transform.affine_from_translation(translation: Any)

Create an affine translation.

Parameters:
translation: array-like vector of x, y, and z translations
Returns:
(4, 4) numpy.ndarray affine matrix
neuron_morphology.transforms.affine_transform.affine_from_transform(transform: Any)

Create affine transformation.

Parameters:
transformation: (3, 3) row major array-like transformation
Returns:
(4, 4) numpy.ndarray affine matrix