Brain Python API documentation

This is the reference documention of the Brain Python API. For a quick introduction on the capabilities of this API check the Brain Python tutorial.

brain namespace

class brain._brain.Circuit

Read access to a circuit database

This class provides convenience functions to access information about the cells inside the circuit and their morphologies.

class Coordinates
global_ = brain._brain.Coordinates.global_
local = brain._brain.Coordinates.local
Circuit.__init__((object)arg1, (str)arg2) → object :

Opens a circuit for read access.

Parameters

source - the URI to the CircuitConfig or BlueConfig file.
Circuit.afferent_synapses((Circuit)self, (object)gids[, (SynapsePrefetch)prefetch=brain._brain.SynapsePrefetch.none]) → Synapses :

Access all afferent synapses of the given GIDs.

Parameters

gids - the gids to load afferent synapses for

prefetch - which synapse data to preload

Circuit.efferent_synapses((Circuit)self, (object)gids[, (SynapsePrefetch)prefetch=brain._brain.SynapsePrefetch.none]) → Synapses :

Access all efferent synapses of the given GIDs.

Parameters

gids - the gids to load efferent synapses for

prefetch - which synapse data to preload

Circuit.electrophysiology_type_names((Circuit)self) → list :
Return
The electrophysiology type names of the circuit, indexed by ::getElectrophysiologyTypes().
Circuit.electrophysiology_types((Circuit)self, (object)gids) → object :
Return
The electrophysiology type indices of the given cells in the iteration order of the input gids.
Circuit.gids((Circuit)self) → object :
Return
The arrayof all GIDs held by the circuit.

gids( (Circuit)self, (str)target) -> object :

Return
The arrayof GIDs for the given target name.

Exceptions

std.runtime_error - if the target cannot be found.
Circuit.load_morphologies((Circuit)self, (object)gids, (Coordinates)coords) → list :
Return
The list of morpholgies for the GID set. If local coordinates are requested, morphologies that are repeated in the circuit will shared the same Morphology object in the list. If global coordinates are requested, all Morphology objects are unique.
Circuit.morphology_type_names((Circuit)self) → list :
Return
The morphology type names of the circuit, indexed by ::getMorphologyTypes().
Circuit.morphology_types((Circuit)self, (object)gids) → object :
Return
The morphology type indices of the given cells in the iteration order of the input gids.
Circuit.morphology_uris((Circuit)self, (object)gids) → object :
Return
The set of URIs to access the morphologies of the given cells
Circuit.num_neurons((Circuit)self) → int :
Return
The number of neurons in the circuit.
Circuit.positions((Circuit)self, (object)gids) → object :
Return
The positions of the given cells in the iteration order of the input gids.
Circuit.projected_synapses((Circuit)self, (object)preGids, (object)postGIDs[, (SynapsePrefetch)prefetch=brain._brain.SynapsePrefetch.none]) → Synapses :

Access all synapses along the projection from the pre- to the postGIDs.

Parameters

preGIDs - the gids to load the efferent synapses for

postGIDs - the gids to load the afferent synapses for

prefetch - which synapse data to preload

Circuit.random_gids((Circuit)self, (float)fraction, (str)target) → object

random_gids( (Circuit)self, (float)fraction) -> object :

Return
A random fraction of GIDs from the circuit. Environmental variables: BRAIN_CIRCUIT_SEED set the seed for deterministic randomness

Exceptions

std.runtime_error - if the fraction is not in the range [0,1].
Circuit.rotations((Circuit)self, (object)gids) → object :
Return
A Nx4 numpy array with the local to world rotation of the given cells.
Circuit.transforms((Circuit)self, (object)gids) → object :
Return
A Nx4 numpy array with the local to world transformations of the given cells in the iteration
class brain._brain.CompartmentReport
__init__((object)arg1, (str)arg2) → object
create_view((CompartmentReport)self, (object)gids) → CompartmentReportView :

Create a view of a subset of neurons. An empty gid set creates a view containing all the data.

Version
2.0

Parameters

gids - the neurons of interest

Exceptions

std.runtime_error - if invalid GID set.

create_view( (CompartmentReport)self) -> CompartmentReportView :

Create a view with all the neurons in the report.

Version
2.0
metadata
Return
the metadata of the report
class brain._brain.CompartmentReportMapping
__init__()

Raises an exception This class cannot be instantiated from Python

compartment_counts((CompartmentReportMapping)self) → object :
Get the number of compartments for each section of each neuron in the view Return
the compartment counts for each section for each neuron
Version
2.0
index
Return
return the index of the all the neurons in the view.
Version
2.0
num_compartments((CompartmentReportMapping)arg1, (int)arg2) → int :
Get the number of compartments for the given neuron. Return
number of compartments for the given neuron
Version
2.0

Parameters

index - neuron index per current GID set
offsets

Get the current mapping of each section of each neuron in each simulation frame buffer. For instance, ::getOffsets()[1][15] retrieves the lookup index for the frame buffer for section 15 of neuron with index 1. The neuron index is derived from the order in the GID set provided in the view constructor.

Return
the offset for each section for each neuron
Version
2.0
class brain._brain.CompartmentReportView
__init__()

Raises an exception This class cannot be instantiated from Python

gids
Return
the considered GIDs
Version
2.0
load((CompartmentReportView)self, (float)time) → object :

Load a frame at the given time stamp.

Return
a frame containing the data if found at timestamp, an empty frame otherwise
Version
2.0

Parameters

timestamp - the time stamp of interest

load( (CompartmentReportView)self, (float)start, (float)end) -> object :

Load frames between start and end time stamps.

Return
the frames overlapped by the given time window. The start time doesn’t need to be aligned with the report timestep and the time interval is open on the right. The result may be empty is the time window falls out of the report window.
Version
2.0

Parameters

start - the start time stamp

end - the end time stamp

Exceptions

std.logic_error - if invalid interval
load_all((CompartmentReportView)self) → object :
Load all the frames. This is equivalent to call load(starTime, endTime) Version
2.0
mapping
Return
the data mapping of the view.
Version
2.0
class brain._brain.SpikeReportReader
__init__((object)arg1, (str)arg2) → object :
Construct a new reader opening a spike data source. Version
1.0

Parameters

uri - URI to spike report (can contain a wildcard to specify several files).

Exceptions

std.runtime_error - if source is invalid.

__init__( (object)arg1, (str)arg2, (object)arg3) -> object :

Construct a new reader opening a spike data source. Version
1.0

Parameters

uri - URI to spike report (can contain a wildcard to specify several files).

subset - Subset of cells to be reported. files).

Exceptions

std.runtime_error - if source is invalid.
close((SpikeReportReader)arg1) → None :

Close the data source.

Any thread blocked in getSpikes will return immediately, possibly returning an empty container. This method may be called concurrently to both ::getSpikes() functions and ::hasEnded().

Version
1.0
end_time
Return
the end timestamp of the report. This is the timestamp of the last spike known to be available or larger if the implementation has more metadata available. For stream reports this time is 0 and it is updated when getSpikes is called.
Version
1.0
get_spikes((SpikeReportReader)self, (float)start_time, (float)stop_time) → object :

Get all spikes inside a time window.

For stream reports this method will wait until the first spike with a time larger or equal to end arrives. The time interval is open on the right, so assuming that spikes arrive in order, this method will return a full snapshot of the spikes between [start, end). Precondition : start < end Version
1.0

Exceptions

std.logic_error - if the precondition is not fulfilled.
has_ended
Return
true if any of the versions of ::getSpikes() reaches the end of the stream, if the report is static or if closed has been called.
Version
1.0
class brain._brain.SpikeReportWriter
__init__((object)arg1, (str)arg2) → object
close((SpikeReportWriter)arg1) → None
writeSpikes((SpikeReportWriter)arg1, (Spikes)arg2) → None
class brain._brain.Spikes
__init__()

Raises an exception This class cannot be instantiated from Python

class brain._brain.Synapse

A proxy object returned by the Synapses container to access data for a particular synapse.

The lifetime of this object is stricly bound to the synapses container it comes from.

__init__()

Raises an exception This class cannot be instantiated from Python

conductance((Synapse)self) → float :
Return
the conductance in nanosiemens.
decay((Synapse)self) → float :
Return
the decay time constant in milliseconds.
delay((Synapse)self) → float :
Return
the axonal delay in milliseconds.
depression((Synapse)self) → float :
Return
the depression time constant in milliseconds.
efficacy((Synapse)self) → int :
Return
the absolute synaptic efficacy in millivolts.
facilitation((Synapse)self) → float :
Return
the facilitation time constant in milliseconds.
post_center_position((Synapse)self) → object :
Return
the postsynaptic touch position in the center of the segment.
post_distance((Synapse)self) → float :
Return
the distance in micrometer to the postsynaptic neuron.
post_gid((Synapse)self) → int :
Return
the GID of the postsynaptic neuron.
post_section((Synapse)self) → int :
Return
the section ID on the postsynaptic neuron.
post_segment((Synapse)self) → int :
Return
the segment ID on the postsynaptic neuron.
post_surface_position((Synapse)self) → object :
Return
the postsynaptic touch position on the surface of the segment.
pre_center_position((Synapse)self) → object :
Return
the presynaptic touch position in the center of the segment.
pre_distance((Synapse)self) → float :
Return
the distance in micrometer to the presynaptic neuron.
pre_gid((Synapse)self) → int :
Return
the GID of the presynaptic neuron.
pre_section((Synapse)self) → int :
Return
the section ID on the presynaptic neuron.
pre_segment((Synapse)self) → int :
Return
the segment ID on the presynaptic neuron.
pre_surface_position((Synapse)self) → object :
Return
the presynaptic touch position on the surface of the segment.
utilization((Synapse)self) → float :
Return
the neuro-transmitter release probability.
class brain._brain.SynapsePrefetch

Loading of data during SynapsesStream.read(), otherwise load happens on-demand.

Values:
  • none:
only loads pre- and post GIDs
  • attributes:
topological information (section, segment, distance) and model attributes
  • positions:
pre/post surface/center positions
  • all:

all synapse data

all = brain._brain.SynapsePrefetch.all
attributes = brain._brain.SynapsePrefetch.attributes
none = brain._brain.SynapsePrefetch.none
positions = brain._brain.SynapsePrefetch.positions
class brain._brain.Synapses

A container providing read-only access to Synapses retrieved by getXXXSynapses() functions from brain.Circuit. It provides per-object and per-array access on the various synapses attributes. Data which was not prefetched will be loaded on-demand.

This container can be iterated as well as random accessed using the operator [].

This class is thread-safe, moveable and copyable.

__init__()

Raises an exception This class cannot be instantiated from Python

conductances((Synapses)self) → object :
Return
the conductances in nanosiemens.
decays((Synapses)self) → object :
Return
the decay time constants in milliseconds.
delays((Synapses)self) → object :
Return
the axonal delays in milliseconds.
depressions((Synapses)self) → object :
Return
the depression time constants in milliseconds.
efficacies((Synapses)self) → object :
Return
the absolute synaptic efficacies in millivolts.
empty((Synapses)self) → bool :
Return
size() == 0.
facilitations((Synapses)self) → object :
Return
the facilitation time constants in milliseconds.
indices((Synapses)self) → object :
Return
the synapse GIDs containing GIDs of the post-synaptic cells and the indices in the afferent contacts array.

Exceptions

std.runtime_error - if index information not found in the synapse source of the circuit.
post_center_x_positions((Synapses)self) → object :
Return
the postsynaptic touch position x-coordinates in the center of the segments.
post_center_y_positions((Synapses)self) → object :
Return
the postsynaptic touch position y-coordinates in the center of the segments.
post_center_z_positions((Synapses)self) → object :
Return
the postsynaptic touch position z-coordinates in the center of the segments.
post_distances((Synapses)self) → object :
Return
the distances in micrometer to the postsynaptic neurons.
post_gids((Synapses)self) → object :
Return
the GIDs of the postsynaptic neurons.
post_section_ids((Synapses)self) → object :
Return
the section IDs on the postsynaptic neurons.
post_segment_ids((Synapses)self) → object :
Return
the segment IDs on the postsynaptic neurons.
post_surface_x_positions((Synapses)self) → object :
Return
the postsynaptic touch position x-coordinates on the surfaces of the segments. May be null in old circuits.
post_surface_y_positions((Synapses)self) → object :
Return
the postsynaptic touch position x-coordinates on the surfaces of the segments. May be null in old circuits.
post_surface_z_positions((Synapses)self) → object :
Return
the postsynaptic touch position x-coordinates on the surfaces of the segments. May be null in old circuits.
pre_center_x_positions((Synapses)self) → object :
Return
the presynaptic touch position x-coordinates in the center of the segments.
pre_center_y_positions((Synapses)self) → object :
Return
the presynaptic touch position y-coordinates in the center of the segments.
pre_center_z_positions((Synapses)self) → object :
Return
the presynaptic touch position z-coordinates in the center of the segments.
pre_distances((Synapses)self) → object :
Return
the distances in micrometer to the presynaptic neurons.
pre_gids((Synapses)self) → object :
Return
the GIDs of the presynaptic neurons.
pre_section_ids((Synapses)self) → object :
Return
the section IDs on the presynaptic neurons.
pre_segment_ids((Synapses)self) → object :
Return
the segment IDs on the presynaptic neurons.
pre_surface_x_positions((Synapses)self) → object :
Return
the presynaptic touch position x-coordinates on the surfaces of the segments. May be null in old circuits.
pre_surface_y_positions((Synapses)self) → object :
Return
the presynaptic touch position y-coordinates on the surfaces of the segments. May be null in old circuits.
pre_surface_z_positions((Synapses)self) → object :
Return
the presynaptic touch position z-coordinates on the surfaces of the segments. May be null in old circuits.
utilizations((Synapses)self) → object :
Return
the neuro-transmitter release probabilities.

brain.neuron namespace

class brain._brain._neuron.Morphology

Wrapper around brion.Morphology with higher level functions.

This class provides methods to facilitate some queries about morphologies in the context of circuits. Morphologies can be loaded with a transformation applied to its points, which is useful for operating in global circuit coordinates. The transformation is applied at construction so it cannot be modified or reverted.

Access to the raw data fields is still provided by getter functions.

Version
unstable

Inherits from noncopyable

__init__((object)arg1, (str)arg2) → object :

Create a morphology from a URI and load all the data.

Parameters

source - URI of the morphology data source.

Exceptions

runtime_error - if an inconsistency is detected in the input file.

__init__( (object)arg1, (str)arg2, (object)arg3) -> object :

Create a morphology from a URI, load all the data and transform the points.

Parameters

source - URI of the morphology data source.

transform - the transformation matrix to apply to the points. Radii will not be affected by this transformation.

Exceptions

runtime_error - if an inconsistency is detected in the input file.
apicals((Morphology)self) → object :

Return a 2xN numpy array with the section id and point index of apical points.

points((Morphology)self) → object :

Return a 4xN numpy array with the x,y,z and radius of all the points of this morphology.

section((Morphology)self, (int)id) → Section :

Return the sections which have the given section type. If type is SectionType.Soma an empty list is returned.

section_ids((Morphology)self, (object)types) → object :

Return the list of ids for the given section types.

section_types((Morphology)self) → object :

Return a numpy array with the section types.

sections((Morphology)self) → object :

Return a 2xN numpy array with the parent ID and first point offset of each section.

sections( (Morphology)self, (object)type) -> object :

Return the sections which have any of the given section types. No sections are returned for the type SectionType.Soma.
soma((Morphology)self) → Soma :

Return the object with the information about the neuron soma

transformation((Morphology)self) → object :

Return a 4x4 numpy array with the transformation that was passed to the constructor or the identity matrix is no transformation was given.

class brain._brain._neuron.Section

A class to represent a morphological section.

A Section is an unbranched piece of a morphological skeleton. This class provides functions to query information about the sample points that compose the section and functions to obtain the parent and children sections.

The cell soma is also considered a section, but some functions have special meaning for it.

Sections cannot be directly created, but are returned by several brain.Morphology and brain.Section methods.

This is a lightweight object with STL container style thread safety. It is also safe to use a section after the morphology from where it comes has been deallocated. The morphological data will be kept as long as there is a Section referring to it.

__init__()

Raises an exception This class cannot be instantiated from Python

children((Section)self) → object :

Return a vector with all the direct children of this section. The container will be empty for terminal sections.

distance_to_soma((Section)self) → float :

Return the absolute distance from the start of the section to the soma.

id((Section)self) → int :

Return the ID of this section.

length((Section)self) → float :

Return the total length of this section in microns.

If this section is a soma section the length is ill-defined and this function will return 0.

parent((Section)self) → object :

Return the parent section of this section or None if doesn’t have any.

sample_distances_to_soma((Section)self) → object :

Return the absolute distances to the soma in microns for all sample positions.

Return
A list of distances. For a section consisting of n segments, this list will have n + 1 values. The section length is equal to the difference between the first and last values of the list.
samples((Section)self) → object :

Return the list of all point samples that define this section.

If this sections is a soma section return the list of points of the soma profile poly-line.

Return
A list of point positions with diameter. For a section consisting of n segments, this list will have n + 1 points.

samples( (Section)self, (object)positions) -> object :

Return a list of points sampling this section at discrete locations.

If the section is a soma section this function will return the soma position for all sampling positions. The soma position is assumed to be (0, 0, 0) unless the origin morphology has been transformed.

Return
The section sampled at the given relative positions.

Parameters

points - Normalized positions of the sample points along the section. Values will be clampled to [0, 1] before sampling.
type((Section)self) → SectionType :

Return the morphological type of this section (dendrite, axon, ...).

class brain._brain._neuron.SectionType
apical_dendrite = brain._brain._neuron.SectionType.apical_dendrite
axon = brain._brain._neuron.SectionType.axon
dendrite = brain._brain._neuron.SectionType.dendrite
soma = brain._brain._neuron.SectionType.soma
undefined = brain._brain._neuron.SectionType.undefined
class brain._brain._neuron.Soma

A class to represent a neuron soma.

This class provides functions to query information about the soma of a neuron.

Typically the soma is described as the poly-line of the projection of the soma onto a plane, where the plane normal points in the vertical direction in the local coordinate system of the morphology. In other cases the poly-line is not projected onto a plane, but is an approximation of the countour of the soma as seen in an orhogonal projection down the vertical axis (this is basically the same as before, but the vertical coordinate is not 0 for all the points). This class can also be used for both descriptions as well as somas simply approximated as spheres.

The coordinates system used by a soma will be in the same as the brain.Morphology from where it comes.

Version
unstable
__init__()

Raises an exception This class cannot be instantiated from Python

centroid((Soma)self) → object :

Return the average of the profile points.

mean_radius((Soma)self) → float :

Return the mean distance between the profile points and the centroid.

profile_points((Soma)self) → object :

Return the x,y,z and radius of the points of the soma profile as a 4xN numpy array.