From 24945931fd6ab23cb18e2ba9bb6de9b09368d14c Mon Sep 17 00:00:00 2001 From: Jeremy Kubica <104161096+jeremykubica@users.noreply.github.com> Date: Wed, 18 Dec 2024 14:59:24 -0500 Subject: [PATCH] Rename function as suggested in PR review --- src/kbmod/trajectory_utils.py | 4 ++-- tests/test_trajectory_utils.py | 26 +++++++++++++------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/kbmod/trajectory_utils.py b/src/kbmod/trajectory_utils.py index 087ef0d2..3b0265fc 100644 --- a/src/kbmod/trajectory_utils.py +++ b/src/kbmod/trajectory_utils.py @@ -266,7 +266,7 @@ def evaluate_trajectory_mse(trj, x_vals, y_vals, zeroed_times, centered=True): return np.mean(sq_err) -def ave_trajectory_distance(trjA, trjB, times=[0.0]): +def avg_trajectory_distance(trjA, trjB, times=[0.0]): """Evaluate the average distance between two trajectories (in pixels) across different times. @@ -347,7 +347,7 @@ def match_trajectory_sets(traj_query, traj_base, threshold, times=[0.0]): dists = np.zeros((num_query, num_base)) for q_idx in range(num_query): for b_idx in range(num_base): - dists[q_idx][b_idx] = ave_trajectory_distance(traj_query[q_idx], traj_base[b_idx], times) + dists[q_idx][b_idx] = avg_trajectory_distance(traj_query[q_idx], traj_base[b_idx], times) # Use scipy to solve the optimal bipartite matching problem. row_inds, col_inds = linear_sum_assignment(dists) diff --git a/tests/test_trajectory_utils.py b/tests/test_trajectory_utils.py index 03753750..2b209a5c 100644 --- a/tests/test_trajectory_utils.py +++ b/tests/test_trajectory_utils.py @@ -156,34 +156,34 @@ def test_evaluate_trajectory_mse(self): self.assertRaises(ValueError, evaluate_trajectory_mse, trj, [], [], []) - def test_ave_trajectory_distance(self): + def test_avg_trajectory_distance(self): times_0 = np.array([0.0]) times_1 = np.array([0.0, 1.0]) times_5 = np.array([0.0, 1.0, 2.0, 3.0, 4.0]) # A trajectory is always zero pixels from itself. trjA = Trajectory(x=1, y=2, vx=1.0, vy=-1.0) - self.assertAlmostEqual(ave_trajectory_distance(trjA, trjA, times_0), 0.0) - self.assertAlmostEqual(ave_trajectory_distance(trjA, trjA, times_1), 0.0) - self.assertAlmostEqual(ave_trajectory_distance(trjA, trjA, times_5), 0.0) + self.assertAlmostEqual(avg_trajectory_distance(trjA, trjA, times_0), 0.0) + self.assertAlmostEqual(avg_trajectory_distance(trjA, trjA, times_1), 0.0) + self.assertAlmostEqual(avg_trajectory_distance(trjA, trjA, times_5), 0.0) # Create a trajectory with a constant 1 pixel offset in the y direction. trjB = Trajectory(x=1, y=1, vx=1.0, vy=-1.0) - self.assertAlmostEqual(ave_trajectory_distance(trjA, trjB, times_0), 1.0) - self.assertAlmostEqual(ave_trajectory_distance(trjA, trjB, times_1), 1.0) - self.assertAlmostEqual(ave_trajectory_distance(trjA, trjB, times_5), 1.0) + self.assertAlmostEqual(avg_trajectory_distance(trjA, trjB, times_0), 1.0) + self.assertAlmostEqual(avg_trajectory_distance(trjA, trjB, times_1), 1.0) + self.assertAlmostEqual(avg_trajectory_distance(trjA, trjB, times_5), 1.0) # Create a trajectory with an increasing offset in the x direction. trjC = Trajectory(x=1, y=2, vx=2.0, vy=-1.0) - self.assertAlmostEqual(ave_trajectory_distance(trjA, trjC, times_0), 0.0) - self.assertAlmostEqual(ave_trajectory_distance(trjA, trjC, times_1), 0.5) - self.assertAlmostEqual(ave_trajectory_distance(trjA, trjC, times_5), 2.0) + self.assertAlmostEqual(avg_trajectory_distance(trjA, trjC, times_0), 0.0) + self.assertAlmostEqual(avg_trajectory_distance(trjA, trjC, times_1), 0.5) + self.assertAlmostEqual(avg_trajectory_distance(trjA, trjC, times_5), 2.0) # Create a trajectory with an increasing offset in the y direction. trjC = Trajectory(x=1, y=2, vx=1.0, vy=1.0) - self.assertAlmostEqual(ave_trajectory_distance(trjA, trjC, times_0), 0.0) - self.assertAlmostEqual(ave_trajectory_distance(trjA, trjC, times_1), 1.0) - self.assertAlmostEqual(ave_trajectory_distance(trjA, trjC, times_5), 4.0) + self.assertAlmostEqual(avg_trajectory_distance(trjA, trjC, times_0), 0.0) + self.assertAlmostEqual(avg_trajectory_distance(trjA, trjC, times_1), 1.0) + self.assertAlmostEqual(avg_trajectory_distance(trjA, trjC, times_5), 4.0) # A list of empty times is invalid. with self.assertRaises(ValueError):