From 38baa8db5ab78f6cd79172e7566d0e45ea1f2bd3 Mon Sep 17 00:00:00 2001 From: Dan Trickey Date: Sun, 24 Jun 2018 18:09:51 +0100 Subject: [PATCH 1/4] Remove Legacy Polar Co-ordinates system --- README.md | 4 +--- sb_vision/__init__.py | 3 +-- sb_vision/coordinates.py | 20 -------------------- sb_vision/tokens.py | 4 ---- tests/test_coordinates_from_file.py | 22 +++------------------- 5 files changed, 5 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index 0345e5c..ec96ec4 100644 --- a/README.md +++ b/README.md @@ -63,9 +63,7 @@ Run them by running `python setup.py test` (or `pytest`). ## Co-ordinate spaces sb-vision describes the locations of identified markers in either Cartesian or -spherical co-ordinate spaces. A "legacy polar" co-ordinate space exists for -backwards compatibility but is deprecated, undocumented and will be removed in -May 2018. +spherical co-ordinate spaces. ### Cartesian co-ordinates diff --git a/sb_vision/__init__.py b/sb_vision/__init__.py index 21b3492..692dba4 100644 --- a/sb_vision/__init__.py +++ b/sb_vision/__init__.py @@ -7,7 +7,7 @@ """ from .camera import Camera, FileCamera -from .coordinates import Cartesian, LegacyPolar, Spherical, cartesian_to_spherical +from .coordinates import Cartesian, Spherical, cartesian_to_spherical from .tokens import Token from .vision import Vision @@ -17,7 +17,6 @@ 'FileCamera', 'Token', 'Cartesian', - 'LegacyPolar', 'Spherical', 'cartesian_to_spherical', ] diff --git a/sb_vision/coordinates.py b/sb_vision/coordinates.py index 01b9154..a6a052c 100644 --- a/sb_vision/coordinates.py +++ b/sb_vision/coordinates.py @@ -30,13 +30,6 @@ def tolist(self): ('dist', AnyFloat), )) -LegacyPolar = NamedTuple('LegacyPolar', ( - ('polar_x', AnyFloat), - ('polar_y', AnyFloat), - ('dist', AnyFloat), -)) - - PixelCoordinate = NamedTuple('PixelCoordinate', [('x', AnyFloat), ('y', AnyFloat)]) @@ -48,16 +41,3 @@ def cartesian_to_spherical(cartesian: Cartesian) -> Spherical: rot_y=arctan2(x, z), dist=linalg.norm(cartesian), ) - - -def cartesian_to_legacy_polar(cartesian: Cartesian) -> LegacyPolar: - """ - Convert cartesian co-ordinate space to the legacy "polar" space. - - This is kept for compatibility only. - """ - cart_x, cart_y, cart_z = tuple(cartesian) - polar_dist = np.linalg.norm(cartesian) - polar_x = np.arctan2(cart_z, cart_x) - polar_y = np.arctan2(cart_z, cart_y) - return LegacyPolar(polar_x, polar_y, polar_dist) diff --git a/sb_vision/tokens.py b/sb_vision/tokens.py index f8b003c..f6e444d 100644 --- a/sb_vision/tokens.py +++ b/sb_vision/tokens.py @@ -6,7 +6,6 @@ from .coordinates import ( Cartesian, - cartesian_to_legacy_polar, cartesian_to_spherical, ) from .find_3D_coords import ( @@ -110,9 +109,6 @@ def update_3D_transforms( self.cartesian = translation # Polar co-ordinates in the 3D world, relative to the camera - self.polar = cartesian_to_legacy_polar(self.cartesian) - self.legacy_polar = cartesian_to_legacy_polar(self.cartesian) - self.spherical = cartesian_to_spherical(self.cartesian) def __repr__(self) -> str: diff --git a/tests/test_coordinates_from_file.py b/tests/test_coordinates_from_file.py index b5d7a37..a08d9e2 100644 --- a/tests/test_coordinates_from_file.py +++ b/tests/test_coordinates_from_file.py @@ -6,7 +6,7 @@ import pytest from pytest import approx -from sb_vision import Cartesian, FileCamera, LegacyPolar, Spherical, Vision +from sb_vision import Cartesian, FileCamera, Spherical, Vision # Ensure all distance values are within this tolerance # (as a percentage of the total distance) @@ -20,11 +20,6 @@ ( '1.0z-0.1x.jpg', Cartesian(x=-0.1, y=0, z=1), - LegacyPolar( - polar_x=1.6704649792860642, - polar_y=1.5707963267948966, - dist=1.004987562112089, - ), Spherical( rot_x=0, rot_y=math.atan(-0.1), # or -5.710593137499643 degrees @@ -34,11 +29,6 @@ ( '3.0z1.0x.jpg', Cartesian(x=1, y=0, z=3), - LegacyPolar( - polar_x=1.1922, - polar_y=1.6032, - dist=(1 + 9)**0.5, # or 3.1622776601683795 - ), Spherical( rot_x=0, rot_y=math.atan(1 / 3), # or 18.43494882296774 degrees @@ -49,10 +39,10 @@ @pytest.mark.parametrize( - "photo, expected_cartesian, expected_polar, expected_spherical", + "photo, expected_cartesian, expected_spherical", TEST_IMAGES, ) -def test_image_coordinates(photo, expected_cartesian, expected_polar, expected_spherical): +def test_image_coordinates(photo, expected_cartesian, expected_spherical): """Make sure that this particular file gives these particular tokens.""" camera = FileCamera(CALIBRATIONS / photo, camera_model='C016') vision = Vision(camera) @@ -70,12 +60,6 @@ def approx_ang(expected): assert y == approx_dist(expected_cartesian.y), "Wrong y-coordinate" assert z == approx_dist(expected_cartesian.z), "Wrong z-coordinate" - polar_x, polar_y, polar_dist = token.legacy_polar - - assert polar_x == approx_ang(expected_polar.polar_x), "Wrong polar_x coordinate" - assert polar_y == approx_ang(expected_polar.polar_y), "Wrong polar_y coordinate" - assert polar_dist == approx_dist(expected_polar.dist), "Wrong polar_dist coordinate" - rot_x, rot_y, dist = token.spherical assert rot_x == approx_ang(expected_spherical.rot_x), "Wrong x-coordinate" From a89f0bf8c1be3ec9c79e7f0e86e611411dcc0d5e Mon Sep 17 00:00:00 2001 From: Dan Trickey Date: Sun, 24 Jun 2018 18:13:02 +0100 Subject: [PATCH 2/4] Fix linting errors --- sb_vision/tokens.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/sb_vision/tokens.py b/sb_vision/tokens.py index f6e444d..62e5231 100644 --- a/sb_vision/tokens.py +++ b/sb_vision/tokens.py @@ -2,12 +2,7 @@ from typing import TYPE_CHECKING, Any, List, Optional, Tuple -import numpy as np - -from .coordinates import ( - Cartesian, - cartesian_to_spherical, -) +from .coordinates import Cartesian, cartesian_to_spherical from .find_3D_coords import ( PixelCoordinate, calculate_transforms, From 741d705adfa3e40392a8a32e89dc3519b76aff17 Mon Sep 17 00:00:00 2001 From: Dan Trickey Date: Sun, 24 Jun 2018 18:19:11 +0100 Subject: [PATCH 3/4] Revert removing np --- sb_vision/tokens.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sb_vision/tokens.py b/sb_vision/tokens.py index 62e5231..b569013 100644 --- a/sb_vision/tokens.py +++ b/sb_vision/tokens.py @@ -2,6 +2,8 @@ from typing import TYPE_CHECKING, Any, List, Optional, Tuple +import numpy as np + from .coordinates import Cartesian, cartesian_to_spherical from .find_3D_coords import ( PixelCoordinate, From 593dc6e589d9342b0376cad78984f8b580562651 Mon Sep 17 00:00:00 2001 From: Dan Trickey Date: Mon, 25 Jun 2018 11:01:45 +0100 Subject: [PATCH 4/4] Remove unused numpy import --- sb_vision/coordinates.py | 1 - 1 file changed, 1 deletion(-) diff --git a/sb_vision/coordinates.py b/sb_vision/coordinates.py index a6a052c..17ef755 100644 --- a/sb_vision/coordinates.py +++ b/sb_vision/coordinates.py @@ -2,7 +2,6 @@ from typing import NamedTuple, Union -import numpy as np from numpy import arctan2, float64, linalg AnyFloat = Union[float, float64]