Skip to content

Commit

Permalink
Use iter_segments in segment features
Browse files Browse the repository at this point in the history
  • Loading branch information
eleftherioszisis committed Mar 15, 2022
1 parent 16bb8e0 commit 17060f5
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions neurom/features/neurite.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
from neurom import morphmath
from neurom.utils import flatten
from neurom.core.types import NeuriteType
from neurom.core.morphology import Section
from neurom.core.morphology import Section, iter_segments
from neurom.core.dataformat import COLS
from neurom.features import NameSpace, feature, bifurcation as bf, section as sf
from neurom.geom import convex_hull
Expand Down Expand Up @@ -237,34 +237,33 @@ def segment_lengths(neurite, section_type=NeuriteType.all):
@feature(shape=(...,))
def segment_areas(neurite, section_type=NeuriteType.all):
"""Areas of the segments."""
def func(section):
points = section.points
return [morphmath.segment_area(seg) for seg in zip(points[:-1], points[1:])]
def section_segment_areas(section):
return map(morphmath.segment_area, iter_segments(section))

return _map_segments(func, neurite, section_type=section_type)
return _map_segments(section_segment_areas, neurite, section_type=section_type)


@feature(shape=(...,))
def segment_volumes(neurite, section_type=NeuriteType.all):
"""Volumes of the segments."""

def _func(sec):
def section_segment_volumes(section):
"""List of segment volumes of a section."""
return [morphmath.segment_volume(seg) for seg in zip(sec.points[:-1], sec.points[1:])]
return map(morphmath.segment_volume, iter_segments(section))

return _map_segments(_func, neurite, section_type=section_type)
return _map_segments(section_segment_volumes, neurite, section_type=section_type)


@feature(shape=(...,))
def segment_radii(neurite, section_type=NeuriteType.all):
"""Arithmetic mean of the radii of the points in segments."""

def _seg_radii(sec):
def section_segment_radii(sec):
"""Vectorized mean radii."""
pts = sec.points[:, COLS.R]
return np.divide(np.add(pts[:-1], pts[1:]), 2.0)

return _map_segments(_seg_radii, neurite, section_type=section_type)
return _map_segments(section_segment_radii, neurite, section_type=section_type)


@feature(shape=(...,))
Expand All @@ -274,14 +273,14 @@ def segment_taper_rates(neurite, section_type=NeuriteType.all):
The taper rate is defined as the absolute radii differences divided by length of the section
"""

def _seg_taper_rates(sec):
def section_segment_taper_rates(sec):
"""Vectorized taper rates."""
pts = sec.points[:, COLS.XYZR]
diff = np.diff(pts, axis=0)
distance = np.linalg.norm(diff[:, COLS.XYZ], axis=1)
return np.divide(2 * np.abs(diff[:, COLS.R]), distance)

return _map_segments(_seg_taper_rates, neurite, section_type=section_type)
return _map_segments(section_segment_taper_rates, neurite, section_type=section_type)


@feature(shape=(...,))
Expand Down

0 comments on commit 17060f5

Please sign in to comment.