Skip to content

Commit

Permalink
Rename function as suggested in PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremykubica committed Dec 18, 2024
1 parent 4898df1 commit 2494593
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/kbmod/trajectory_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
26 changes: 13 additions & 13 deletions tests/test_trajectory_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 2494593

Please sign in to comment.