neuron_morphology.features.layer.layer_histogram module

class neuron_morphology.features.layer.layer_histogram.EarthMoversDistanceInterpretation[source]

Bases: enum.Enum

Describes how to understand an earth mover’s distance result. This is useful in the case that one or both histograms are all 0.

BothEmpty = 2
BothPresent = 0
OneEmpty = 1
class neuron_morphology.features.layer.layer_histogram.EarthMoversDistanceResult[source]

Bases: tuple

The result of comparing two histograms using earth mover’s distance

Attributes:
interpretation

Alias for field number 1

result

Alias for field number 0

Methods

count(self, value, /) Return number of occurrences of value.
index(self, value[, start, stop]) Return first index of value.
to_dict_human_readable  
interpretation

Alias for field number 1

result

Alias for field number 0

to_dict_human_readable(self)[source]
class neuron_morphology.features.layer.layer_histogram.LayerHistogram[source]

Bases: tuple

The results of calculating a within-layer depth histogram of points within some cortical layer.

Attributes:
bin_edges

Alias for field number 1

counts

Alias for field number 0

Methods

count(self, value, /) Return number of occurrences of value.
index(self, value[, start, stop]) Return first index of value.
bin_edges

Alias for field number 1

counts

Alias for field number 0

neuron_morphology.features.layer.layer_histogram.ensure_layers(layers)[source]

Make sure the argued layer array is a tuple

neuron_morphology.features.layer.layer_histogram.ensure_node_types(node_types)[source]

Make sure the argued node types are a tuple

neuron_morphology.features.layer.layer_histogram.ensure_tuple(inputs: Any, item_type: Type, if_none: Union[str, Tuple] = 'raise') → Tuple[source]

Try to smartly coerce inputs to a tuple.

Parameters:
inputs : the data to be coerced
item_type : which type do/should the elements of the tuple have?
if_none : if the inputs are none, return this value. If the value is

“raise”, instead raise an exception

Returns:
the coerced inputs
neuron_morphology.features.layer.layer_histogram.histogram_earth_movers_distance(from_hist: numpy.ndarray, to_hist: numpy.ndarray) → neuron_morphology.features.layer.layer_histogram.EarthMoversDistanceResult[source]

Calculate the earth mover’s distance between to histograms, normalizing each. If one histogram is empty, return the sum of the other and a flag. If both are empty, return 0 a and a flag.

Parameters:
from_hist : distance is calculated between (the normalized form of) this

histogram and to_hist. The result is symmetric.

to_hist : distance is calculated between (the normalized form of) this

histogram and from_hist

Returns:
The distance between input histograms, along with an enum indicating
whether one or both of the histograms was all 0.
neuron_morphology.features.layer.layer_histogram.normalized_depth_histogram_within_layer(point_depths: numpy.ndarray, local_layer_pia_side_depths: numpy.ndarray, local_layer_wm_side_depths: numpy.ndarray, reference_layer_depths: neuron_morphology.features.layer.reference_layer_depths.ReferenceLayerDepths, bin_size: float) → numpy.ndarray[source]

Calculates a histogram of node depths within a single (cortical) layer. Uses reference information about layer boundaries to normalize these depths for cross-reconstruction comparison.

Parameters:
depths : Each item corresponds to a point of interest (such as a node

in a morphological reconstruction). Values are the depths of these points of interest from the pia surface.

local_layer_pia_side_depths : Each item corresponds to a point of interest.

Values are the depth of the intersection point between a path of steepest descent from the pia surface to the point of interest and the upper surface of the layer.

local_layer_wm_side_depths : Each item corresponds to a point of interest.

Values are the depth of the intersection point between the layer’s lower boundary and the path described above.

reference_layer_depths : Used to provide normalized depths suitable

for comparison across reconstructions. Should provide a generic equivalent of local layer depths for a population or reference space.

bin_size : The width of each bin, in terms of depths from pia in the

reference space. Provide only one of bin_edges or bin_size.

Returns:
A numpy array listing for each depth bin the number of nodes falling within

that bin.

Notes

This function relies on the notion of a steepest descent path through cortex, but is agnostic to the method used to obtain such a path and to features of the path (e.g. whether it is allowed to curve). Rather the caller must ensure that all depths have been calculated according to a consistent scheme.

neuron_morphology.features.layer.layer_histogram.normalized_depth_histograms_across_layers(data: neuron_morphology.feature_extractor.data.Data, point_types: Union[Tuple[int], NoneType] = None, only_layers: Union[Tuple[str], NoneType] = None, bin_size=5.0) → Dict[str, neuron_morphology.features.layer.layer_histogram.LayerHistogram][source]

A helper function for running cortical depth histograms across multiple layers.

Parameters:
data : must have reference_layer_depths and layered_point_depths
point_types : calculate histograms for points labeled with these types
only_layers : exclude other layers from this calculation
bin_size : the size of each depth bin. Default is appropriate if the units

are microns.