Skip to content

Commit

Permalink
fix tests to load slp paths in Series
Browse files Browse the repository at this point in the history
  • Loading branch information
eberrigan committed May 12, 2024
1 parent c7df4c3 commit 13ae08d
Show file tree
Hide file tree
Showing 9 changed files with 294 additions and 80 deletions.
27 changes: 21 additions & 6 deletions tests/test_angle.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,16 @@ def test_get_vector_angle_from_gravity(vector, expected_angle):


# test get_node_ind function
def test_get_node_ind(canola_h5):
def test_get_node_ind(canola_h5, canola_primary_slp, canola_lateral_slp):
# Set the frame index to 0
frame_index = 0
# Load the series from the canola dataset
series = Series.load(canola_h5, primary_name="primary", lateral_name="lateral")
series = Series.load(
series_name="canola_test",
h5_path=canola_h5,
primary_path=canola_primary_slp,
lateral_path=canola_lateral_slp,
)
# Get the primary root points
primary_points = series.get_primary_points(frame_index)
# Set the proximal flag to True
Expand Down Expand Up @@ -204,11 +209,16 @@ def test_get_node_ind_5node_proximal(pts_nan32_5node):


# test canola get_root_angle function (base node to distal node angle)
def test_get_root_angle_distal(canola_h5):
def test_get_root_angle_distal(canola_h5, canola_primary_slp, canola_lateral_slp):
# Set the frame index to 0
frame_index = 0
# Load the series from the canola dataset
series = Series.load(canola_h5, primary_name="primary", lateral_name="lateral")
series = Series.load(
series_name="canola_test",
h5_path=canola_h5,
primary_path=canola_primary_slp,
lateral_path=canola_lateral_slp,
)
# Get the primary root points
primary_points = series.get_primary_points(frame_index)
# Set the proximal flag to False
Expand All @@ -221,11 +231,16 @@ def test_get_root_angle_distal(canola_h5):


# test rice get_root_angle function (base node to proximal node angle)
def test_get_root_angle_proximal_rice(rice_h5):
def test_get_root_angle_proximal_rice(rice_h5, rice_main_slp, rice_long_slp):
# Set the frame index to 0
frame_index = 0
# Load the series from the rice dataset
series = Series.load(rice_h5, primary_name="crown", lateral_name="primary")
series = Series.load(
series_name="rice_test",
h5_path=rice_h5,
primary_path=rice_long_slp,
crown_path=rice_main_slp,
)
# Get the primary root points
primary_points = series.get_primary_points(frame_index)
# Set the proximal flag to True
Expand Down
45 changes: 35 additions & 10 deletions tests/test_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,16 @@ def test_get_base_tip_dist_no_roots(pts_no_roots):


# test get_base_xs with canola
def test_get_base_xs_canola(canola_h5):
def test_get_base_xs_canola(canola_h5, canola_primary_slp, canola_lateral_slp):
# Set the frame idx to 0
frame_idx = 0
# Load a series from a canola dataset
plant = Series.load(canola_h5, primary_name="primary", lateral_name="lateral")
plant = Series.load(
series_name="canola_test",
h5_path=canola_h5,
primary_path=canola_primary_slp,
lateral_path=canola_lateral_slp,
)
# Get the labeled frame
lateral_points = plant.get_lateral_points(frame_idx)
# Get the lateral root bases
Expand Down Expand Up @@ -269,11 +274,16 @@ def test_get_base_ys_no_roots(pts_no_roots):


# test get_base_length with canola
def test_get_base_length_canola(canola_h5):
def test_get_base_length_canola(canola_h5, canola_primary_slp, canola_lateral_slp):
# Set the frame index to 0
frame_idx = 0
# Load a series from a canola dataset
plant = Series.load(canola_h5, primary_name="primary", lateral_name="lateral")
plant = Series.load(
series_name="canola_test",
h5_path=canola_h5,
primary_path=canola_primary_slp,
lateral_path=canola_lateral_slp,
)
# Get the lateral points
lateral_pts = plant.get_lateral_points(frame_idx)
# Get the bases of the lateral roots
Expand Down Expand Up @@ -309,11 +319,16 @@ def test_get_base_ct_density(primary_pts, lateral_pts):


# test get_base_ct_density function with canola example
def test_get_base_ct_density_canola(canola_h5):
def test_get_base_ct_density_canola(canola_h5, canola_primary_slp, canola_lateral_slp):
# Set the frame index to 0
frame_idx = 0
# Load a series from a canola dataset
series = Series.load(canola_h5, primary_name="primary", lateral_name="lateral")
series = Series.load(
series_name="canola_test",
h5_path=canola_h5,
primary_path=canola_primary_slp,
lateral_path=canola_lateral_slp,
)
# Get the primary and lateral points
primary_pts = series.get_primary_points(frame_idx)
lateral_pts = series.get_lateral_points(frame_idx)
Expand All @@ -328,11 +343,16 @@ def test_get_base_ct_density_canola(canola_h5):


# test get_base_length_ratio with canola
def test_get_base_length_ratio(canola_h5):
def test_get_base_length_ratio(canola_h5, canola_primary_slp, canola_lateral_slp):
# Set the frame index to 0
frame_idx = 0
# Load a series from a canola dataset
series = Series.load(canola_h5, primary_name="primary", lateral_name="lateral")
series = Series.load(
series_name="canola_test",
h5_path=canola_h5,
primary_path=canola_primary_slp,
lateral_path=canola_lateral_slp,
)
# Get the primary and lateral points
primary_pts = series.get_primary_points(frame_idx)
lateral_pts = series.get_lateral_points(frame_idx)
Expand All @@ -350,11 +370,16 @@ def test_get_base_length_ratio(canola_h5):
np.testing.assert_almost_equal(base_length_ratio, 0.086, decimal=3)


def test_root_width_canola(canola_h5):
def test_root_width_canola(canola_h5, canola_primary_slp, canola_lateral_slp):
# Set the frame index to 0
frame_idx = 0
# Load a series from a canola dataset
series = Series.load(canola_h5, primary_name="primary", lateral_name="lateral")
series = Series.load(
series_name="canola_test",
h5_path=canola_h5,
primary_path=canola_primary_slp,
lateral_path=canola_lateral_slp,
)
# Get the primary points
primary_pts = series.get_primary_points(frame_idx)
# Get the primary points with the maximum length
Expand Down
42 changes: 32 additions & 10 deletions tests/test_convhull.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,16 @@ def lateral_pts():


# test get_convhull function using canola
def test_get_convhull_canola(canola_h5):
def test_get_convhull_canola(canola_h5, canola_primary_slp, canola_lateral_slp):
# Set frame index to 0
frame_index = 0
# Load the series from the canola dataset
series = Series.load(canola_h5, primary_name="primary", lateral_name="lateral")
series = Series.load(
series_name="canola_test",
h5_path=canola_h5,
primary_path=canola_primary_slp,
lateral_path=canola_lateral_slp,
)
# Get the primary and lateral root from the series
primary_pts = series.get_primary_points(frame_index)
lateral_pts = series.get_lateral_points(frame_index)
Expand All @@ -137,12 +142,19 @@ def test_get_convhull_canola(canola_h5):
assert type(convex_hull) == ConvexHull


# test canola model
def test_get_convhull_features_canola(canola_h5):
# test canola convex hull features
def test_get_convhull_features_canola(
canola_h5, canola_primary_slp, canola_lateral_slp
):
# Set the frame index to 0
frame_index = 0
# Load the series from the canola dataset
series = Series.load(canola_h5, primary_name="primary", lateral_name="lateral")
series = Series.load(
series_name="canola_test",
h5_path=canola_h5,
primary_path=canola_primary_slp,
lateral_path=canola_lateral_slp,
)
# Get the primary and lateral root from the series
primary_pts = series.get_primary_points(frame_index)
lateral_pts = series.get_lateral_points(frame_index)
Expand All @@ -163,12 +175,17 @@ def test_get_convhull_features_canola(canola_h5):
np.testing.assert_almost_equal(max_height, 876.5622253417969, decimal=3)


# test rice model
def test_get_convhull_features_rice(rice_h5):
# test rice convex hull features
def test_get_convhull_features_rice(rice_h5, rice_long_slp, rice_main_slp):
# Set the frame index to 0
frame_index = 0
# Load the series from the rice dataset
series = Series.load(rice_h5, primary_name="primary", crown_name="crown")
series = Series.load(
series_name="rice_test",
h5_path=rice_h5,
primary_path=rice_long_slp,
crown_path=rice_main_slp,
)
# Get the crown root from the series
crown_pts = series.get_crown_points(frame_index)
# Get the convex hull from the points
Expand Down Expand Up @@ -221,11 +238,16 @@ def test_get_chull_perimeter(lateral_pts):


# test get_chull_line_lengths with canola
def test_get_chull_line_lengths(canola_h5):
def test_get_chull_line_lengths(canola_h5, canola_primary_slp, canola_lateral_slp):
# Set the frame index to 0
frame_index = 0
# Load the series from the canola dataset
series = Series.load(canola_h5, primary_name="primary", lateral_name="lateral")
series = Series.load(
series_name="canola_test",
h5_path=canola_h5,
primary_path=canola_primary_slp,
lateral_path=canola_lateral_slp,
)
# Get the primary and lateral root from the series
primary_pts = series.get_primary_points(frame_index)
lateral_pts = series.get_lateral_points(frame_index)
Expand Down
34 changes: 30 additions & 4 deletions tests/test_ellipse.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,24 @@
from typing import Literal


def test_get_ellipse(canola_h5: Literal["tests/data/canola_7do/919QDUH.h5"]):
def test_get_ellipse(
canola_h5: Literal["tests/data/canola_7do/919QDUH.h5"],
canola_primary_slp: Literal[
"tests/data/canola_7do/919QDUH.primary.predictions.slp"
],
canola_lateral_slp: Literal[
"tests/data/canola_7do/919QDUH.lateral.predictions.slp"
],
):
# Set the frame index = 0
frame_index = 0
# Load the canola dataset
series = Series.load(canola_h5, primary_name="primary", lateral_name="lateral")
series = Series.load(
series_name="canola_test",
h5_path=canola_h5,
primary_path=canola_primary_slp,
lateral_path=canola_lateral_slp,
)
primary_pts = series.get_primary_points(frame_index)
# only test ellipse for primary root points
a, b, ratio = fit_ellipse(primary_pts)
Expand All @@ -34,11 +47,24 @@ def test_get_ellipse(canola_h5: Literal["tests/data/canola_7do/919QDUH.h5"]):
assert np.isnan(ratio)


def test_get_ellipse_all_points(canola_h5: Literal["tests/data/canola_7do/919QDUH.h5"]):
def test_get_ellipse_all_points(
canola_h5: Literal["tests/data/canola_7do/919QDUH.h5"],
canola_primary_slp: Literal[
"tests/data/canola_7do/919QDUH.primary.predictions.slp"
],
canola_lateral_slp: Literal[
"tests/data/canola_7do/919QDUH.lateral.predictions.slp"
],
):
# Set the frame index = 0
frame_index = 0
# Load the canola dataset
series = Series.load(canola_h5, primary_name="primary", lateral_name="lateral")
series = Series.load(
series_name="canola_test",
h5_path=canola_h5,
primary_path=canola_primary_slp,
lateral_path=canola_lateral_slp,
)
primary_pts = series.get_primary_points(frame_index)
primary_max_length_pts = get_max_length_pts(primary_pts)
lateral_pts = series.get_lateral_points(frame_index)
Expand Down
27 changes: 21 additions & 6 deletions tests/test_lengths.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,16 @@ def test_min_distance_line_to_line():


# tests for get_curve_index function
def test_get_curve_index_canola(canola_h5):
def test_get_curve_index_canola(canola_h5, canola_primary_slp, canola_lateral_slp):
# Set the frame index to 0
frame_idx = 0
# Load the series from the canola dataset
series = Series.load(canola_h5, primary_name="primary", lateral_name="lateral")
series = Series.load(
series_name="canola_test",
h5_path=canola_h5,
primary_path=canola_primary_slp,
lateral_path=canola_lateral_slp,
)
# Get the primary points from the first frame
primary_pts = series.get_primary_points(frame_idx)
# Get the points from the root with maximum length
Expand Down Expand Up @@ -310,11 +315,16 @@ def test_curve_index_mixed_invalid():
)


def test_get_root_lengths(canola_h5):
def test_get_root_lengths(canola_h5, canola_primary_slp, canola_lateral_slp):
# Set the frame index to 0
frame_idx = 0
# Load the series from the canola dataset
series = Series.load(canola_h5, primary_name="primary", lateral_name="lateral")
series = Series.load(
series_name="canola_test",
h5_path=canola_h5,
primary_path=canola_primary_slp,
lateral_path=canola_lateral_slp,
)
# Get the primary points from the first frame
primary_pts = series.get_primary_points(frame_idx)
assert primary_pts.shape == (1, 6, 2)
Expand Down Expand Up @@ -347,11 +357,16 @@ def test_get_root_lengths_one_point(pts_one_base):
)


def test_get_max_length_pts(canola_h5):
def test_get_max_length_pts(canola_h5, canola_primary_slp, canola_lateral_slp):
# Set the frame index to 0
frame_idx = 0
# Load the series from the canola dataset
series = Series.load(canola_h5, primary_name="primary", lateral_name="lateral")
series = Series.load(
series_name="canola_test",
h5_path=canola_h5,
primary_path=canola_primary_slp,
lateral_path=canola_lateral_slp,
)
# Get the primary points from the first frame
primary_pts = series.get_primary_points(frame_idx)
# Get the points from the root with maximum length
Expand Down
Loading

0 comments on commit 13ae08d

Please sign in to comment.