Skip to content

Commit 0c49aaa

Browse files
committed
Minor refactorings, adding some tests.
1 parent 26762b9 commit 0c49aaa

File tree

18 files changed

+823
-219
lines changed

18 files changed

+823
-219
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*.log
2525
*.mp4
2626
exp/
27+
.coverage
2728

2829
# Sphinx documentation
2930
docs/_build/

notebooks/01_scene_tutorial.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@
162162
],
163163
"metadata": {
164164
"kernelspec": {
165-
"display_name": "py123d",
165+
"display_name": "py123d_dev",
166166
"language": "python",
167167
"name": "python3"
168168
},

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ docs = [
7373
]
7474
nuplan = [
7575
"nuplan-devkit @ git+https://github.com/motional/nuplan-devkit/@nuplan-devkit-v1.2",
76+
"SQLAlchemy==1.4.27",
77+
"rasterio",
78+
"aioboto3",
79+
"retry",
80+
"cachetools",
7681
]
7782
nuscenes = [
7883
"nuscenes-devkit==1.2.0",

src/py123d/api/scene/scene_builder.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,3 @@ def get_scenes(self, filter: SceneFilter, worker: WorkerPool) -> List[SceneAPI]:
1919
:param worker: WorkerPool to parallelize the scene extraction.
2020
:return: Iterator over AbstractScene objects.
2121
"""
22-
raise NotImplementedError

src/py123d/conversion/registry/box_detection_label_registry.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class BoxDetectionLabel(SerialIntEnum):
1919
@abc.abstractmethod
2020
def to_default(self) -> DefaultBoxDetectionLabel:
2121
"""Convert to the default box detection label."""
22-
raise NotImplementedError("Subclasses must implement this method.")
2322

2423

2524
@register_box_detection_label

src/py123d/geometry/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Corners2DIndex,
77
Corners3DIndex,
88
EulerAnglesIndex,
9-
EulerStateSE3Index,
9+
EulerPoseSE3Index,
1010
QuaternionIndex,
1111
PoseSE2Index,
1212
PoseSE3Index,
@@ -16,7 +16,7 @@
1616
from py123d.geometry.point import Point2D, Point3D
1717
from py123d.geometry.vector import Vector2D, Vector3D
1818
from py123d.geometry.rotation import EulerAngles, Quaternion
19-
from py123d.geometry.pose import EulerStateSE3, PoseSE2, PoseSE3
19+
from py123d.geometry.pose import EulerPoseSE3, PoseSE2, PoseSE3
2020
from py123d.geometry.bounding_box import BoundingBoxSE2, BoundingBoxSE3
2121
from py123d.geometry.polyline import Polyline2D, Polyline3D, PolylineSE2
2222
from py123d.geometry.occupancy_map import OccupancyMap2D

src/py123d/geometry/geometry_index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def VECTOR(cls) -> slice:
103103
return slice(cls.QX, cls.QZ + 1)
104104

105105

106-
class EulerStateSE3Index(IntEnum):
106+
class EulerPoseSE3Index(IntEnum):
107107
"""Indexing enum for array-like representations of SE3 states with Euler angles (x,y,z,roll,pitch,yaw).
108108
109109
Notes

src/py123d/geometry/pose.py

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import shapely.geometry as geom
66

77
from py123d.common.utils.mixin import ArrayMixin
8-
from py123d.geometry.geometry_index import EulerStateSE3Index, Point3DIndex, PoseSE2Index, PoseSE3Index
8+
from py123d.geometry.geometry_index import EulerPoseSE3Index, Point3DIndex, PoseSE2Index, PoseSE3Index
99
from py123d.geometry.point import Point2D, Point3D
1010
from py123d.geometry.rotation import EulerAngles, Quaternion
1111

@@ -279,7 +279,7 @@ def transformation_matrix(self) -> npt.NDArray[np.float64]:
279279
return transformation_matrix
280280

281281

282-
class EulerStateSE3(ArrayMixin):
282+
class EulerPoseSE3(ArrayMixin):
283283
"""
284284
Class to represents a 3D pose as SE3 (x, y, z, roll, pitch, yaw).
285285
@@ -293,17 +293,17 @@ class EulerStateSE3(ArrayMixin):
293293

294294
def __init__(self, x: float, y: float, z: float, roll: float, pitch: float, yaw: float):
295295
"""Initialize PoseSE3 with x, y, z, roll, pitch, yaw coordinates."""
296-
array = np.zeros(len(EulerStateSE3Index), dtype=np.float64)
297-
array[EulerStateSE3Index.X] = x
298-
array[EulerStateSE3Index.Y] = y
299-
array[EulerStateSE3Index.Z] = z
300-
array[EulerStateSE3Index.ROLL] = roll
301-
array[EulerStateSE3Index.PITCH] = pitch
302-
array[EulerStateSE3Index.YAW] = yaw
296+
array = np.zeros(len(EulerPoseSE3Index), dtype=np.float64)
297+
array[EulerPoseSE3Index.X] = x
298+
array[EulerPoseSE3Index.Y] = y
299+
array[EulerPoseSE3Index.Z] = z
300+
array[EulerPoseSE3Index.ROLL] = roll
301+
array[EulerPoseSE3Index.PITCH] = pitch
302+
array[EulerPoseSE3Index.YAW] = yaw
303303
object.__setattr__(self, "_array", array)
304304

305305
@classmethod
306-
def from_array(cls, array: npt.NDArray[np.float64], copy: bool = True) -> EulerStateSE3:
306+
def from_array(cls, array: npt.NDArray[np.float64], copy: bool = True) -> EulerPoseSE3:
307307
"""Constructs a PoseSE3 from a numpy array.
308308
309309
:param array: Array of shape (6,) representing the state [x, y, z, roll, pitch, yaw], indexed by \
@@ -312,24 +312,24 @@ def from_array(cls, array: npt.NDArray[np.float64], copy: bool = True) -> EulerS
312312
:return: A PoseSE3 instance.
313313
"""
314314
assert array.ndim == 1
315-
assert array.shape[0] == len(EulerStateSE3Index)
315+
assert array.shape[0] == len(EulerPoseSE3Index)
316316
instance = object.__new__(cls)
317317
object.__setattr__(instance, "_array", array.copy() if copy else array)
318318
return instance
319319

320320
@classmethod
321-
def from_transformation_matrix(cls, transformation_matrix: npt.NDArray[np.float64]) -> EulerStateSE3:
322-
"""Constructs a EulerStateSE3 from a 4x4 transformation matrix.
321+
def from_transformation_matrix(cls, transformation_matrix: npt.NDArray[np.float64]) -> EulerPoseSE3:
322+
"""Constructs a EulerPoseSE3 from a 4x4 transformation matrix.
323323
324324
:param array: A 4x4 numpy array representing the transformation matrix.
325-
:return: A EulerStateSE3 instance.
325+
:return: A EulerPoseSE3 instance.
326326
"""
327327
assert transformation_matrix.ndim == 2
328328
assert transformation_matrix.shape == (4, 4)
329329
translation = transformation_matrix[:3, 3]
330330
rotation = transformation_matrix[:3, :3]
331331
roll, pitch, yaw = EulerAngles.from_rotation_matrix(rotation)
332-
return EulerStateSE3(
332+
return EulerPoseSE3(
333333
x=translation[Point3DIndex.X],
334334
y=translation[Point3DIndex.Y],
335335
z=translation[Point3DIndex.Z],
@@ -344,47 +344,47 @@ def x(self) -> float:
344344
345345
:return: The x-coordinate.
346346
"""
347-
return self._array[EulerStateSE3Index.X]
347+
return self._array[EulerPoseSE3Index.X]
348348

349349
@property
350350
def y(self) -> float:
351351
"""Returns the y-coordinate of the 3D state.
352352
353353
:return: The y-coordinate.
354354
"""
355-
return self._array[EulerStateSE3Index.Y]
355+
return self._array[EulerPoseSE3Index.Y]
356356

357357
@property
358358
def z(self) -> float:
359359
"""Returns the z-coordinate of the 3D state.
360360
361361
:return: The z-coordinate.
362362
"""
363-
return self._array[EulerStateSE3Index.Z]
363+
return self._array[EulerPoseSE3Index.Z]
364364

365365
@property
366366
def roll(self) -> float:
367367
"""Returns the roll (x-axis rotation) of the 3D state.
368368
369369
:return: The roll angle.
370370
"""
371-
return self._array[EulerStateSE3Index.ROLL]
371+
return self._array[EulerPoseSE3Index.ROLL]
372372

373373
@property
374374
def pitch(self) -> float:
375375
"""Returns the pitch (y-axis rotation) of the 3D state.
376376
377377
:return: The pitch angle.
378378
"""
379-
return self._array[EulerStateSE3Index.PITCH]
379+
return self._array[EulerPoseSE3Index.PITCH]
380380

381381
@property
382382
def yaw(self) -> float:
383383
"""Returns the yaw (z-axis rotation) of the 3D state.
384384
385385
:return: The yaw angle.
386386
"""
387-
return self._array[EulerStateSE3Index.YAW]
387+
return self._array[EulerPoseSE3Index.YAW]
388388

389389
@property
390390
def array(self) -> npt.NDArray[np.float64]:
@@ -444,20 +444,32 @@ def transformation_matrix(self) -> npt.NDArray[np.float64]:
444444
rotation_matrix = self.rotation_matrix
445445
transformation_matrix = np.eye(4, dtype=np.float64)
446446
transformation_matrix[:3, :3] = rotation_matrix
447-
transformation_matrix[:3, 3] = self.array[EulerStateSE3Index.XYZ]
447+
transformation_matrix[:3, 3] = self.array[EulerPoseSE3Index.XYZ]
448448
return transformation_matrix
449449

450450
@property
451451
def euler_angles(self) -> EulerAngles:
452-
return EulerAngles.from_array(self.array[EulerStateSE3Index.EULER_ANGLES])
452+
"""Returns the :class:`~py123d.geometry.EulerAngles` representation of the state's orientation.
453+
454+
:return: An EulerAngles instance representing the state's orientation.
455+
"""
456+
return EulerAngles.from_array(self.array[EulerPoseSE3Index.EULER_ANGLES])
453457

454458
@property
455459
def pose_se3(self) -> PoseSE3:
460+
"""Returns the :class:`~py123d.geometry.PoseSE3` representation of the state.
461+
462+
:return: A PoseSE3 instance representing the state.
463+
"""
456464
quaternion_se3_array = np.zeros(len(PoseSE3Index), dtype=np.float64)
457-
quaternion_se3_array[PoseSE3Index.XYZ] = self.array[EulerStateSE3Index.XYZ]
465+
quaternion_se3_array[PoseSE3Index.XYZ] = self.array[EulerPoseSE3Index.XYZ]
458466
quaternion_se3_array[PoseSE3Index.QUATERNION] = Quaternion.from_euler_angles(self.euler_angles)
459467
return PoseSE3.from_array(quaternion_se3_array, copy=False)
460468

461469
@property
462470
def quaternion(self) -> Quaternion:
471+
"""Returns the :class:`~py123d.geometry.Quaternion` representation of the state's orientation.
472+
473+
:return: A Quaternion instance representing the state's orientation.
474+
"""
463475
return Quaternion.from_euler_angles(self.euler_angles)

0 commit comments

Comments
 (0)