neuror.utils

Utils module

Functions

angle_between

Returns the angle in radians between vectors 'v1' and 'v2'.

direction

Return the direction vector of a section.

repair_type_map

Return a dict of extended types.

rotation_matrix

Return the rotation matrix associated with counterclockwise rotation about the given axis by theta radians.

section_length

Section length.

unit_vector

Returns the unit vector of the vector.

Classes

RepairJSON

JSON encoder that handles numpy types.

RepairType

The types used for the repair.

class neuror.utils.RepairJSON(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]

Bases: JSONEncoder

JSON encoder that handles numpy types.

In python3, numpy types don’t serialize to correctly, so a custom converter is needed.

default(o)[source]

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return JSONEncoder.default(self, o)
class neuror.utils.RepairType(value)[source]

Bases: Enum

The types used for the repair.

neuror.utils.angle_between(v1, v2)[source]

Returns the angle in radians between vectors ‘v1’ and ‘v2’.

..code:

>>> angle_between((1, 0, 0), (0, 1, 0))
1.5707963267948966
>>> angle_between((1, 0, 0), (1, 0, 0))
0.0
>>> angle_between((1, 0, 0), (-1, 0, 0))
3.141592653589793
neuror.utils.direction(section)[source]

Return the direction vector of a section.

Parameters:

section (morphio.mut.Section) – section

neuror.utils.repair_type_map(neuron, apical_section)[source]

Return a dict of extended types.

neuror.utils.rotation_matrix(axis, theta)[source]

Return the rotation matrix associated with counterclockwise rotation about the given axis by theta radians.

neuror.utils.section_length(section)[source]

Section length.

Parameters:

section (morphio.mut.Section) – section

neuror.utils.unit_vector(vector)[source]

Returns the unit vector of the vector.