Skip to content

Commit

Permalink
Add radar dtype bugfix and test, addresses nutonomy#588 (nutonomy#589)
Browse files Browse the repository at this point in the history
* Add bugfix and test

* Typo

Co-authored-by: Holger Caesar <holger.caesar@motional.com>
  • Loading branch information
holger-motional and Holger Caesar authored Apr 20, 2021
1 parent 87b88fe commit 68eb618
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
5 changes: 1 addition & 4 deletions python-sdk/nuscenes/utils/data_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def from_file_multisweep(cls,
:return: (all_pc, all_times). The aggregated point cloud and timestamps.
"""
# Init.
points = np.zeros((cls.nbr_dims(), 0), dtype=np.float32)
points = np.zeros((cls.nbr_dims(), 0), dtype=np.float32 if cls == LidarPointCloud else np.float64)
all_pc = cls(points)
all_times = np.zeros((1, 0))

Expand Down Expand Up @@ -127,9 +127,6 @@ def from_file_multisweep(cls,
else:
current_sd_rec = nusc.get('sample_data', current_sd_rec['prev'])

# Check that the multisweep pointcloud has the same dtype as individual pointclouds.
assert all_pc.points.dtype == np.float32, 'Error: Invalid dtype for multisweep pointcloud!'

return all_pc, all_times

def nbr_points(self) -> int:
Expand Down
38 changes: 38 additions & 0 deletions python-sdk/nuscenes/utils/tests/test_data_classes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# nuScenes dev-kit.
# Code written by Holger Caesar, 2021.

import os
import unittest

from nuscenes import NuScenes
from nuscenes.utils.data_classes import LidarPointCloud, RadarPointCloud


class TestDataClasses(unittest.TestCase):

def test_load_pointclouds(self):
"""
Loads up lidar and radar pointclouds.
"""
assert 'NUSCENES' in os.environ, 'Set NUSCENES env. variable to enable tests.'
dataroot = os.environ['NUSCENES']
nusc = NuScenes(version='v1.0-mini', dataroot=dataroot, verbose=False)
sample_rec = nusc.sample[0]
lidar_name = nusc.get('sample_data', sample_rec['data']['LIDAR_TOP'])['filename']
radar_name = nusc.get('sample_data', sample_rec['data']['RADAR_FRONT'])['filename']
lidar_path = os.path.join(dataroot, lidar_name)
radar_path = os.path.join(dataroot, radar_name)
pc1 = LidarPointCloud.from_file(lidar_path)
pc2 = RadarPointCloud.from_file(radar_path)
pc3, _ = LidarPointCloud.from_file_multisweep(nusc, sample_rec, 'LIDAR_TOP', 'LIDAR_TOP', nsweeps=2)
pc4, _ = RadarPointCloud.from_file_multisweep(nusc, sample_rec, 'RADAR_FRONT', 'RADAR_FRONT', nsweeps=2)

# Check for valid dimensions.
assert pc1.points.shape[0] == pc3.points.shape[0] == 4, 'Error: Invalid dimension for lidar pointcloud!'
assert pc2.points.shape[0] == pc4.points.shape[0] == 18, 'Error: Invalid dimension for radar pointcloud!'
assert pc1.points.dtype == pc3.points.dtype, 'Error: Invalid dtype for lidar pointcloud!'
assert pc2.points.dtype == pc4.points.dtype, 'Error: Invalid dtype for radar pointcloud!'


if __name__ == '__main__':
unittest.main()

0 comments on commit 68eb618

Please sign in to comment.