Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix partition_asymmetry Uylings to not throw for bifurcations with leaves #1001

Merged
merged 1 commit into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ Changelog

Version 3.2.0
-------------

- Fix ``neurom.features.bifurcation.partition_asymmetry`` Uylings variant to not throw
for bifurcations with leaves.
- Fix ``neurom.features.neurite.principal_direction_extents`` to remove duplicate points
when calculated.
- Add ``neurom.features.morphology.volume_density`` feature so that it is calculated
correctly when the entire morphology is taken into account instead of summing the per
neurite volume densities.
- Add support for py39 and py310 testing.
- Fix ``neurom.features.morphology.sholl_frequency`` to return an empty list when a
neurite_type that is not present in the morphology is specified.
- Fix ``neurom.features.morphology.trunk_origin_radii`` to warn and use only the root
Expand Down
13 changes: 7 additions & 6 deletions neurom/features/bifurcation.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,13 @@ def partition_asymmetry(bif_point, uylings=False):

n = float(sum(1 for _ in bif_point.children[0].ipreorder()))
m = float(sum(1 for _ in bif_point.children[1].ipreorder()))
c = 0
if uylings:
c = 2
if n + m <= c:
raise NeuroMError('Partition asymmetry cant be calculated by Uylings because the sum of'
'terminal tips is less than 2.')

if n == m == 1:
# By definition the asymmetry A(1, 1) is zero
return 0.0

c = 2.0 if uylings else 0.0

return abs(n - m) / abs(n + m - c)


Expand Down
3 changes: 1 addition & 2 deletions tests/features/test_bifurcation.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ def test_partition_asymmetry():
assert bf.partition_asymmetry(root) == 0.5
assert bf.partition_asymmetry(root.children[0]) == 0.0
assert bf.partition_asymmetry(root, True) == 1.0
with pytest.raises(NeuroMError, match='Uylings'):
bf.partition_asymmetry(root.children[0], True)
assert bf.partition_asymmetry(root.children[0], True) == 0.0

leaf = root.children[0].children[0]
assert_raises(NeuroMError, bf.partition_asymmetry, leaf)
Expand Down