diff --git a/brain/python/brain/neuron/__init__.py b/brain/python/brain/neuron/__init__.py index ed03d35..fddf46d 100644 --- a/brain/python/brain/neuron/__init__.py +++ b/brain/python/brain/neuron/__init__.py @@ -17,3 +17,35 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. from .._brain._neuron import * + +import numpy as _np + +def compute_morphological_samples(morphology, sections, segments, distances): + """Compute the 3D position and radius of the morphological samples identified + by tuples of section, segment and distance from segment's start. + + The input tuples are given as three separate iterables of equal length. The + result is a numpy array of dtype = float and shape = n x 4, where n is the + length of input iterables. + """ + + samples = _np.empty((len(sections), 4)) + + original_samples = { + id : morphology.section(int(id)).samples() for id in set(sections)} + index = 0 + for section, segment, distance in zip(sections, segments, distances): + section = original_samples[section] + + s = section[segment + 1] - section[segment] + if not s.any(): + # The points are equal + samples[index] = section[segment] + index += 1 + continue + + a = distance / _np.linalg.norm(s) + samples[index] = (section[segment] * (1 - a) + section[segment + 1] * a) + index += 1 + + return samples diff --git a/brain/synapse.h b/brain/synapse.h index 5680c1c..5ca1bbe 100644 --- a/brain/synapse.h +++ b/brain/synapse.h @@ -56,7 +56,8 @@ class Synapse /** @return the segment ID on the presynaptic neuron. */ BRAIN_API uint32_t getPresynapticSegmentID() const; - /** @return the distance in micrometer to the presynaptic neuron. */ + /** @return the distance from the beginning of the presynaptic segment + to the synapse in micrometers. */ BRAIN_API float getPresynapticDistance() const; /** @return the presynaptic touch position on the surface of the segment. */ @@ -77,7 +78,8 @@ class Synapse /** @return the segment ID on the postsynaptic neuron. */ BRAIN_API uint32_t getPostsynapticSegmentID() const; - /** @return the distance in micrometer to the postsynaptic neuron. */ + /** @return the distance from the beginning of the postsynaptic segment + to the synapse in micrometers. */ BRAIN_API float getPostsynapticDistance() const; /** @return the postsynaptic touch position on the surface of the segment.*/ diff --git a/brain/synapses.h b/brain/synapses.h index 2db2beb..6570bb4 100644 --- a/brain/synapses.h +++ b/brain/synapses.h @@ -95,7 +95,8 @@ class Synapses /** @return the segment IDs on the presynaptic neurons. */ BRAIN_API const uint32_t* preSegmentIDs() const; - /** @return the distances in micrometer to the presynaptic neurons. */ + /** @return the distances between each synapse and the beginning of theirs + presynaptic segments in micrometers. */ BRAIN_API const float* preDistances() const; /** @@ -146,7 +147,8 @@ class Synapses /** @return the segment IDs on the postsynaptic neurons. */ BRAIN_API const uint32_t* postSegmentIDs() const; - /** @return the distances in micrometer to the postsynaptic neurons. */ + /** @return the distances between each synapse and the beginning of theirs + postsynaptic segments in micrometers. */ BRAIN_API const float* postDistances() const; /** diff --git a/doc/Changelog.md b/doc/Changelog.md index 363f176..f5a6cbc 100644 --- a/doc/Changelog.md +++ b/doc/Changelog.md @@ -3,6 +3,9 @@ Changelog {#Changelog} # git master +* [152](https://github.com/BlueBrain/Brion/pull/151): + Added the function brain.neuron.compute_morphological_samples to help getting + sample positions from morphologies * [151](https://github.com/BlueBrain/Brion/pull/151): brain::Circuit accepts full paths to mvd files in CircuitPath * [150](https://github.com/BlueBrain/Brion/pull/150):