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

Add convex hull function #13

Merged
merged 4 commits into from
Jan 19, 2023
Merged

Add convex hull function #13

merged 4 commits into from
Jan 19, 2023

Conversation

linwang9926
Copy link
Collaborator

  • Add get_convhull function.
  • Test the function using canola and rice models, instance(s) with NaN nodes.

@codecov
Copy link

codecov bot commented Jan 9, 2023

Codecov Report

Merging #13 (ecca898) into main (6faba20) will increase coverage by 1.32%.
The diff coverage is 100.00%.

@@            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              
Impacted Files Coverage Δ
sleap_roots/convhull.py 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@linwang9926 linwang9926 requested a review from talmo January 9, 2023 19:26
Copy link
Contributor

@talmo talmo left a 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

from typing import Tuple


def get_convhull(
Copy link
Contributor

@talmo talmo Jan 10, 2023

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
    ...

Copy link
Contributor

@talmo talmo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@linwang9926 linwang9926 merged commit 3c156b3 into main Jan 19, 2023
@linwang9926 linwang9926 deleted the lin/add_convex_hull_function branch January 19, 2023 22:34
eberrigan pushed a commit that referenced this pull request Mar 14, 2024
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants