Cable cell morphology¶
- arbor.mnpos: int¶
Value used to indicate “no parent” in
segment_treeandmorphologytrees of segments and branches respectively.import arbor as A tree = A.segment_tree() # mnpos can be used to explicitly specify that a segment # is at the root of the tree. More than one segment can # be at the root, and they will all be joined electrically # at their proximal ends. tree.append(parent=A.mnpos, # attach segment to root. prox=A.mpoint(0, 0,-5, 5), dist=A.mpoint(0, 0, 5, 5), tag=1) tree.append(parent=0, prox=A.mpoint(0, 0, 5, 0.5), dist=A.mpoint(0, 0,50, 0.2), tag=3) # mnpos can also be used when querying a segment_tree or morphology, # for example, the following snippet that finds all branches in the # morphology that are attached to the root of the morphology. m = A.morphology(tree) base_branches = [i for i in range(m.num_branches) if m.branch_parent(i) == A.mnpos] print(base_branches)
- class arbor.location¶
A location on
branch, wherepos, in the range0 ≤ pos ≤ 1, gives the relative position between the proximal and distal ends of the branch. The position is in terms of branch path length, so for example, on a branch of path length 100 μmpos=0.2corresponds to 20 μm and 80 μm from the proximal and distal ends of the branch, respectively.- location(branch, pos)¶
Constructor.
- branch: int¶
The branch id of the location.
- pos: float¶
The relative position of the location on the branch.
- class arbor.cable¶
An unbranched cable is a subset of a branch. The values of
0 ≤ prox ≤ dist ≤ 1are the relative position of the cable’s end points on the branch, in terms of branch path length. For example, on a branch of path length 100 μm, the valuesprox=0.2,dist=0.8 describe a cable that starts and ends 20 μm and 80 μm along the branch, respectively.- cable(branch, prox, dist)¶
Constructor.
- branch: int¶
The branch id of the cable.
- prox: float¶
The relative position of the proximal end of the cable on the branch.
- dist: float¶
The relative position of the distal end of the cable on the branch.
- class arbor.mpoint¶
A location of a cell morphology at a fixed location in space. Describes the location of the as three-dimensional coordinates (
x,y,z) and theradiusof the cable.- x: real¶
X coordinate (μm)
- y: real¶
Y coordinate (μm)
- z: real¶
x coordinate (μm)
- radius: real¶
The radius of the cable (μm)
- class arbor.msegment¶
-
- tag: int¶
Integer tag meta-data associated with the segment. Typically, the tag would correspond to the SWC structure identifier: soma=1, axon=2, dendrite=3, apical dendrite=4, however arbitrary tags, including zero and negative values, can be used.
- class arbor.segment_tree¶
A segment tree is a description of the segments and their connections. Segment trees comprise a sequence of segments starting from at least one root segment, together with a parent-child adjacency relationship where a child segment is distal to its parent. Branches in the tree occur where a segment has more than one child. Furthermore, a segment can not have more than one parent. In this manner, neuron morphologies are modeled as a tree, where cables that represent dendrites and axons can branch, but branches can not rejoin. A segment tree is a segment-based description of a cell’s morphology.
- segment_tree()¶
Construct an empty segment tree.
The tree is constructed by appending segments to the tree. Segments are numbered starting at 0 in the order that they are added, with the first segment getting id 0, the second segment id 1, and so forth.
A segment can not be added before its parent, hence the first segment is always at the root. In this manner, a segment tree is always guaranteed to be in a correct state, with consistent parent-child indexing, and with n segments numbered from 0 to n-1.
To illustrate how a segment tree is constructed by appending segments, take the segment tree used in the documentation above.
Which is constructed as follows.
import arbor as A from arbor import mpoint from arbor import mnpos tree = A.segment_tree() # Start with a cylinder segment for the soma (with tag 1) tree.append(mnpos, mpoint(0, 0.0, 0, 2.0), mpoint( 4, 0.0, 0, 2.0), tag=1) # Construct the first section of the dendritic tree, # comprised of segments 1 and 2, attached to soma segment 0. tree.append(0, mpoint(4, 0.0, 0, 0.8), mpoint( 8, 0.0, 0, 0.8), tag=3) tree.append(1, mpoint(8, 0.0, 0, 0.8), mpoint(12, -0.5, 0, 0.8), tag=3) # Construct the rest of the dendritic tree. tree.append(2, mpoint(12, -0.5, 0, 0.8), mpoint(20, 4.0, 0, 0.4), tag=3) tree.append(3, mpoint(20, 4.0, 0, 0.4), mpoint(26, 6.0, 0, 0.2), tag=3) tree.append(2, mpoint(12, -0.5, 0, 0.5), mpoint(19, -3.0, 0, 0.5), tag=3) tree.append(5, mpoint(19, -3.0, 0, 0.5), mpoint(24, -7.0, 0, 0.2), tag=3) tree.append(5, mpoint(19, -3.0, 0, 0.5), mpoint(23, -1.0, 0, 0.2), tag=3) tree.append(7, mpoint(23, -1.0, 0, 0.2), mpoint(26, -2.0, 0, 0.2), tag=3) # Two segments that define the axon, with the first at the root, where its proximal # end will be connected with the proximal end of the soma segment. tree.append(mnpos, mpoint(0, 0.0, 0, 2.0), mpoint(-7, 0.0, 0, 0.4), tag=2) tree.append(9, mpoint(-7, 0.0, 0, 0.4), mpoint(-10, 0.0, 0, 0.4), tag=2)
- append(parent, prox, dist, tag)¶
Append a segment to the tree.
- append(parent, dist, tag)
Append a segment to the tree whose proximal end has the location and radius of the distal end of the parent segment.
This version of append can’t be used for a segment at the root of the tree, that is, when
parentismnpos, in which case both proximal and distal ends of the segment must be specified.- Returns:
index of the new segment
- Parameters:
parent (int) – index of segment
dist (mpoint) – distal end of the segment
tag (int) – tag metadata of the segment
- append(parent, x, y, z, radius, tag)
Append a segment to the tree whose proximal end has the location and radius of the distal end of the parent segment.
This version of append can’t be used for a segment at the root of the tree, that is, when
parentismnpos, in which case both proximal and distal ends of the segment must be specified.- Returns:
index of the new segment
- Parameters:
parent (int) – index of segment
x (float) – distal x coordinate (μm)
y (float) – distal y coordinate (μm)
z (float) – distal z coordinate (μm)
radius (float) – distal radius (μm)
tag (int) – tag metadata of the segment
- split_at(id)¶
Split a segment_tree
Tinto a pair of subtrees(L, R)such thatRis the subtree ofTthat starts at the given id and L isTwithoutR. Splitting above the rootmnposreturns(T, {}).
- join_at(id, other)¶
Join two subtrees
LandRat a givenidinL, such thatjoin_atis inverse tosplit_atfor a proper choice ofid. The join pointidmust be inL.
- tag_roots(tag)¶
Get IDs of roots of region with a particular
tagin the segment tree, i.e. segments whose parent is eithermnposor a segment with a different tag.
- apply_isometry(iso)¶
Apply an
isometryto the segment tree and return the transformed tree as a copy. Isometries are rotations around an arbitrary axis and/or translations; they can be instantiated usingtranslateandrotateand combined using the*operator.- Returns:
new tree
- Parameters:
iso – isometry
- equivalent(other)¶
Two trees are equivalent if
the root segments’
proxanddistpoints and theirtagsare identical.recursively: all sub-trees starting at the current segment are equivalent.
- empty: bool¶
If the tree is empty (i.e., whether it has size 0)
- size: int¶
The number of segments.
- parents: list¶
A list of parent indexes of the segments.
- show()¶
Return a string containing an ASCII rendering of the tree.
- Returns:
string
- class arbor.morphology¶
A morphology describes the geometry of a cell as unbranched cables with variable radius and their associated tree structure.
Note
A morphology takes a segment tree and constructs the cable branches. Metadata about branches and their properties that may be expensive to calculate is stored for fast look-up during the later stages of model building and querying by users.
For this reason, morphologies are read-only. To change a morphology, a new morphology should be created using a new segment tree.
There is one constructor for a morphology:
- morphology(segment_tree)¶
Construct from a segment tree.
The morphology provides an interface for querying morphology properties:
- empty: bool¶
Indicates if the morphology is empty.
- num_branches: int¶
The number of branches in the morphology.
- branch_parent(i)¶
The parent branch of a branch.
- Parameters:
i (int) – branch index
- Return type:
int
- branch_children(i)¶
The child branches of a branch.
- Parameters:
i (int) – branch index
- Return type:
list
- branch_segments(i)¶
A list of the segments in a branch, ordered from proximal to distal.
- Parameters:
i (int) – branch index
- Return type:
list[msegment]
- show()¶
Return a string containing an ASCII rendering of the morphology.
- Returns:
string
- class arbor.place_pwlin¶
A
place_pwlinobject allows the querying of the 3-d location of locations and cables in a morphology. Refer to the C++ documentation forplace_pwlinfor more details.- place_pwlin(morphology, isometry)¶
- place_pwlin(morphology)
Construct a piecewise linear placement of the morphology in space, optionally applying the given isometry.
- at(loc: location) location¶
Return any single point corresponding to the
locationlocin the placement.
- all_at(loc: location) list[location]¶
Return all points corresponding to the given
locationlocthe placement.
- segments(cables: list[cable]) list[msegment]¶
Return any minimal collection of segments and partial segments whose union is coterminous with the sub-region of the morphology covered by the given cables in the placement.
- class arbor.isometry¶
Isometries represent rotations and translations in space, and can be used with
place_pwlinto position a morphology in an arbitrary spatial location and orientation. Refer to the C++ documentation forisometryfor more details.- static translate(x: float, y: float, z: float) isometry¶
Construct a translation (x, y, z) with respect to the extrinsic coordinate system.
- static translate(displacement: Tuple[float, float, float]) isometry
Construct a translation from the elements of the given tuple.
- static translate(displacement: mpoint) isometry
Construct a translation from the (x, y, z) components of the given
mpoint.
- static rotate(theta: float, x: float, y: float, z: float) isometry¶
Construct a rotation of
thetaradians about the axis (x, y, z) with respect to the intrinsic coordinate system.
- static rotate(theta: float, axiss: Tuple[float, float, float]) isometry
Construct a rotation of
thetaradians about the axis given by theaxistuple.
- __call__(point: Tuple[float, float, float, ...]) Tuple[float, float, float, ...]
Apply the isometry to the first three components of the given tuple, interpreted as a point.
- __mul__(a: isometry, b: isometry) isometry¶
Compose the two isometries to form a new isometry that applies b and then applies a. Note that rotations are composed as being with respect to the intrinsic coordinate system, while translations are always taken to be with respect to the extrinsic absolute coordinate system.
Discretisation and CV policies¶
The set of boundary points used by the simulator is determined by a
CV policy. These are objects of type
cv_policy, which has the following public methods:
- class arbor.cv_policy¶
- domain¶
A read-only string expression describing the subset of a cell morphology (region) on which this policy has been declared.
CV policies can be composed with
+and|operators.# The plus operator applies policy = arbor.cv_policy_single('"soma"') + cv_policy('"dend"') # The | operator uses CVs of length 10 μm everywhere, except # on the soma, to which a single CV policy is applied. policy = arbor.cv_policy_max_extent(10) | cv_policy_single('"soma"')
Specific CV policy objects are created by functions described below.
These all take a region parameter that restricts the
domain of applicability of that policy; this facility is useful for specifying
differing discretisations on different parts of a cell’s morphology. When a CV
policy is constrained in this manner, the boundary of the domain will always
constitute part of the CV boundary point set.
- arbor.cv_policy_single(domain='(all)')¶
Use one CV for the whole cell, or one for each connected component of the supplied domain.
# Use one CV for the entire cell (a single-compartment model) single_comp = arbor.cv_policy_single() # Use a single CV for the soma. single_comp_soma = arbor.cv_policy_single('"soma"')
- Parameters:
domain (str) – The region on which the policy is applied.
- arbor.cv_policy_explicit(locset, domain='(all)')¶
Use the provided locset as control volume boundaries.
# Place CV boundaries at the midway of every branch. midbranch_cvp = arbor.cv_policy_explicit('(on-branches 0.5)') # Place CV boundaries at 10 random positions on the soma. random_soma_cvp = arbor.cv_policy_explicit('(uniform (tag 3) 0 9 0)','"soma"')
- Parameters:
locset (str) – The locset on which CV boundaries are placed.
domain (str) – The region on which the policy is applied.
- arbor.cv_policy_every_segment(domain='(all)')¶
Use every sample point in the morphology definition as a CV boundary, optionally restricted to the supplied domain. Each fork point in the domain is represented by a trivial CV.
- Parameters:
domain (str) – The region on which the policy is applied.
- arbor.cv_policy_fixed_per_branch(cv_per_branch, domain='(all)')¶
For each branch in each connected component of the domain (or the whole cell, if no domain is given), evenly distribute boundary points along the branch so as to produce exactly
cv_per_branchCVs.- Parameters:
cv_per_branch (int) – The number of CVs per branch.
domain (str) – The region on which the policy is applied.
- arbor.cv_policy_max_extent(max_extent, domain='(all)')¶
As for
cv_policy_fixed_per_branch(), save the number of CVs on any given branch will be chosen to be the smallest number that ensures no CV will have an extent on the branch longer thanmax_extentmicrometres.- Parameters:
max_etent (float) – The maximum length for generated CVs.
domain (str) – The region on which the policy is applied.
CV discretization as mcables¶
It is often useful for the user to have a detailed view of the CVs generated for a given morphology and cv-policy. For example, while debugging and fine-tuning model implementations, it can be helpful to know how many CVs a cable-cell is comprised of, or how many CVs lie on a certain region of the cell.
The following classes and functions allow the user to inspect the CVs of a cell or region.
- class arbor.cell_cv_data¶
Stores the discretisation data of a cable-cell in terms of CVs and the
cablescomprising each of these CVs.- children(idx) list[int]¶
Returns a list of the indices of the CVs representing the children of the CV at index
idx.
- parent(idx) int¶
Returns the index of the CV representing the parent of the CV at index
idx.
- int num_cv
Returns the total number of CVs on the cell.
- arbor.cv_data(cell) optional<cell_cv_data>¶
Constructs a
cell_cv_dataobject representing the CVs comprising the cable-cell according to thecv_policyprovided in thedecorof the cell. ReturnsNoneif nocv_policywas provided in the decor.- Parameters:
cell (cable_cell) – The cable-cell.
- Return type:
optional<
cell_cv_data>
- arbor.intersect_region(reg, cv_data, integrate_along) list[idx, proportion]¶
Returns a list of tuples
[idx, proportion]identifying the indices (idx) of the CVs from thecv_dataargument that lie in the provided regionreg, and how much of each CV belongs to that region (proportion). Theproportionis either the area proportion or the length proportion, chosen according to theintegrate_alongargument.- Parameters:
reg (str) – The region on the cable-cell represented as s-expression or a label from the label-dictionary of the cell.
cv_data (cell_cv_data) – The cv_data of a cell.
integrate_along (string) – Either “area” or “length”. Decides whether the proportion of a CV is measured according to the area or length of the CV.
- Return type:
list[idx, proportion]
- class arbor.loaded_morphology¶
SWC¶
- arbor.load_swc_arbor(data)¶
Loads the
morphologyfrom an SWC file according to arbor’s SWC specifications. (See the morphology concepts page for more details).The samples in the SWC files are treated as the end points of segments, where a sample and its parent form a segment. The
tagof each segment is the structure identifier of the distal sample. The structure identifier of the first (root) sample is ignored, as it can only be the proximal end of any segment.Note
This method does not interpret the first sample, typically associated with the soma, as a sphere. SWC files with single-point somas are common, for example SONATA model descriptions.
Such representations are challenging to consistently interpret in different simulation tools because they require heuristics and, often undocumented, rules for how to interpret the connection of axons and dendrites to the soma.
The
load_swc_neuron()function provides support for loading SWC files according to the interpretation used by NEURON.- Parameters:
data – string or Path with the name of the SWC file or a handle we can read from
- Return type:
- load_swc_neuron(filename, **, allow_non_monotonic_ids=False,
- allow_mismatched_tags=False,
- tags={1: "soma", 2: "axon", 3: "dend", 4: "apic"},
- )
Loads the
morphologyfrom an SWC file according to NEURON’sImport3Dinterpretation of the SWC specification. See the SWC file documentation for more details.- Parameters:
data – string or Path with the name of the SWC file or a handle we can read from
allow_non_monotonic_ids – allow skips in parent/child relations
allow_mismatched_tags – disable checking for tag congruence between parent and child
tags – permissible SWC tags as dict of tag -> name
- Return type:
NeuroML¶
- class arbor.nml_metadata¶
A
nml_metadataobject contains extra information specific to NeuroML.- cell_id: optional<str>¶
The id attribute of the cell that was used to find the morphology in the NeuroML document, if any.
- id: str¶
The id attribute of the morphology.
- group_segments: dict[str, list[long]]¶
A map from each segment group id to its corresponding collection of segments.
- segments()¶
Returns a label dictionary with a region entry for each segment, keyed by the segment id (as a string).
- Return type:
- named_segments()¶
Returns a label dictionary with a region entry for each name attribute given to one or more segments. The region corresponds to the union of all segments sharing the same name attribute.
- Return type:
- groups()¶
Returns a label dictionary with a region entry for each defined segment group.
- Return type:
- class arbor.neuroml¶
A
neuromlobject represents NeuroML documents, and provides methods for the identification and translation of morphology data.An implementation limitation restricts valid segment id values to those that can be represented by an unsigned long long value.
The
allow_spherical_rootoptional parameter below, if set to true, will instruct the parser to interpret a zero-length constant radius root segment as denoting a spherical segment, and this will in turn be represented in the resultant morphology by a cylinder of equivalent surface area.- neuroml(filename)¶
Build a NeuroML document representation from the supplied file contents.
- Parameters:
filename (str) – the name of the NeuroML file.
- cell_ids()¶
Return the id of each
<cell>element defined in the NeuroML document.- Return type:
list[str]
- morphology_ids()¶
Return the id of each top-level
<morphology>element defined in the NeuroML document.- Return type:
list[str]
- morphology(morph_id, allow_spherical_root=false)¶
Returns a representation of the top-level morphology with the supplied morph_id if it could be found. Parse errors or an inconsistent representation will raise an exception.
- Parameters:
morph_id (str) – ID of the top-level morphology.
allow_spherical_root (bool) – Treat zero-length root segments especially.
- Return type:
optional(loaded_morphology)
- cell_morphology(cell_id, allow_spherical_root=false)¶
Returns a representation of the morphology associated with the cell with the supplied cell_id if it could be found. Parse errors or an inconsistent representation will raise an exception.
- Parameters:
morph_id (str) – ID of the cell.
allow_spherical_root (bool) – Treat zero-length root segments especially.
- Return type:
optional(loaded_morphology)
Neurolucida¶
- class arbor.asc_marker¶
One of
dot,circle,cross, ornone.
- class arbor.asc_color¶
RGB triple.
- class arbor.asc_spine¶
Marked spine, comprising:
- location¶
mpointof the spine.
- name¶
Associated name.
- class arbor.asc_marker_set¶
Locations of interest, given as
- locations¶
List of
mpoint.
- marker¶
Associated
asc_marker.
- color¶
Associated
asc_color.
- name¶
Associated name.
- class arbor.asc_metadata¶
The morphology and label dictionary meta-data loaded from a Neurolucida ASCII
.ascfile.- markers¶
List of marker sets in the input.
- spines¶
List of spines in the input.
- arbor.load_asc(filename)¶
Loads the
asc_morphologyfrom a Neurolucida ASCII file.import arbor # Load morphology and labels from the file. asc = arbor.load_asc('granule.asc') # Construct a cable cell. cell = arbor.cable_cell(asc.morphology, arbor.decor(), asc.labels)
- Parameters:
filename (str) – the name of the input file.
- Return type:
asc_morphology