diff --git a/CHANGELOG.rst b/CHANGELOG.rst index de024a1e..4d0b572d 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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 diff --git a/neurom/features/bifurcation.py b/neurom/features/bifurcation.py index 65db001e..6c628d15 100644 --- a/neurom/features/bifurcation.py +++ b/neurom/features/bifurcation.py @@ -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) diff --git a/tests/features/test_bifurcation.py b/tests/features/test_bifurcation.py index 530a4c4e..f2eea4c0 100644 --- a/tests/features/test_bifurcation.py +++ b/tests/features/test_bifurcation.py @@ -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)