Skip to content

Commit

Permalink
Fix: Raise a clear error when there is no tree of given type
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien-berchet committed May 4, 2023
1 parent 75bab8c commit 1d6f992
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 5 additions & 1 deletion neurots/extract_input/from_TMD.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import tmd

from neurots.utils import NeuroTSError


def persistent_homology_angles(
pop, threshold=2, neurite_type="basal_dendrite", feature="radial_distances"
Expand All @@ -35,12 +37,14 @@ def persistent_homology_angles(
ph_ang = [
tmd.methods.get_ph_angles(tree, feature=feature) for tree in getattr(pop, neurite_type)
]
if not ph_ang:
raise NeuroTSError(f"The given population does contain any tree of {neurite_type} type.")

# Keep only the trees whose number of terminations is above the threshold
# Saves the list of persistence diagrams for the selected neurite_type
phs = [p for p in ph_ang if len(p) > threshold]
if not phs:
raise ValueError(
raise NeuroTSError(
"The given threshold excluded all bars of the persistence diagram, please use a "
"lower threshold value."
)
Expand Down
10 changes: 9 additions & 1 deletion tests/test_extract_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ def test_path_distances(self, filename):

def test_threshold_too_small(self):
with pytest.raises(
ValueError,
NeuroTSError,
match=(
"The given threshold excluded all bars of the persistence diagram, please use a "
"lower threshold value."
Expand All @@ -319,6 +319,14 @@ def test_threshold_too_small(self):
neurite_types=["basal_dendrite"],
)

def test_missing_neurite_type(self):
with pytest.raises(NeuroTSError):
extract_input.distributions(
os.path.join(_PATH, "diam_simple.swc"),
feature="path_distances",
neurite_types=["basal_dendrite", "apical_dendrite"],
)

def test_trunk_length(self, filename):
distr = extract_input.distributions(filename, feature="trunk_length")
assert "persistence_diagram" not in distr["basal_dendrite"]
Expand Down

0 comments on commit 1d6f992

Please sign in to comment.