@@ -47,7 +47,7 @@ def ensure_scene_available(root_dir: pathlib.Path, dataset_version: str, scene_n
4747 raise ValueError (f"{ scene_name = } not found in dataset" )
4848
4949
50- def log_nuscenes (root_dir : pathlib .Path , dataset_version : str , scene_name : str ) -> None :
50+ def log_nuscenes (root_dir : pathlib .Path , dataset_version : str , scene_name : str , max_time_sec : float ) -> None :
5151 """Log nuScenes scene."""
5252 nusc = nuscenes .NuScenes (version = dataset_version , dataroot = root_dir , verbose = True )
5353
@@ -72,20 +72,26 @@ def log_nuscenes(root_dir: pathlib.Path, dataset_version: str, scene_name: str)
7272 elif sample_data ["sensor_modality" ] == "camera" :
7373 first_camera_tokens .append (sample_data_token )
7474
75- log_lidar_and_ego_pose (first_lidar_token , nusc )
76- log_cameras (first_camera_tokens , nusc )
77- log_radars (first_radar_tokens , nusc )
78- log_annotations (first_sample_token , nusc )
75+ first_timestamp_us = nusc .get ("sample_data" , first_lidar_token )["timestamp" ]
76+ max_timestamp_us = first_timestamp_us + 1e6 * max_time_sec
7977
78+ log_lidar_and_ego_pose (first_lidar_token , nusc , max_timestamp_us )
79+ log_cameras (first_camera_tokens , nusc , max_timestamp_us )
80+ log_radars (first_radar_tokens , nusc , max_timestamp_us )
81+ log_annotations (first_sample_token , nusc , max_timestamp_us )
8082
81- def log_lidar_and_ego_pose (first_lidar_token : str , nusc : nuscenes .NuScenes ) -> None :
83+
84+ def log_lidar_and_ego_pose (first_lidar_token : str , nusc : nuscenes .NuScenes , max_timestamp_us : float ) -> None :
8285 """Log lidar data and vehicle pose."""
8386 current_lidar_token = first_lidar_token
8487
8588 while current_lidar_token != "" :
8689 sample_data = nusc .get ("sample_data" , current_lidar_token )
8790 sensor_name = sample_data ["channel" ]
8891
92+ if max_timestamp_us < sample_data ["timestamp" ]:
93+ break
94+
8995 # timestamps are in microseconds
9096 rr .set_time_seconds ("timestamp" , sample_data ["timestamp" ] * 1e-6 )
9197
@@ -109,25 +115,29 @@ def log_lidar_and_ego_pose(first_lidar_token: str, nusc: nuscenes.NuScenes) -> N
109115 rr .log (f"world/ego_vehicle/{ sensor_name } " , rr .Points3D (points , colors = point_colors ))
110116
111117
112- def log_cameras (first_camera_tokens : list [str ], nusc : nuscenes .NuScenes ) -> None :
118+ def log_cameras (first_camera_tokens : list [str ], nusc : nuscenes .NuScenes , max_timestamp_us : float ) -> None :
113119 """Log camera data."""
114120 for first_camera_token in first_camera_tokens :
115121 current_camera_token = first_camera_token
116122 while current_camera_token != "" :
117123 sample_data = nusc .get ("sample_data" , current_camera_token )
124+ if max_timestamp_us < sample_data ["timestamp" ]:
125+ break
118126 sensor_name = sample_data ["channel" ]
119127 rr .set_time_seconds ("timestamp" , sample_data ["timestamp" ] * 1e-6 )
120128 data_file_path = nusc .dataroot / sample_data ["filename" ]
121129 rr .log (f"world/ego_vehicle/{ sensor_name } " , rr .ImageEncoded (path = data_file_path ))
122130 current_camera_token = sample_data ["next" ]
123131
124132
125- def log_radars (first_radar_tokens : list [str ], nusc : nuscenes .NuScenes ) -> None :
133+ def log_radars (first_radar_tokens : list [str ], nusc : nuscenes .NuScenes , max_timestamp_us : float ) -> None :
126134 """Log radar data."""
127135 for first_radar_token in first_radar_tokens :
128136 current_camera_token = first_radar_token
129137 while current_camera_token != "" :
130138 sample_data = nusc .get ("sample_data" , current_camera_token )
139+ if max_timestamp_us < sample_data ["timestamp" ]:
140+ break
131141 sensor_name = sample_data ["channel" ]
132142 rr .set_time_seconds ("timestamp" , sample_data ["timestamp" ] * 1e-6 )
133143 data_file_path = nusc .dataroot / sample_data ["filename" ]
@@ -139,14 +149,16 @@ def log_radars(first_radar_tokens: list[str], nusc: nuscenes.NuScenes) -> None:
139149 current_camera_token = sample_data ["next" ]
140150
141151
142- def log_annotations (first_sample_token : str , nusc : nuscenes .NuScenes ) -> None :
152+ def log_annotations (first_sample_token : str , nusc : nuscenes .NuScenes , max_timestamp_us : float ) -> None :
143153 """Log 3D bounding boxes."""
144154 label2id : dict [str , int ] = {}
145155 current_sample_token = first_sample_token
146156 while current_sample_token != "" :
147- sample = nusc .get ("sample" , current_sample_token )
148- rr .set_time_seconds ("timestamp" , sample ["timestamp" ] * 1e-6 )
149- ann_tokens = sample ["anns" ]
157+ sample_data = nusc .get ("sample" , current_sample_token )
158+ if max_timestamp_us < sample_data ["timestamp" ]:
159+ break
160+ rr .set_time_seconds ("timestamp" , sample_data ["timestamp" ] * 1e-6 )
161+ ann_tokens = sample_data ["anns" ]
150162 sizes = []
151163 centers = []
152164 rotations = []
@@ -164,7 +176,7 @@ def log_annotations(first_sample_token: str, nusc: nuscenes.NuScenes) -> None:
164176 class_ids .append (label2id [ann ["category_name" ]])
165177
166178 rr .log ("world/anns" , rr .Boxes3D (sizes = sizes , centers = centers , rotations = rotations , class_ids = class_ids ))
167- current_sample_token = sample ["next" ]
179+ current_sample_token = sample_data ["next" ]
168180
169181 # skipping for now since labels take too much space in 3D view (see https://github.com/rerun-io/rerun/issues/4451)
170182 # annotation_context = [(i, label) for label, i in label2id.items()]
@@ -213,13 +225,16 @@ def main() -> None:
213225 help = "Scene name to visualize (typically of form 'scene-xxxx')" ,
214226 )
215227 parser .add_argument ("--dataset-version" , type = str , default = "v1.0-mini" , help = "Scene id to visualize" )
228+ parser .add_argument (
229+ "--seconds" , type = float , default = float ("inf" ), help = "If specified, limits the number of seconds logged"
230+ )
216231 rr .script_add_args (parser )
217232 args = parser .parse_args ()
218233
219234 ensure_scene_available (args .root_dir , args .dataset_version , args .scene_name )
220235
221236 rr .script_setup (args , "rerun_example_nuscenes" )
222- log_nuscenes (args .root_dir , args .dataset_version , args .scene_name )
237+ log_nuscenes (args .root_dir , args .dataset_version , args .scene_name , max_time_sec = args . seconds )
223238
224239 rr .script_teardown (args )
225240
0 commit comments