From 17c55eef1ce232736af99d7fe643f1e4d4ca5aca Mon Sep 17 00:00:00 2001 From: William Jones Date: Thu, 7 Dec 2023 01:25:59 +0000 Subject: [PATCH 1/2] Update build_distance_function to always provide integer values to calc_distance_coords_pbc, even if given None --- tobac/tracking.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tobac/tracking.py b/tobac/tracking.py index 6e2b8028..362ead05 100644 --- a/tobac/tracking.py +++ b/tobac/tracking.py @@ -643,9 +643,9 @@ def build_distance_function(min_h1, max_h1, min_h2, max_h2, PBC_flag): return functools.partial( pbc_utils.calc_distance_coords_pbc, - min_h1=min_h1, - max_h1=max_h1, - min_h2=min_h2, - max_h2=max_h2, + min_h1=min_h1 if min_h1 is not None else 0, + max_h1=max_h1 if max_h1 is not None else 0, + min_h2=min_h2 if min_h2 is not None else 0, + max_h2=max_h2 if max_h2 is not None else 0, PBC_flag=PBC_flag, ) From 17e12d27efd69a5e0e991dc6074a920c6bcefc1d Mon Sep 17 00:00:00 2001 From: William Jones Date: Thu, 7 Dec 2023 01:31:38 +0000 Subject: [PATCH 2/2] Add additional tests for build_distance_function with different PBC options --- tobac/tests/test_tracking.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tobac/tests/test_tracking.py b/tobac/tests/test_tracking.py index d21b1254..1266b210 100644 --- a/tobac/tests/test_tracking.py +++ b/tobac/tests/test_tracking.py @@ -285,6 +285,17 @@ def test_build_distance_function(): 1.4142135 ) + test_func = tobac.tracking.build_distance_function(0, 10, None, None, "hdim_1") + assert test_func(np.array((0, 9, 9)), np.array((0, 0, 9))) == pytest.approx(1) + + test_func = tobac.tracking.build_distance_function(None, None, 0, 10, "hdim_2") + assert test_func(np.array((0, 9, 9)), np.array((0, 9, 0))) == pytest.approx(1) + + test_func = tobac.tracking.build_distance_function(None, None, None, None, "none") + assert test_func(np.array((0, 9, 9)), np.array((0, 0, 0))) == pytest.approx( + (2 * 81) ** 0.5 + ) + @pytest.mark.parametrize( "point_init, speed, dxy, actual_dz, v_max, use_dz, features_connected",