MorphoBranch#
- class braincell.morph.MorphoBranch(owner, node_id, *, name, branch, parent_id, parent_x, child_x)[source]#
A tree-local branch node bound to exactly one
Morphoowner.MorphoBranchprovides transparent access to branch geometry (via delegation toBranch) and tree navigation (parent, children). It also supports syntax sugar for attaching children:Attribute assignment:
parent.dend = Branch(...)Subscript syntax:
parent[0.5].dend = Branch(...)
MorphoBranchinstances are created internally byMorphoand should not be constructed directly.- Parameters:
owner (
Morphology) – The morphology tree that owns this node.node_id (
int) – Unique node identifier within the tree.name (
str) – Branch name.branch (
Branch) – Underlying geometry object.parent_id (
int|None) – Node ID of the parent (Nonefor the root).parent_x (
float) – Attachment point on the parent branch.child_x (
float) – Attachment point on the child branch.
See also
MorphoThe tree container that owns
MorphoBranchnodes.BranchThe immutable geometry wrapped by this node.
Notes
MorphoBranchdelegates attribute access to the underlyingBranchvia__getattr__, so all geometry properties(
length,area,n_segments,type, etc.) are accessible directly on the node. Child branches can also be retrieved by name (e.g.,morph.soma.dend).Examples
>>> import brainunit as u >>> from braincell import Branch, Morphology >>> soma = Branch.from_lengths( ... lengths=[20.0] * u.um, ... radii=[10.0, 10.0] * u.um, ... type="soma", ... ) >>> dend = Branch.from_lengths( ... lengths=[50.0] * u.um, ... radii=[2.0, 1.0] * u.um, ... type="dendrite", ... ) >>> morph = Morphology.from_root(soma, name="soma") >>> morph.soma.dend = dend >>> morph.soma.n_children 1 >>> morph.soma.dend.length 50.0 * umetre
- attach(branch, name=None, *, parent_x=1.0, child_x=0.0)[source]#
Attach a child branch to this branch.
- Parameters:
branch (
Branch) – Geometry of the child branch to attach.name (
str|None) – Name for the child branch. IfNone, auto-generated from the branch type.parent_x (
float) – Attachment point on this branch:0(proximal),0.5(midpoint, soma only), or1(distal, default).child_x (
float) – Attachment point on the child branch:0(proximal, default) or1(distal).
- Returns:
The newly attached child branch node.
- Return type:
- Raises:
ValueError – If parent_x or child_x is invalid.
Notes
parent_x=0attaches to the proximal end of this branch. This is typically used when this branch is itself a child and you want to attach at its connection point rather than its distal end.Examples
>>> child = morph.soma.attach(dend_branch, name="apical") >>> child.name 'apical'
- property children: tuple[MorphoBranch, ...]#
All direct children of this branch.
- Returns:
Child branch nodes.
- Return type:
- property index: int#
Index of this branch in the default ordering.
- Returns:
Position in the default (by node ID) ordering.
- Return type:
See also
index_byIndex in a specific ordering.
- property parent: MorphoBranch | None#
Parent branch node, or
Nonefor the root.- Returns:
Parent node.
- Return type:
MorphoBranch or None