Series
series ¶
Series-level data loader.
Series ¶
Data and predictions for a single image series.
Attributes:
| Name | Type | Description |
|---|---|---|
series_name |
str
|
Unique identifier for the series. |
h5_path |
Optional[str]
|
Optional path to the HDF5-formatted image series. |
primary_path |
Optional[str]
|
Optional path to the primary root predictions file. At least one of the primary, lateral, or crown paths must be provided. |
lateral_path |
Optional[str]
|
Optional path to the lateral root predictions file. At least one of the primary, lateral, or crown paths must be provided. |
crown_path |
Optional[str]
|
Optional path to the crown predictions file. At least one of the primary, lateral, or crown paths must be provided. |
primary_labels |
Optional[Labels]
|
Optional |
lateral_labels |
Optional[Labels]
|
Optional |
crown_labels |
Optional[Labels]
|
Optional |
video |
Optional[Video]
|
Optional |
csv_path |
Optional[str]
|
Optional path to a metadata CSV. The CSV is keyed on a
|
sample_uid |
Optional[str]
|
Optional cross-scan stable identity for this series. Defaults to
|
Methods:
| Name | Description |
|---|---|
load |
Load a set of predictions for this series. |
get_metadata |
Generic CSV-column accessor keyed on |
__len__ |
Length of the series (number of images). |
__getitem__ |
Return labeled frames for predictions. |
__iter__ |
Iterator for looping through predictions. |
get_frame |
Return labeled frames for predictions. |
plot |
Plot predictions on top of the image. |
get_primary_points |
Get primary root points. |
get_lateral_points |
Get lateral root points. |
get_crown_points |
Get crown root points. |
Properties
expected_count: Fetch the expected plant count for this series from the CSV. group: Group name for the series from the CSV. qc_fail: Flag to indicate if the series failed QC from the CSV. timepoint: Numeric time-axis value for this series, coerced to float.
expected_count
property
¶
Fetch the expected plant count for this series from the CSV.
qc_fail
property
¶
Flag to indicate if the series failed QC from the CSV.
timepoint
property
¶
Numeric time-axis value for this series, coerced to float.
Returns np.nan when the CSV is absent, the timepoint column is missing,
or no row matches sample_uid. Raises ValueError when a matching row
contains a non-numeric string value (e.g. a date) OR a non-finite value
(inf, -inf) — failing loudly at the metadata layer beats silently
producing nonsensical results in downstream timepoint arithmetic.
__attrs_post_init__ ¶
Default sample_uid to series_name and coerce to str.
load
classmethod
¶
load(
series_name: str,
h5_path: Optional[str] = None,
primary_path: Optional[str] = None,
lateral_path: Optional[str] = None,
crown_path: Optional[str] = None,
csv_path: Optional[str] = None,
sample_uid: Optional[str] = None,
) -> Series
Load a set of predictions for this series.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
series_name
|
str
|
Unique identifier for the series. |
required |
h5_path
|
Optional[str]
|
Optional path to the HDF5-formatted image series, which will be used to load the video. |
None
|
primary_path
|
Optional[str]
|
Optional path to the primary root '.slp' predictions file. |
None
|
lateral_path
|
Optional[str]
|
Optional path to the lateral root '.slp' predictions file. |
None
|
crown_path
|
Optional[str]
|
Optional path to the crown '.slp' predictions file. |
None
|
csv_path
|
Optional[str]
|
Optional path to a metadata CSV (keyed on |
None
|
sample_uid
|
Optional[str]
|
Optional cross-scan stable identity. Defaults to |
None
|
Returns:
| Type | Description |
|---|---|
Series
|
An instance of Series loaded with the specified predictions. |
Source code in sleap_roots/series.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
get_metadata ¶
Fetch a CSV column value keyed on sample_uid (and optional plant_id).
Looks up df[df["plant_qr_code"] == self.sample_uid]. If plant_id is given
AND the CSV has a plant_id column, the lookup is the composite
(sample_uid, plant_id) match. If plant_id is given but the CSV has no
plant_id column, the argument is silently ignored, the sample-uid-only
lookup is used, and a one-shot WARNING is emitted (per Series instance).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
column
|
str
|
The CSV column name to fetch. |
required |
plant_id
|
Optional[int]
|
Optional per-plant disambiguator. Used only when the CSV has a
|
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The value in the first matching row's |
Any
|
when the CSV is missing, the requested |
Any
|
|
Any
|
or no row matches. |
Source code in sleap_roots/series.py
__len__ ¶
Length of the series (number of images).
Source code in sleap_roots/series.py
__getitem__ ¶
Return labeled frames for primary and/or lateral and/or crown predictions.
__iter__ ¶
get_frame ¶
Return labeled frames for primary, lateral, and crown predictions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame_idx
|
int
|
Integer frame number. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary with keys 'primary', 'lateral', and 'crown', each corresponding |
dict
|
to the |
dict
|
any set of predictions is not available, its value will be None. |
Source code in sleap_roots/series.py
plot ¶
Plot predictions on top of the image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame_idx
|
int
|
Frame index to visualize. |
required |
scale
|
float
|
Relative size of the visualized image. Useful for plotting smaller images within notebooks. |
1.0
|
Returns:
| Type | Description |
|---|---|
Figure
|
matplotlib.figure.Figure object that shows predictions on top of images. |
Source code in sleap_roots/series.py
get_primary_points ¶
Get primary root points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame_idx
|
int
|
Frame index. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Primary root points as array of shape |
Source code in sleap_roots/series.py
get_lateral_points ¶
Get lateral root points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame_idx
|
int
|
Frame index. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Lateral root points as array of shape |
Source code in sleap_roots/series.py
get_crown_points ¶
Get crown root points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
frame_idx
|
int
|
Frame index. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Crown root points as array of shape |
Source code in sleap_roots/series.py
get_tracked_tips ¶
Return per-frame tracked-tip rows in long format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root_type
|
Optional[str]
|
One of |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
A |
DataFrame
|
"tip_x", "tip_y"] |
DataFrame
|
with a clean range index. One row per |
DataFrame
|
the track has an instance. |
DataFrame
|
Coordinates |
DataFrame
|
top-left, y increases downward), matching the SLEAP |
DataFrame
|
convention. The tip coordinate is the LAST node of the |
DataFrame
|
skeleton ( |
DataFrame
|
by |
DataFrame
|
single-node skeletons (e.g. |
DataFrame
|
skeletons (e.g. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When |
Source code in sleap_roots/series.py
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 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 | |
find_all_h5_paths ¶
Find all .h5 paths from a list of folders.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_folders
|
Union[str, List[str]]
|
Path or list of paths to folders containing .h5 paths. |
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
A list of filenames to .h5 paths. |
Source code in sleap_roots/series.py
find_all_slp_paths ¶
Find all .slp paths from a list of folders.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_folders
|
Union[str, List[str]]
|
Path or list of paths to folders containing .slp paths. |
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
A list of filenames to .slp paths. |
Source code in sleap_roots/series.py
load_series_from_h5s ¶
load_series_from_h5s(
h5_paths: List[str],
model_id: str,
csv_path: Optional[str] = None,
) -> List[Series]
Load a list of Series from a list of .h5 paths.
To load the Series, the files must be named with the following convention:
h5_path: '/path/to/scan/series_name.h5'
primary_path: '/path/to/scan/series_name.model{model_id}.rootprimary.slp'
lateral_path: '/path/to/scan/series_name.model{model_id}.rootlateral.slp'
crown_path: '/path/to/scan/series_name.model{model_id}.rootcrown.slp'
Our pipeline outputs prediction files with this format:
/
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
h5_paths
|
List[str]
|
List of paths to .h5 files. |
required |
csv_path
|
Optional[str]
|
Optional path to the CSV file containing the expected plant count. |
None
|
Returns:
| Type | Description |
|---|---|
List[Series]
|
A list of Series loaded with the specified .h5 files. |
Source code in sleap_roots/series.py
load_series_from_slps ¶
load_series_from_slps(
slp_paths: List[str],
h5s: bool = False,
csv_path: Optional[str] = None,
) -> List[Series]
Load a list of Series from a list of .slp paths.
To load the Series, the files must be named with the following convention.
The slp_paths are expeted to have the series_name in the filename and "primary",
"lateral", or "crown" in the filename to differentiate the predictions.
h5_path: '/path/to/scan/series_name.h5'
Note that everything is expected to be in the same folder.
Our pipeline outputs prediction files with this format:
/
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slp_paths
|
List[str]
|
List of paths to .slp files. |
required |
h5s
|
bool
|
Boolean flag to indicate if the .h5 files are available. Default is False. |
False
|
csv_path
|
Optional[str]
|
Optional path to the CSV file containing the expected plant count. |
None
|
Source code in sleap_roots/series.py
imgfig ¶
Create a tight figure for image plotting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
size
|
Union[float, Tuple]
|
Scalar or 2-tuple specifying the (width, height) of the figure in inches. If scalar, will assume equal width and height. |
6
|
dpi
|
int
|
Dots per inch, controlling the resolution of the image. |
72
|
scale
|
float
|
Factor to scale the size of the figure by. This is a convenience for increasing the size of the plot at the same DPI. |
1.0
|
Returns:
| Type | Description |
|---|---|
Figure
|
A matplotlib.figure.Figure to use for plotting. |
Source code in sleap_roots/series.py
plot_img ¶
Plot an image in a tight figure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
ndarray
|
Image to plot. Can be a numpy array or a |
required |
dpi
|
int
|
Dots per inch, controlling the resolution of the image. |
72
|
scale
|
float
|
Factor to scale the size of the figure by. This is a convenience for increasing the size of the plot at the same DPI. |
1.0
|
Returns:
| Type | Description |
|---|---|
Figure
|
A matplotlib.figure.Figure containing the image. |
Source code in sleap_roots/series.py
plot_instance ¶
plot_instance(
instance,
skeleton=None,
cmap=None,
color_by_node=False,
lw=2,
ms=10,
bbox=None,
scale=1.0,
**kwargs
)
Plot a single instance with edge coloring.
Source code in sleap_roots/series.py
plot_instances ¶
plot_instances(
instances: List,
skeleton: Optional[Skeleton] = None,
cmap: Optional[List] = None,
color_by_track: bool = False,
tracks: Optional[List] = None,
**kwargs: Any
) -> List
Plot a list of instances with identity coloring.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instances
|
List
|
List of instances to plot. |
required |
skeleton
|
Optional[Skeleton]
|
Skeleton to use for edge coloring. If not provided, will use node coloring. |
None
|
cmap
|
Optional[List]
|
Color map to use for coloring. If not provided, will use the default seaborn tab10 color palette. |
None
|
color_by_track
|
bool
|
If True, will color instances by their track. If False, will color instances by their identity in the list. |
False
|
tracks
|
Optional[List]
|
List of tracks to use for coloring. If not provided, will infer tracks from the instances. |
None
|
**kwargs
|
Any
|
Additional keyword arguments to pass to |
{}
|
Returns:
| Type | Description |
|---|---|
List
|
A list of handles to the plotted lines. |
Source code in sleap_roots/series.py
validate_tracked_slp ¶
Validate that every instance in a .slp file has a non-empty track.
Used as an input precondition for TrackedTipPipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slp_path
|
Union[str, Path]
|
Path to the .slp file to validate. |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
When any instance has |
Source code in sleap_roots/series.py
validate_series_for_tracked_tip ¶
validate_series_for_tracked_tip(
series: Series, root_type: Optional[str] = None
) -> None
Validate a Series is loadable by TrackedTipPipeline.
Composite check: resolves root_type (auto-detect when None),
asserts the corresponding <root_type>_path is set and the loaded
skeleton has at least one node, then calls validate_tracked_slp on
the resolved path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
series
|
Series
|
The |
required |
root_type
|
Optional[str]
|
One of |
None
|
Returns:
| Type | Description |
|---|---|
None
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
When |