Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/odlc search grid #62

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 11 additions & 2 deletions flight/odlc_search_grid/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
Sample runner to test the search paths feature
"""

import plotter
import search_path

Expand Down Expand Up @@ -25,8 +29,13 @@
search_area_points = search_path.all_latlon_to_utm(search_area_points)

# Generate search path
buffer_distance = -50
search_paths = search_path.generate_search_path(search_area_points, buffer_distance)
BUFFER_DISTANCE = -50 # use height/2 of camera image as buffer distance
Copy link
Contributor

Choose a reason for hiding this comment

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

This constant needs a type hint.

search_paths = search_path.generate_search_paths(search_area_points, BUFFER_DISTANCE)

# fly all points in search_paths[0],
# when you reach your starting point,
# fly all points in search_paths[1],
# etc... until all search paths have been flown

# Plot data
plotter.plot_data(search_paths)
12 changes: 10 additions & 2 deletions flight/odlc_search_grid/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@
Provides plotting functionality for visualizing coordinate data
"""

from typing import List, Dict, Tuple
from typing import List, Tuple
import matplotlib.pyplot as plt


def plot_data(search_paths) -> None:
def plot_data(search_paths: List[List[Tuple[float, float]]]) -> None:
"""Simple plotter function to plot the search paths

Parameters
----------
search_paths : List[Tuple[float, float]]
A list of search paths to be plotted
"""

for path in search_paths:
x, y = [], []
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't forget your type hints; label what exactly these two lists are and what they contain, similar in format to the return type in your docstring.

for point in path:
Expand Down
44 changes: 29 additions & 15 deletions flight/odlc_search_grid/search_path.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
"""
Functions for generating a search path for standard odlc objects
Functions for generating search paths to cover an area for finding the standard odlc objects
"""

from typing import List, Dict, Tuple

from shapely.geometry import Point, Polygon
from shapely.ops import nearest_points
from shapely.geometry import Polygon
import utm


Expand Down Expand Up @@ -50,23 +48,39 @@ def all_latlon_to_utm(list_of_coords: List[Dict[str, float]]) -> List[Dict[str,
return list_of_coords


# use height/2 of camera image as buffer distance
def generate_search_path(search_area_points, buffer_distance):
poly_points = [(point["utm_x"], point["utm_y"]) for point in search_area_points]
def generate_search_paths(
search_area_points: List[Dict[str, float]], buffer_distance: int
) -> List[Tuple[float, float]]:
"""Generates a list of search paths of increasingly smaller sizes until the whole area
of the original shape has been covered

Parameters
----------
search_area_points : Dict[str, float]
Copy link
Contributor

Choose a reason for hiding this comment

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

The parameter says that this is a List[Dict[str, float]], I think you forgot the first List[]

A list of coordinates in dictionary form that contain utm coordinate data
buffer_distance : int
The distance that each search path will be apart from the previous one.
For complete photographic coverage of the area, this should be equal to half the height
of the area the camera covers on the ground given the current altitude.

Returns
-------
List[Tuple[float, float]]
A list of concentric search paths that cover the area of the polygon
"""

# convert to shapely polygon for buffer operations
poly_points = [(point["utm_x"], point["utm_y"]) for point in search_area_points]
Copy link
Contributor

Choose a reason for hiding this comment

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

Type hint for this guy as well

boundary_shape = Polygon(poly_points)
Copy link
Contributor

Choose a reason for hiding this comment

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

Python will also support a type hint of an object from an imported module, I know this seems redundant since the function is literally called Polygon, however you still need a type hint for the object you create here.


search_paths = []
Copy link
Contributor

Choose a reason for hiding this comment

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

You already know; type hints for this new list

search_paths.append(
list(zip(*boundary_shape.exterior.coords.xy)) # pylint: disable=maybe-no-member
)

while True:
boundary_shape = boundary_shape.buffer(buffer_distance, single_sided=True)
if boundary_shape.area <= 0:
break
# shrink boundary by a fixed amount until the area it covers is 0
# add the smaller boundary to our list of search paths on each iteration
while boundary_shape.area > 0:
search_paths.append(
list(zip(*boundary_shape.exterior.coords.xy)) # pylint: disable=maybe-no-member
tuple(zip(*boundary_shape.exterior.coords.xy)) # pylint: disable=maybe-no-member
)
boundary_shape = boundary_shape.buffer(buffer_distance, single_sided=True)

return search_paths