From a3dfbfb5cc7b9e3373775791465b3137b9647e03 Mon Sep 17 00:00:00 2001 From: Cyuber Date: Wed, 9 Oct 2024 11:26:54 -0400 Subject: [PATCH 1/3] remade branch for commits for ObjectInWorld label parameter implementation --- .../cluster_estimation/cluster_estimation.py | 5 +- modules/object_in_world.py | 7 +- tests/unit/test_decision.py | 14 ++-- tests/unit/test_landing_pad_tracking.py | 72 +++++++++---------- 4 files changed, 53 insertions(+), 45 deletions(-) diff --git a/modules/cluster_estimation/cluster_estimation.py b/modules/cluster_estimation/cluster_estimation.py index 31675f47..8184aa54 100644 --- a/modules/cluster_estimation/cluster_estimation.py +++ b/modules/cluster_estimation/cluster_estimation.py @@ -193,14 +193,15 @@ def run( # Create output list of remaining valid clusters detections_in_world = [] for cluster in model_output: - result, landing_pad = object_in_world.ObjectInWorld.create( + result, temp_object = object_in_world.ObjectInWorld.create( cluster[0][0], cluster[0][1], cluster[2], + 0, ) if result: - detections_in_world.append(landing_pad) + detections_in_world.append(temp_object) return True, detections_in_world diff --git a/modules/object_in_world.py b/modules/object_in_world.py index 1ce9f65e..a2bb0b48 100644 --- a/modules/object_in_world.py +++ b/modules/object_in_world.py @@ -12,16 +12,17 @@ class ObjectInWorld: @classmethod def create( - cls, location_x: float, location_y: float, spherical_variance: float + cls, location_x: float, location_y: float, spherical_variance: float, label: int ) -> "tuple[bool, ObjectInWorld | None]": """ location_x, location_y: Location of the object. spherical_variance: Uncertainty of the location. + label: Type of object in real world. """ if spherical_variance < 0.0: return False, None - return True, ObjectInWorld(cls.__create_key, location_x, location_y, spherical_variance) + return True, ObjectInWorld(cls.__create_key, location_x, location_y, spherical_variance, label) def __init__( self, @@ -29,6 +30,7 @@ def __init__( location_x: float, location_y: float, spherical_variance: float, + label: int, ) -> None: """ Private constructor, use create() method. @@ -38,3 +40,4 @@ def __init__( self.location_x = location_x self.location_y = location_y self.spherical_variance = spherical_variance + self.label = label diff --git a/tests/unit/test_decision.py b/tests/unit/test_decision.py index 9b24211b..0c2d8da3 100644 --- a/tests/unit/test_decision.py +++ b/tests/unit/test_decision.py @@ -41,7 +41,9 @@ def best_pad_within_tolerance() -> object_in_world.ObjectInWorld: # type: ignor location_x = BEST_PAD_LOCATION_X location_y = BEST_PAD_LOCATION_Y spherical_variance = 1.0 - result, pad = object_in_world.ObjectInWorld.create(location_x, location_y, spherical_variance) + result, pad = object_in_world.ObjectInWorld.create( + location_x, location_y, spherical_variance, 0 + ) assert result assert pad is not None @@ -56,7 +58,9 @@ def best_pad_outside_tolerance() -> object_in_world.ObjectInWorld: # type: igno location_x = 100.0 location_y = 200.0 spherical_variance = 5.0 # variance outside tolerance - result, pad = object_in_world.ObjectInWorld.create(location_x, location_y, spherical_variance) + result, pad = object_in_world.ObjectInWorld.create( + location_x, location_y, spherical_variance, 0 + ) assert result assert pad is not None @@ -68,15 +72,15 @@ def pads() -> "list[object_in_world.ObjectInWorld]": # type: ignore """ Create a list of ObjectInWorld instances for the landing pads. """ - result, pad_1 = object_in_world.ObjectInWorld.create(30.0, 40.0, 2.0) + result, pad_1 = object_in_world.ObjectInWorld.create(30.0, 40.0, 2.0, 0) assert result assert pad_1 is not None - result, pad_2 = object_in_world.ObjectInWorld.create(50.0, 60.0, 3.0) + result, pad_2 = object_in_world.ObjectInWorld.create(50.0, 60.0, 3.0, 0) assert result assert pad_2 is not None - result, pad_3 = object_in_world.ObjectInWorld.create(70.0, 80.0, 4.0) + result, pad_3 = object_in_world.ObjectInWorld.create(70.0, 80.0, 4.0, 0) assert result assert pad_3 is not None diff --git a/tests/unit/test_landing_pad_tracking.py b/tests/unit/test_landing_pad_tracking.py index 51bfc3f7..2105c84a 100644 --- a/tests/unit/test_landing_pad_tracking.py +++ b/tests/unit/test_landing_pad_tracking.py @@ -30,23 +30,23 @@ def detections_1() -> "list[object_in_world.ObjectInWorld]": # type: ignore """ Sample instances of ObjectInWorld for testing. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 8) + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 8, 0) assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(2, 2, 4) + result, obj_2 = object_in_world.ObjectInWorld.create(2, 2, 4, 0) assert result assert obj_2 is not None - result, obj_3 = object_in_world.ObjectInWorld.create(-2, -2, 2) + result, obj_3 = object_in_world.ObjectInWorld.create(-2, -2, 2, 0) assert result assert obj_3 is not None - result, obj_4 = object_in_world.ObjectInWorld.create(3, 3, 10) + result, obj_4 = object_in_world.ObjectInWorld.create(3, 3, 10, 0) assert result assert obj_4 is not None - result, obj_5 = object_in_world.ObjectInWorld.create(-3, -3, 6) + result, obj_5 = object_in_world.ObjectInWorld.create(-3, -3, 6, 0) assert result assert obj_5 is not None @@ -59,23 +59,23 @@ def detections_2() -> "list[object_in_world.ObjectInWorld]": # type: ignore """ Sample instances of ObjectInWorld for testing. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0.5, 0.5, 1) + result, obj_1 = object_in_world.ObjectInWorld.create(0.5, 0.5, 1, 0) assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(1.5, 1.5, 3) + result, obj_2 = object_in_world.ObjectInWorld.create(1.5, 1.5, 3, 0) assert result assert obj_2 is not None - result, obj_3 = object_in_world.ObjectInWorld.create(4, 4, 7) + result, obj_3 = object_in_world.ObjectInWorld.create(4, 4, 7, 0) assert result assert obj_3 is not None - result, obj_4 = object_in_world.ObjectInWorld.create(-4, -4, 5) + result, obj_4 = object_in_world.ObjectInWorld.create(-4, -4, 5, 0) assert result assert obj_4 is not None - result, obj_5 = object_in_world.ObjectInWorld.create(5, 5, 9) + result, obj_5 = object_in_world.ObjectInWorld.create(5, 5, 9, 0) assert result assert obj_5 is not None @@ -88,23 +88,23 @@ def detections_3() -> "list[object_in_world.ObjectInWorld]": # type: ignore """ Sample instances of ObjectInWorld for testing. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 8) + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 8, 0) assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(0.5, 0.5, 4) + result, obj_2 = object_in_world.ObjectInWorld.create(0.5, 0.5, 4, 0) assert result assert obj_2 is not None - result, obj_3 = object_in_world.ObjectInWorld.create(-2, -2, 2) + result, obj_3 = object_in_world.ObjectInWorld.create(-2, -2, 2, 0) assert result assert obj_3 is not None - result, obj_4 = object_in_world.ObjectInWorld.create(3, 3, 10) + result, obj_4 = object_in_world.ObjectInWorld.create(3, 3, 10, 0) assert result assert obj_4 is not None - result, obj_5 = object_in_world.ObjectInWorld.create(-3, -3, 6) + result, obj_5 = object_in_world.ObjectInWorld.create(-3, -3, 6, 0) assert result assert obj_5 is not None @@ -123,11 +123,11 @@ def test_is_similar_positive_equal_to_threshold(self) -> None: Test case where the second landing pad has positive coordinates and the distance between them is equal to the distance threshold. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0) + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0, 0) assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(1, 1, 0) + result, obj_2 = object_in_world.ObjectInWorld.create(1, 1, 0, 0) assert result assert obj_2 is not None @@ -145,11 +145,11 @@ def test_is_similar_negative_equal_to_threshold(self) -> None: Test case where the second landing pad has negative coordinates and the distance between them is equal to the distance threshold. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0) + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0, 0) assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(-1, -1, 0) + result, obj_2 = object_in_world.ObjectInWorld.create(-1, -1, 0, 0) assert result assert obj_2 is not None @@ -168,11 +168,11 @@ def test_is_similar_positive_less_than_threshold(self) -> None: Test case where the second landing pad has positive coordinates and the distance between them is less than the distance threshold. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0) + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0, 0) assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(0.5, 0.5, 0) + result, obj_2 = object_in_world.ObjectInWorld.create(0.5, 0.5, 0, 0) assert result assert obj_2 is not None @@ -191,11 +191,11 @@ def test_is_similar_negative_less_than_threshold(self) -> None: Test case where the second landing pad has negative coordinates and the distance between them is less than the distance threshold. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0) + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0, 0) assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(-0.5, -0.5, 0) + result, obj_2 = object_in_world.ObjectInWorld.create(-0.5, -0.5, 0, 0) assert result assert obj_2 is not None @@ -214,11 +214,11 @@ def test_is_similar_positive_more_than_threshold(self) -> None: Test case where the second landing pad has positive coordinates and the distance between them is more than the distance threshold. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0) + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0, 0) assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(2, 2, 0) + result, obj_2 = object_in_world.ObjectInWorld.create(2, 2, 0, 0) assert result assert obj_2 is not None @@ -237,11 +237,11 @@ def test_is_similar_negative_more_than_threshold(self) -> None: Test case where the second landing pad has negative coordinates and the distance between them is more than the distance threshold. """ - result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0) + result, obj_1 = object_in_world.ObjectInWorld.create(0, 0, 0, 0) assert result assert obj_1 is not None - result, obj_2 = object_in_world.ObjectInWorld.create(-2, -2, 0) + result, obj_2 = object_in_world.ObjectInWorld.create(-2, -2, 0, 0) assert result assert obj_2 is not None @@ -269,7 +269,7 @@ def test_mark_false_positive_no_similar( """ Test if marking false positive adds detection to list of false positives. """ - _, false_positive = object_in_world.ObjectInWorld.create(20, 20, 20) + _, false_positive = object_in_world.ObjectInWorld.create(20, 20, 20, 0) assert false_positive is not None tracker._LandingPadTracking__unconfirmed_positives = detections_1 # type: ignore @@ -296,7 +296,7 @@ def test_mark_false_positive_with_similar( Test if marking false positive adds detection to list of false positives and removes. similar landing pads """ - _, false_positive = object_in_world.ObjectInWorld.create(1, 1, 1) + _, false_positive = object_in_world.ObjectInWorld.create(1, 1, 1, 0) assert false_positive is not None tracker._LandingPadTracking__unconfirmed_positives = detections_2 # type: ignore @@ -316,10 +316,10 @@ def test_mark_multiple_false_positive( """ Test if marking false positive adds detection to list of false positives. """ - _, false_positive_1 = object_in_world.ObjectInWorld.create(0, 0, 1) + _, false_positive_1 = object_in_world.ObjectInWorld.create(0, 0, 1, 0) assert false_positive_1 is not None - _, false_positive_2 = object_in_world.ObjectInWorld.create(2, 2, 1) + _, false_positive_2 = object_in_world.ObjectInWorld.create(2, 2, 1, 0) assert false_positive_2 is not None tracker._LandingPadTracking__unconfirmed_positives = detections_1 # type: ignore @@ -344,7 +344,7 @@ def test_mark_confirmed_positive( """ Test if marking confirmed positive adds detection to list of confirmed positives. """ - _, confirmed_positive = object_in_world.ObjectInWorld.create(1, 1, 1) + _, confirmed_positive = object_in_world.ObjectInWorld.create(1, 1, 1, 0) assert confirmed_positive is not None expected = [confirmed_positive] @@ -359,10 +359,10 @@ def test_mark_multiple_confirmed_positives( """ Test if marking confirmed positive adds detection to list of confirmed positives. """ - _, confirmed_positive_1 = object_in_world.ObjectInWorld.create(1, 1, 1) + _, confirmed_positive_1 = object_in_world.ObjectInWorld.create(1, 1, 1, 0) assert confirmed_positive_1 is not None - _, confirmed_positive_2 = object_in_world.ObjectInWorld.create(2, 2, 1) + _, confirmed_positive_2 = object_in_world.ObjectInWorld.create(2, 2, 1, 0) assert confirmed_positive_2 is not None expected = [confirmed_positive_1, confirmed_positive_2] @@ -469,7 +469,7 @@ def test_run_with_confirmed_positive( """ Test run when there is a confirmed positive. """ - _, confirmed_positive = object_in_world.ObjectInWorld.create(1, 1, 1) + _, confirmed_positive = object_in_world.ObjectInWorld.create(1, 1, 1, 0) assert confirmed_positive is not None tracker._LandingPadTracking__confirmed_positives.append(confirmed_positive) # type: ignore @@ -488,7 +488,7 @@ def test_run_with_false_positive( """ Test to see if run function doesn't add landing pads that are similar to false positives. """ - _, false_positive = object_in_world.ObjectInWorld.create(1, 1, 1) + _, false_positive = object_in_world.ObjectInWorld.create(1, 1, 1, 0) assert false_positive is not None tracker._LandingPadTracking__false_positives.append(false_positive) # type: ignore From 758368854b1a77d68a61110866605a0237864550 Mon Sep 17 00:00:00 2001 From: Aleksa-M Date: Wed, 9 Oct 2024 12:23:50 -0400 Subject: [PATCH 2/3] fixed formatting --- modules/object_in_world.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/object_in_world.py b/modules/object_in_world.py index a2bb0b48..f1d183e0 100644 --- a/modules/object_in_world.py +++ b/modules/object_in_world.py @@ -22,7 +22,9 @@ def create( if spherical_variance < 0.0: return False, None - return True, ObjectInWorld(cls.__create_key, location_x, location_y, spherical_variance, label) + return True, ObjectInWorld( + cls.__create_key, location_x, location_y, spherical_variance, label + ) def __init__( self, From f188bdac461e2e68b4c58d730ab64544c620e517 Mon Sep 17 00:00:00 2001 From: Cyuber Date: Thu, 10 Oct 2024 23:45:13 -0400 Subject: [PATCH 3/3] changed temp_object to cluster_object --- modules/cluster_estimation/cluster_estimation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/cluster_estimation/cluster_estimation.py b/modules/cluster_estimation/cluster_estimation.py index 8184aa54..c2edc9c7 100644 --- a/modules/cluster_estimation/cluster_estimation.py +++ b/modules/cluster_estimation/cluster_estimation.py @@ -193,7 +193,7 @@ def run( # Create output list of remaining valid clusters detections_in_world = [] for cluster in model_output: - result, temp_object = object_in_world.ObjectInWorld.create( + result, cluster_object = object_in_world.ObjectInWorld.create( cluster[0][0], cluster[0][1], cluster[2], @@ -201,7 +201,7 @@ def run( ) if result: - detections_in_world.append(temp_object) + detections_in_world.append(cluster_object) return True, detections_in_world