Skip to content

Commit

Permalink
Return nan if no points in shape features (#1018)
Browse files Browse the repository at this point in the history
  • Loading branch information
eleftherioszisis committed Apr 4, 2022
1 parent ed518c4 commit 623cbd9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 3 additions & 3 deletions neurom/features/morphology.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ def aspect_ratio(morph, neurite_type=NeuriteType.all, projection_plane="xy"):
The aspect ratio feature of the morphology points.
"""
projected_points = _unique_projected_points(morph, projection_plane, neurite_type)
return [] if len(projected_points) == 0 else morphmath.aspect_ratio(projected_points)
return np.nan if len(projected_points) == 0 else morphmath.aspect_ratio(projected_points)


@feature(shape=())
Expand All @@ -663,7 +663,7 @@ def circularity(morph, neurite_type=NeuriteType.all, projection_plane="xy"):
The circularity of the morphology points.
"""
projected_points = _unique_projected_points(morph, projection_plane, neurite_type)
return [] if len(projected_points) == 0 else morphmath.circularity(projected_points)
return np.nan if len(projected_points) == 0 else morphmath.circularity(projected_points)


@feature(shape=())
Expand All @@ -683,4 +683,4 @@ def shape_factor(morph, neurite_type=NeuriteType.all, projection_plane="xy"):
The shape factor of the morphology points.
"""
projected_points = _unique_projected_points(morph, projection_plane, neurite_type)
return [] if len(projected_points) == 0 else morphmath.shape_factor(projected_points)
return np.nan if len(projected_points) == 0 else morphmath.shape_factor(projected_points)
3 changes: 3 additions & 0 deletions tests/features/test_get_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,7 @@ def test_aspect_ratio():
0.731076,
decimal=6
)
assert np.isnan(features.get("aspect_ratio", morph, neurite_type=nm.NeuriteType.custom5))


def test_circularity():
Expand All @@ -942,6 +943,7 @@ def test_circularity():
0.730983,
decimal=6
)
assert np.isnan(features.get("circularity", morph, neurite_type=nm.NeuriteType.custom5))


def test_shape_factor():
Expand All @@ -968,3 +970,4 @@ def test_shape_factor():
0.364678,
decimal=6
)
assert np.isnan(features.get("shape_factor", morph, neurite_type=nm.NeuriteType.custom5))

0 comments on commit 623cbd9

Please sign in to comment.