From 3e91eb693c8530d128f867c10db7e196eb80d6b8 Mon Sep 17 00:00:00 2001 From: William Ljungbergh Date: Mon, 30 Oct 2023 19:46:49 +0100 Subject: [PATCH] Remove lidar returns on the EGO vehicle by default --- zod/data_classes/sensor.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/zod/data_classes/sensor.py b/zod/data_classes/sensor.py index a9cc505..61f853c 100644 --- a/zod/data_classes/sensor.py +++ b/zod/data_classes/sensor.py @@ -15,6 +15,11 @@ from ._serializable import JSONSerializable from .geometry import Pose +# we want to remove the points that get returns from the ego vehicle. +# we do this by removing all points that are within the box defined by +# EGO_RETURNS_BOX. This box is defined in the LiDAR frame. +EGO_RETURNS_BOX = np.array([[-1.5, -3.0, -1.5], [1.5, 3.0, 0.5]]) + @dataclass class LidarData: @@ -48,10 +53,17 @@ def empty(cls) -> LidarData: ) @classmethod - def from_npy(cls, path: str) -> LidarData: + def from_npy(cls, path: str, remove_ego_lidar_returns: bool = True) -> LidarData: """Load lidar data from a .npy file.""" data = np.load(path) core_timestamp = parse_datetime_from_filename(path).timestamp() + if remove_ego_lidar_returns: + ego_returns_mask = np.ones(len(data), dtype=np.bool_) + for idim, dim in enumerate(("x", "y", "z")): + ego_returns_mask &= np.logical_and( + data[dim] > EGO_RETURNS_BOX[0, idim], data[dim] < EGO_RETURNS_BOX[1, idim] + ) + data = data[~ego_returns_mask] return cls( points=np.vstack((data["x"], data["y"], data["z"])).T, timestamps=core_timestamp + data["timestamp"] / 1e6,