Skip to content

Commit

Permalink
editing tests, plant provider and plant
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasBaecker committed Sep 3, 2024
1 parent b0fbb08 commit e352134
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
1 change: 0 additions & 1 deletion field_friend/automations/plant.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import uuid
from collections import deque
from dataclasses import dataclass, field
from typing import Optional
Expand Down
14 changes: 7 additions & 7 deletions field_friend/automations/plant_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import rosys
from nicegui import ui
from rosys.geometry import Point
from rosys.geometry import Point3d

from .plant import Plant

Expand Down Expand Up @@ -129,18 +129,18 @@ def _add_crop_prediction(self, plant: Plant) -> None:
crop_1 = sorted_crops[0]
crop_2 = sorted_crops[1]

yaw = crop_2.position.direction(crop_1.position)
prediction = crop_1.position.polar(self.crop_spacing, yaw)
yaw = crop_2.position.projection().direction(crop_1.position.projection())
prediction = crop_1.position.projection().polar(self.crop_spacing, yaw)

if plant.position.distance(prediction) > self.match_distance:
if plant.position.projection().distance(prediction) > self.match_distance:
return
plant.positions.append(prediction)
plant.positions.append(Point3d.from_point(prediction, 0))
plant.confidences.append(self.prediction_confidence)

def get_relevant_crops(self, point: Point, *, max_distance=0.5) -> list[Plant]:
def get_relevant_crops(self, point: Point3d, *, max_distance=0.5) -> list[Plant]:
return [c for c in self.crops if c.position.distance(point) <= max_distance and c.confidence >= self.minimum_combined_crop_confidence]

def get_relevant_weeds(self, point: Point, *, max_distance=0.5) -> list[Plant]:
def get_relevant_weeds(self, point: Point3d, *, max_distance=0.5) -> list[Plant]:
return [w for w in self.weeds if w.position.distance(point) <= max_distance and w.confidence >= self.minimum_combined_weed_confidence]

def settings_ui(self) -> None:
Expand Down
8 changes: 4 additions & 4 deletions tests/test_plant_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ def test_extracting_relevant_crops():
plants = PlantProvider()
for i in range(20):
plants.add_crop(create_crop(i/10.0, 0))
crops = plants.get_relevant_crops(rosys.geometry.Point(x=1.0, y=0), max_distance=0.45)
crops = plants.get_relevant_crops(rosys.geometry.Point3d(x=1.0, y=0, z=0), max_distance=0.45)
assert len(crops) == 9
# TODO do not clear list; better to use weighted average in confidence property
plants.crops[10].confidences.clear()
plants.crops[10].confidences.append(0.4)
crops = plants.get_relevant_crops(rosys.geometry.Point(x=1.0, y=0), max_distance=0.45)
crops = plants.get_relevant_crops(rosys.geometry.Point3d(x=1.0, y=0, z=0), max_distance=0.45)
assert len(crops) == 8, 'crops with a confidence of less than PlantProvider.MINIMUM_COMBINED_CROP_CONFIDENCE should be ignored'


def create_crop(x: float, y: float) -> Plant:
"""Creates a maize plant with three observed positions at the given coordinates."""
plant = Plant(type='maize', detection_time=rosys.time())
for _ in range(3):
plant.positions.append(rosys.geometry.Point(x=x, y=y))
plant.positions.append(rosys.geometry.Point3d(x=x, y=y, z=0))
plant.confidences.append(0.9)
return plant

Expand All @@ -32,7 +32,7 @@ def test_crop_prediction():

def add_crop(x):
plant = Plant(type='maize', detection_time=rosys.time())
plant.positions.append(rosys.geometry.Point(x=x, y=0))
plant.positions.append(rosys.geometry.Point3d(x=x, y=0, z=0))
plant.confidences.append(confidence)
plant_provider.add_crop(plant)

Expand Down

0 comments on commit e352134

Please sign in to comment.