Points¶
Overview¶
Utility functions for manipulating, filtering, and transforming root point arrays.
Key functions:
- join_pts - Combine multiple point arrays
- get_all_pts_array - Flatten to 2D array
- associate_lateral_to_primary - Map laterals to primary
- filter_roots_with_nans - Remove invalid roots
Quick Example¶
import sleap_roots as sr
series = sr.Series.load("plant", primary_path="primary.slp", lateral_path="lateral.slp")
primary_pts = series.get_primary_points()
lateral_pts_list = series.get_lateral_points()
# Combine all points
all_pts = sr.join_pts([primary_pts] + lateral_pts_list)
print(f"Combined points shape: {all_pts.shape}")
# Filter out roots with NaN
valid_laterals = sr.filter_roots_with_nans(lateral_pts_list)
print(f"Valid laterals: {len(valid_laterals)}/{len(lateral_pts_list)}")
API Reference¶
join_pts¶
join_pts ¶
Join an arbitrary number of points arrays and return them as a list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pts0
|
ndarray
|
The first array of points. Should have shape |
required |
*args
|
Optional[ndarray]
|
Additional optional arrays of points. Each should have shape
|
()
|
Returns:
| Type | Description |
|---|---|
List[ndarray]
|
A list of arrays, each having shape |
Source code in sleap_roots/points.py
get_all_pts_array¶
get_all_pts_array ¶
Get all landmark points within a given frame as a flat array of coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pts0
|
ndarray
|
The first array of points. Should have shape |
required |
*args
|
Optional[ndarray]
|
Additional optional arrays of points. Each should have shape
|
()
|
Returns:
| Type | Description |
|---|---|
ndarray
|
A 2D array of shape (n_points, 2), containing the coordinates of all extracted |
ndarray
|
points. |
Source code in sleap_roots/points.py
associate_lateral_to_primary¶
associate_lateral_to_primary ¶
Associates each lateral root with the closest primary root.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
primary_pts
|
ndarray
|
A numpy array of primary root points with shape (instances, nodes, 2), where 'instances' is the number of primary roots, 'nodes' is the number of points in each root, and '2' corresponds to the x and y coordinates. Points cannot have NaN values. |
required |
lateral_pts
|
ndarray
|
A numpy array of lateral root points with a shape similar to primary_pts, representing the lateral roots. Points cannot have NaN values. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
A dictionary where each key is an index of a primary root (from the primary_pts |
dict
|
array) and each value is a dictionary containing 'primary_points' as the points of |
|
dict
|
the primary root (1, nodes, 2) and 'lateral_points' as an array of |
|
dict
|
lateral root points that are closest to that primary root. The shape of |
|
dict
|
'lateral_points' is (instances, nodes, 2), where instances is the number of |
|
dict
|
lateral roots associated with the primary root. |
Source code in sleap_roots/points.py
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 | |
filter_roots_with_nans¶
filter_roots_with_nans ¶
Remove roots with NaN values from an array of root points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pts
|
ndarray
|
An array of points representing roots, with shape (instances, nodes, 2), where 'instances' is the number of roots, 'nodes' is the number of points in each root, and '2' corresponds to the x and y coordinates. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: An array of shape (instances, nodes, 2) with NaN-containing roots removed. If all roots contain NaN values, an empty array of shape (0, nodes, 2) is returned. |
Source code in sleap_roots/points.py
Related Modules¶
- Series - Loading point data
- All trait modules use point utilities