morphoclass.transforms.augmentors package

Module contents

Transforms that generate morphology data augmentations.

This implies that the transforms in this module will modify the actual morphology. Normally it is desired to restore the original morphology after the forward pass. To achieve this insert the “copy” transform into the transform pipeline.

class morphoclass.transforms.augmentors.AddNodesAtIntervals(interval)

Bases: object

Add points to reduced tree at given interval distance.

The reduced apical tree specified by the point mask, is enhanced by adding additional points from the original apical tree.

First it is checked that all branching points are set. Then all points are added that are further away from those that are already set by the given interval distance.

Parameters

interval (float) – Threshold distance at which a new point is added.

add_nodes(apical, mask)

Add nodes to the mask according to the interval configuration.

Parameters
  • apical (tmd.Tree.Tree.Tree) – An apical tree.

  • mask (np.ndarray) – The mask to set. The data in this array will be modified in-place.

class morphoclass.transforms.augmentors.AddRandomPointsToReductionMask(n_points)

Bases: object

A Transform that adds a fixed number of random points to the apical mask.

Parameters

n_points (int) – The number of random points to add to the apical mask.

class morphoclass.transforms.augmentors.AddSectionMiddlePoints(n_points_to_add)

Bases: object

Transform that splits apical sections into two by adding a middle point.

Parameters

n_points_to_add (int) – The number of sections to split into two by adding middle points.

class morphoclass.transforms.augmentors.ApplyNodeReductionMasks

Bases: object

Transform that applies the apical node masks to the apicals.

static apply_mask(apical, mask)

Apply a node mask to the given apical.

Parameters
  • apical (tmd.Tree.Tree) – The apical dendrite tree.

  • mask (np.ndarray) – The node mask.

class morphoclass.transforms.augmentors.BranchingOnlyNeurites

Bases: object

Extract simplified structure from TMD neurites.

All neurites in the original data or reduced to branching points only

class morphoclass.transforms.augmentors.BranchingOnlyNeuron

Bases: object

Extract simplified structure from TMD neurons.

All neurites in the original data or reduced to branching points only

class morphoclass.transforms.augmentors.EqualizeNodeCounts(min_total_nodes=None)

Bases: object

Equalize node counts across the whole dataset.

If possible, nodes from the original apicals are added to the apicals as long as the node count in the sample is smaller than the threshold specified by the field min_total_nodes.

The threshold min_total_nodes can be either set manually or found automatically by fitting the transformer to a dataset, in which case the value is set to the minimal number of nodes in the original apicals across the whole dataset.

Parameters

min_total_nodes (int (optional)) – The threshold for the new node count.

fit(dataset)

Find a heuristic number of nodes to which to equalize the samples.

This is simply the minimal number of apical nodes across the whole dataset. This way we make sure that each sample can reach this number of nodes.

Parameters

dataset – The dataset to which to fit.

class morphoclass.transforms.augmentors.ExtractBranchingNodeReductionMasks

Bases: object

Transform that extracts apical node masks for branching nodes.

class morphoclass.transforms.augmentors.OrientApicals(special_treatment_ipcs=False, special_treatment_hpcs=False)

Bases: object

Orient all apicals along the positive y-axis.

Parameters
  • special_treatment_ipcs (bool) – If True, then IPCs (inverted pyramidal cells) will be oriented along the negative y-axis

  • special_treatment_hpcs (bool) – If True, then HPCs (horizontal pyramidal cells) will be oriented along the positive x-axis

class morphoclass.transforms.augmentors.OrientNeuron

Bases: object

Orient neuron using ray fitting.

class morphoclass.transforms.augmentors.RandomJitter(d_add=0.0, d_scale=0.0, shift_to_origin=True)

Bases: object

Randomly jitter all nodes.

The jittering is applied in the following way. For each coordinate x draw two random numbers, d1 in {-d_add, +d_add} and d2 in {-d_scale, +d_scale} and transform x as follows:

x => (x + d1) * (1 + d2)

Note that d_scale is the scale variation relative to 1.0.

Parameters
  • d_add (float) – The maximal additive factor for jittering.

  • d_scale (float) – The maximal multiplicative factor for jittering (relative to 1.0).

  • shift_to_origin (bool (optional)) – If true then make sure that the root point is at the origin before and after the transformation.

class morphoclass.transforms.augmentors.RandomRotation(only_y_rotation=False)

Bases: object

Randomly rotate the apical in its 3D embedding space.

The full rotations are parametrized by three Euler angles alpha, beta, and gamma in the following way:

v -> R_y(gamma).R_x(beta).R_y(alpha).v

With this parametrization the range of the angles is the following:

alpha: [0, 2 * pi] beta: [0, pi] gamma: [0, 2 * pi]

It is possible to restrict the rotations to the y-rotations only by setting beta = gamma = 0. This is useful if the apicals are oriented along the y-axis.

Parameters

only_y_rotation (bool, optional) – If true only rotate along the y-axis.

class morphoclass.transforms.augmentors.RandomStretching(d_scale_x=0.0, d_scale_y=0.0, d_scale_z=0.0)

Bases: object

Randomly scale coordinates along all axes.

Parameters
  • d_scale_x (float) – The range for the random scale along the x-axis. The generated random scale will be in the range (1 - d_scale_x, 1 + d_scale_x).

  • d_scale_y (float) – The range for the random scale along the y-axis. The generated random scale will be in the range (1 - d_scale_y, 1 + d_scale_y).

  • d_scale_z (float) – The range for the random scale along the z-axis. The generated random scale will be in the range (1 - d_scale_z, 1 + d_scale_z).