Skip to content
This repository was archived by the owner on Nov 13, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion modules/cluster_estimation/cluster_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from .. import object_in_world
from .. import detection_in_world
from ..common.modules.logger import logger


class ClusterEstimation:
Expand Down Expand Up @@ -70,7 +71,11 @@ class ClusterEstimation:

@classmethod
def create(
cls, min_activation_threshold: int, min_new_points_to_run: int, random_state: int
cls,
min_activation_threshold: int,
min_new_points_to_run: int,
random_state: int,
local_logger: logger.Logger,
) -> "tuple[bool, ClusterEstimation | None]":
"""
Data requirement conditions for estimation model to run.
Expand All @@ -88,6 +93,7 @@ def create(
min_activation_threshold,
min_new_points_to_run,
random_state,
local_logger,
)

def __init__(
Expand All @@ -96,6 +102,7 @@ def __init__(
min_activation_threshold: int,
min_new_points_to_run: int,
random_state: int,
local_logger: logger.Logger,
) -> None:
"""
Private constructor, use create() method.
Expand All @@ -121,6 +128,7 @@ def __init__(
self.__min_activation_threshold = min_activation_threshold
self.__min_new_points_to_run = min_new_points_to_run
self.__has_ran_once = False
self.__logger = local_logger

def run(
self, detections: "list[detection_in_world.DetectionInWorld]", run_override: bool
Expand Down Expand Up @@ -160,6 +168,7 @@ def run(

# Check convergence
if not self.__vgmm.converged_:
self.__logger.warning("Model failed to converge")
return False, None

# Get predictions from cluster model
Expand Down Expand Up @@ -201,7 +210,10 @@ def run(

if result:
detections_in_world.append(landing_pad)
else:
self.__logger.warning("Failed to create ObjectInWorld object")

self.__logger.info(detections_in_world)
return True, detections_in_world

def __decide_to_run(self, run_override: bool) -> bool:
Expand Down
18 changes: 17 additions & 1 deletion modules/cluster_estimation/cluster_estimation_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
Gets detections in world space and outputs estimations of objects.
"""

import os
import pathlib

from utilities.workers import queue_proxy_wrapper
from utilities.workers import worker_controller
from . import cluster_estimation
from ..common.modules.logger import logger


def cluster_estimation_worker(
Expand Down Expand Up @@ -38,13 +42,25 @@ def cluster_estimation_worker(
worker_controller: worker_controller.WorkerController
How the main process communicates to this worker process.
"""
worker_name = pathlib.Path(__file__).stem
process_id = os.getpid()
result, local_logger = logger.Logger.create(f"{worker_name}_{process_id}", True)
if not result:
print("ERROR: Worker failed to create logger")
return

assert local_logger is not None

local_logger.info("Logger initialized")

result, estimator = cluster_estimation.ClusterEstimation.create(
min_activation_threshold,
min_new_points_to_run,
random_state,
local_logger,
)
if not result:
print("ERROR: Worker failed to create class object")
local_logger.error("Worker failed to create class object", True)
return

# Get Pylance to stop complaining
Expand Down
12 changes: 12 additions & 0 deletions modules/object_in_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,15 @@ def __init__(
self.location_x = location_x
self.location_y = location_y
self.spherical_variance = spherical_variance

def __str__(self) -> str:
"""
To string.
"""
return f"{self.__class__}, location_x: {self.location_x}, location_y: {self.location_y}, spherical_variance: {self.spherical_variance}"

def __repr__(self) -> str:
"""
For collections (e.g. list).
"""
return str(self)
6 changes: 6 additions & 0 deletions tests/unit/test_cluster_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sklearn.datasets

from modules.cluster_estimation import cluster_estimation
from modules.common.modules.logger import logger
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move between line 9 and 10 . This is to make imports in alphabetical order.

from modules import detection_in_world


Expand All @@ -26,10 +27,15 @@ def cluster_model() -> cluster_estimation.ClusterEstimation: # type: ignore
"""
Cluster estimation object.
"""
result, test_logger = logger.Logger.create("test_logger", False)
assert result
assert test_logger is not None

result, model = cluster_estimation.ClusterEstimation.create(
MIN_TOTAL_POINTS_THRESHOLD,
MIN_NEW_POINTS_TO_RUN,
RNG_SEED,
test_logger,
)
assert result
assert model is not None
Expand Down