Repository: tobac-project/tobac

Issue:
Raise error if no search range parameter is specified
We should raise a specific error if neither `v_max`, `d_max` nor `d_min` is provided in `linking_trackpy`.

Discussion:

Patch:
diff --git a/tobac/tracking.py b/tobac/tracking.py
index 5c14647..e4a3985 100644
--- a/tobac/tracking.py
+++ b/tobac/tracking.py
@@ -178,6 +178,11 @@ def linking_trackpy(
     #    from trackpy import filter_stubs
     #    from .utils import add_coordinates
 
+    if (v_max is None) and (d_min is None) and (d_max is None):
+        raise ValueError(
+            "Neither d_max nor v_max has been provided. Either one of these arguments must be specified."
+        )
+
     # calculate search range based on timestep and grid spacing
     if v_max is not None:
         search_range = int(dt * v_max / dxy)


Test patch:
diff --git a/tobac/tests/test_tracking.py b/tobac/tests/test_tracking.py
index 6494c03..64d3e40 100644
--- a/tobac/tests/test_tracking.py
+++ b/tobac/tests/test_tracking.py
@@ -164,3 +164,26 @@ def test_tracking_extrapolation():
         output = tobac.linking_trackpy(
             cell_1, None, 1, 1, d_max=100, method_linking="predict", extrapolate=1
         )
+
+
+def test_argument_logic():
+    """Tests whether missing arguments are handled correctly,
+    i.e. whether a ValueError is raised if neither d_min, d_max nor v_max have
+    been provided to tobac.linking_trackpy.
+    """
+    cell_1 = tobac.testing.generate_single_feature(
+        1,
+        1,
+        min_h1=0,
+        max_h1=100,
+        min_h2=0,
+        max_h2=100,
+        frame_start=0,
+        num_frames=5,
+        spd_h1=20,
+        spd_h2=20,
+    )
+    with pytest.raises(ValueError):
+        output = tobac.linking_trackpy(
+            cell_1, None, 1, 1, d_min=None, d_max=None, v_max=None
+        )