# Copyright (c) 2015, Ecole Polytechnique Federale de Lausanne, Blue Brain Project
# All rights reserved.
#
# This file is part of NeuroM <https://github.com/BlueBrain/NeuroM>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
#     1. Redistributions of source code must retain the above copyright
#        notice, this list of conditions and the following disclaimer.
#     2. Redistributions in binary form must reproduce the above copyright
#        notice, this list of conditions and the following disclaimer in the
#        documentation and/or other materials provided with the distribution.
#     3. Neither the name of the copyright holder nor the names of
#        its contributors may be used to endorse or promote products
#        derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

'''Basic functions and iterators for neuron neurite segment morphometrics

'''
import functools
from neurom.core import tree as tr
import neurom.analysis.morphmath as mm


iter_type = tr.isegment


def itr(neuron, mapping=None, filt=None):
    '''Iterator to neuron's segments

    Applies a filter function and a mapping.

    Example:
        Get the lengths of segments in a neuron and a population

        >>> neuron_lengths = [l for l in seg.itr(nrn, seg.length)]
        >>> population_lengths = [l for l in seg.itr(pop, seg.length)]

    '''
    return tr.i_chain(neuron.neurites, iter_type, mapping, filt)


length = mm.segment_length
radius = mm.segment_radius
volume = mm.segment_volume
area = mm.segment_area


def radial_dist(pos):
    '''Return a function that calculates radial distance for a segment

    Radial distance calculater WRT pos
    '''
    return functools.partial(mm.segment_radial_dist, pos=pos)


def n_segments(neuron):
    """
    Return number of segments in neuron or population
    """
    return sum(1 for _ in itr(neuron))

@@ -1946,22 +1946,45 @@
 ator to 
+a 
 neuron
+ or neuron population
 's segme
@@ -2002,16 +2002,24 @@
 plies a 
+neurite 
 filter f
@@ -2032,16 +2032,24 @@
 n and a 
+segment 
 mapping.
@@ -2129,16 +2129,63 @@
 lation%0A%0A
+        %3E%3E%3E from neurom import segments as seg%0A
         

improve neurom.segments docs