Skip to content

Commit

Permalink
coverage now at 67%
Browse files Browse the repository at this point in the history
Lots of moving things around <3
fixed a bug where everything hangs due to how I did fcmega
  • Loading branch information
TheMariday committed Oct 13, 2024
1 parent dbf0e29 commit 00220ca
Show file tree
Hide file tree
Showing 17 changed files with 259 additions and 124 deletions.
5 changes: 2 additions & 3 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[flake8]
ignore = E402
exclude = marimapper/backends/fadecandy/opc.py, venv, marimapper/database.py, marimapper/read_write_model.py
exclude = marimapper/backends/fadecandy/opc.py, venv, marimapper/pycolmap_tools/*
max-line-length=127
max-complexity = 10
extend-ignore = W503, E203, C901
extend-ignore = W503, E203
5 changes: 1 addition & 4 deletions marimapper/backends/fcmega/fcmega_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@ def __init__(self):
self.fc_mega = FCMega()
self.leds = [(0, 0, 0) for _ in range(self.get_led_count())]
self.running = True
self.update_thread = threading.Thread(target=self._run)
self.update_thread = threading.Thread(target=self._run, daemon=True)
self.update_thread.start()

def __del__(self):
self.running = False

def get_led_count(self):
return 24 * 400

Expand Down
5 changes: 3 additions & 2 deletions marimapper/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self, device_id):
break

if not self.device.isOpened():
logging.error(f"Failed to connect to camera {device_id}")
raise RuntimeError(f"Failed to connect to camera {device_id}")

self.set_resolution(self.get_width(), self.get_height()) # Don't ask

Expand Down Expand Up @@ -71,7 +71,8 @@ def set_resolution(self, width, height):
new_width = self.get_width()
new_height = self.get_height()

if width != new_width or height != new_height:
# this is cov ignored as it's a strange position to be in but ultimately fine
if width != new_width or height != new_height: # pragma: no cover
logging.error(
f"Failed to set camera {self.device_id} resolution to {width} x {height}",
)
Expand Down
2 changes: 1 addition & 1 deletion marimapper/database_populator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import numpy as np

from marimapper.database import COLMAPDatabase
from marimapper.pycolmap_tools.database import COLMAPDatabase


def populate(db_path, led_maps_2d):
Expand Down
9 changes: 3 additions & 6 deletions marimapper/led_map_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ def __init__(self, data=None):
if data is not None:
self.data = data

def __setitem__(self, led_index, led_data):
def __setitem__(self, led_index, led_data): # pragma: no cover
self.data[led_index] = led_data

def __getitem__(self, led_index):
def __getitem__(self, led_index): # pragma: no cover
return self.data[led_index]

def __contains__(self, led_index):
def __contains__(self, led_index): # pragma: no cover
return led_index in self.data

def __len__(self):
Expand Down Expand Up @@ -64,9 +64,6 @@ def rescale(self, target_inter_distance=1.0):
for cam in self.cameras:
cam[1] *= scale

def get_normal_list(self):
return np.array([self[led_id]["normal"] for led_id in self.keys()])

def get_inter_led_distance(self):
max_led_id = max(self.keys())

Expand Down
41 changes: 0 additions & 41 deletions marimapper/map_cleaner.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,44 +72,3 @@ def fill_gaps(led_map, max_dist_err=0.2, max_missing=5):
total_leds_filled += leds_missing

return total_leds_filled


def extract_strips(led_map, max_dist_err=0.5):

max_led_id = max(led_map.keys())

strips = [[]]
led_id = -1

led_to_led_distance = find_inter_led_distance(led_map)

max_dist = (1 + max_dist_err) * led_to_led_distance
min_dist = (1 - max_dist_err) * led_to_led_distance

while True:

led_id += 1

if led_id > max_led_id:
break

if led_id not in led_map:
continue

if led_id + 1 not in led_map:
if strips[-1]:
strips[-1].append(led_id)
strips.append([])
continue

distance = _distance_between_leds(led_map[led_id], led_map[led_id + 1])

if not (min_dist < distance < max_dist):
if strips[-1]:
strips[-1].append(led_id)
strips.append([])
continue

strips[-1].append(led_id)

return strips
2 changes: 1 addition & 1 deletion marimapper/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import numpy as np

from marimapper.read_write_model import (
from marimapper.pycolmap_tools.read_write_model import (
qvec2rotmat,
read_images_binary,
read_points3D_binary,
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# fmt: off
# Copyright (c) 2023, ETH Zurich and UNC Chapel Hill.
# All rights reserved.
#
Expand Down Expand Up @@ -429,5 +428,3 @@ def example_usage():

if __name__ == "__main__":
example_usage()

# fmt: on
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# fmt: off
# Copyright (c) 2023, ETH Zurich and UNC Chapel Hill.
# All rights reserved.
#
Expand Down Expand Up @@ -604,4 +603,3 @@ def main():

if __name__ == "__main__":
main()
# fmt: on
22 changes: 14 additions & 8 deletions marimapper/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def add_backend_args(parser):
parser.add_argument("--server", type=str, help="Some backends require a server")


def get_user_confirmation(prompt):
def get_user_confirmation(prompt): # pragma: no coverage

try:
uin = input(logging.colorise(prompt, logging.Col.BLUE))
Expand All @@ -86,13 +86,21 @@ def load_custom_backend(backend_file, server=None):

backend = custom_backend.Backend(server) if server else custom_backend.Backend()

if "get_led_count" not in dir(backend):
raise RuntimeError("Your backend does not have a get_led_count function")
check_backend(backend)

if "set_led" not in dir(backend):
raise RuntimeError("Your backend does not have a set_led function")
return backend


def check_backend(backend):

if len(signature(backend.get_led_count).parameters) != 0:
missing_funcs = {"get_led_count", "set_led"}.difference(set(dir(backend)))

if missing_funcs:
raise RuntimeError(
f"Your backend does not have the following functions: {missing_funcs}"
)

if len(signature(backend.get_led_count).parameters) != 0: # pragma: no coverage
raise RuntimeError(
"Your backend get_led_count function should not take any arguments"
)
Expand All @@ -102,8 +110,6 @@ def load_custom_backend(backend_file, server=None):
"Your backend set_led function should only take two arguments"
)

return backend


def get_backend(backend_name, server=""):
if backend_name == "fadecandy":
Expand Down
2 changes: 1 addition & 1 deletion marimapper/visualize_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def reload_geometry__(self, first=False):
np.array([led_map.data[led_id]["pos"] for led_id in led_map.keys()])
)
self.point_cloud.normals = open3d.utility.Vector3dVector(
led_map.get_normal_list() * 0.2
np.array([led_map[led_id]["normal"] for led_id in led_map.keys()]) * 0.2
)

self.strip_set.points = self.point_cloud.points
Expand Down
16 changes: 13 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ readme = "README.md"
license = {file = "LICENSE"}



[project.optional-dependencies]
develop = [
"pytest",
"pytest-cov",
"pytest-mock",
"black",
"flake8",
"flake8-bugbear"
Expand All @@ -62,5 +63,14 @@ omit = [
"*/__main__.py",
"marimapper/backends/*",
"marimapper/scripts/*",
"marimapper/read_write_model.py"
]
"marimapper/pycolmap_tools/*"
]

[tool.black]
exclude = '''
(/(
| venv
| marimapper/backends
| marimapper/pycolmap_tools
)/)
'''
Loading

0 comments on commit 00220ca

Please sign in to comment.