Skip to content

Commit

Permalink
Added check to get_network_distribution for root length > 1
Browse files Browse the repository at this point in the history
  • Loading branch information
eberrigan committed Sep 22, 2023
1 parent 7f92031 commit 611d0e0
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions sleap_roots/networklength.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import numpy as np
from shapely import LineString, Polygon
from sleap_roots.lengths import get_root_lengths, get_max_length_pts
from typing import Optional, Tuple, Union
from sleap_roots.lengths import get_max_length_pts
from typing import Tuple, Union


def get_bbox(pts: np.ndarray) -> Tuple[float, float, float, float]:
Expand Down Expand Up @@ -198,10 +198,11 @@ def get_network_distribution(
# Calculate length of roots within the lower bounding box
network_length = 0
for root in all_roots:
root_poly = LineString(root)
lower_intersection = root_poly.intersection(lower_box)
root_length = lower_intersection.length
network_length += root_length if ~np.isnan(root_length) else 0
if len(root) > 1: # Ensure that root has more than one point
root_poly = LineString(root)
lower_intersection = root_poly.intersection(lower_box)
root_length = lower_intersection.length
network_length += root_length if ~np.isnan(root_length) else 0

return network_length

Expand Down

0 comments on commit 611d0e0

Please sign in to comment.