Morphologies module

class bsb.morphologies.Branch(*args, labels=None)[source]

A vector based representation of a series of point in space. Can be a root or connected to a parent branch. Can be a terminal branch or have multiple children.

attach_child(branch)[source]

Attach a branch as a child to this branch.

Parameters

branch (Branch) – Child branch

property children

Collection of the child branches of this branch.

Returns

list of Branches

Return type

list

detach_child(branch)[source]

Remove a branch as a child from this branch.

Parameters

branch (Branch) – Child branch

label(*labels)[source]

Add labels to every point on the branch. See label_points to label individual points.

Parameters

labels (str) – Label(s) for the branch.

label_points(label, mask)[source]

Add labels to specific points on the branch. See label to label the entire branch.

Parameters
  • label (str) – Label to apply to the points.

  • mask (np.ndarray(dtype=bool, shape=(branch_size,))) – Boolean mask equal in size to the branch that determines which points get labelled.

label_walk()[source]

Iterate over the labels of each point in the branch.

property points

Return the vectors of this branch as a matrix.

property size

Returns the amount of points on this branch

Returns

Number of points on the branch.

Return type

int

property terminal

Returns whether this branch is terminal or has children.

Returns

True if this branch has no children, False otherwise.

Return type

bool

to_compartments(start_id=0, parent=None)[source]

Convert the branch to compartments.

Deprecated since version 3.6: Use the vectors and points API instead (.points, .walk())

walk()[source]

Iterate over the points in the branch.

class bsb.morphologies.Compartment(start, end, radius, id=None, labels=None, parent=None, section_id=None, morphology=None)[source]

Compartments are line segments with a radius. They can be constructed from the points on a Branch or by concatenating the results of a depth-first iteration of the branches of a Morphology.

classmethod from_template(template, **kwargs)[source]

Create a compartment based on a template compartment. Accepts any keyword argument to overwrite or add attributes.

class bsb.morphologies.GolgiCellGeometry[source]
validate()[source]

Must be implemented by child classes. Raise exceptions when invalid configuration parameters are received.

class bsb.morphologies.GranuleCellGeometry[source]
validate()[source]

Must be implemented by child classes. Raise exceptions when invalid configuration parameters are received.

class bsb.morphologies.Morphology(roots)[source]

A multicompartmental spatial representation of a cell based on connected 3D compartments.

Todo

Uncouple from the MorphologyRepository and merge with TrueMorphology.

property branches

Return a depth-first flattened array of all branches.

flatten(vectors=None, matrix=False, labels=None)[source]

Return the flattened vectors of the morphology

Parameters

vectors (list of str) – List of vectors to return such as [‘x’, ‘y’, ‘z’] to get the positional vectors.

Returns

Tuple of the vectors in the given order, if matrix is True a matrix composed of the vectors is returned instead.

Return type

tuple of ndarrays (matrix=False) or matrix (matrix=True)

get_branches(labels=None)[source]

Return a depth-first flattened array of all or the selected branches.

Parameters

labels (list) – Names of the labels to select.

Returns

List of all branches or all branches with any of the labels when given

Return type

list

rotate(v0, v)[source]

Rotate a morphology to be oriented as vector v, supposing to start from orientation v0. norm(v) = norm(v0) = 1 Rotation matrix R, representing a rotation of angle alpha around vector k

to_compartments()[source]

Return a flattened array of compartments

class bsb.morphologies.NilCompartment[source]
class bsb.morphologies.NoGeometry[source]
validate()[source]

Must be implemented by child classes. Raise exceptions when invalid configuration parameters are received.

class bsb.morphologies.PurkinjeCellGeometry[source]
validate()[source]

Must be implemented by child classes. Raise exceptions when invalid configuration parameters are received.

class bsb.morphologies.RadialGeometry[source]
validate()[source]

Must be implemented by child classes. Raise exceptions when invalid configuration parameters are received.

class bsb.morphologies.Representation[source]
bsb.morphologies.branch_iter(branch)[source]

Iterate over a branch and all of its children depth first.