-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add convex hull function #13
Conversation
Codecov Report
@@ Coverage Diff @@
## main #13 +/- ##
==========================================
+ Coverage 93.20% 94.53% +1.32%
==========================================
Files 6 7 +1
Lines 103 128 +25
==========================================
+ Hits 96 121 +25
Misses 7 7
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small change to factorize the function
sleap_roots/convhull.py
Outdated
from typing import Tuple | ||
|
||
|
||
def get_convhull( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is maybe a semantic preference, but I'd call this get_convhull_features
.
The convex hull is technically defined by a set of points, so that's what I'd expect to get back from calling a function named get_convhull
.
A better organization here might be to split this into two functions, where one just gets the convhull points:
def get_convhull(pts: np.ndarray) -> Optional[ConvexHull]:
pts = pts.reshape(-1, 2)
pts = pts[~(np.isnan(pts).any(axis=-1))]
if len(pts) <= 2:
return None
# Get Convex Hull
hull = ConvexHull(pts)
return hull
And the second one which takes the ConvexHull
instance and gives you back features. I appreciate it's more cumbersome to have to call two functions, so you could add a convenience checker to compute the convhull if needed:
def get_convhull_features(pts: Union[np.ndarray, ConvexHull]):
hull = pts if type(pts) == ConvexHull else get_convhull(pts)
if hull is None:
return np.full((7,), np.nan)
# perimeter
perimeter = hull.area
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
* Add convex hull function, test canola, rice models and NaN nodes. * Fix convhull test function by changing the test name. * Separate functions of get_convhull and get_convhull_features. * Formatting convhull.py Co-authored-by: Lin Wang <linwang9926@gmail.com>
get_convhull
function.