From 52526107cd0b5a45621bf22102c4eb489869f6fb Mon Sep 17 00:00:00 2001 From: Tobias Klockau Date: Mon, 9 Dec 2024 10:15:36 +0100 Subject: [PATCH] feat: make uri field optional for JSONStreamRadar and JSONStreamCamera --- raillabel/json_format/stream_camera.py | 2 +- raillabel/json_format/stream_radar.py | 2 +- tests/scene_builder/test_scene_builder.py | 194 ++++++++++++++-------- 3 files changed, 126 insertions(+), 72 deletions(-) diff --git a/raillabel/json_format/stream_camera.py b/raillabel/json_format/stream_camera.py index fbcd980..f1933dd 100644 --- a/raillabel/json_format/stream_camera.py +++ b/raillabel/json_format/stream_camera.py @@ -20,7 +20,7 @@ class JSONStreamCamera(_JSONFormatBase): stream_properties: JSONStreamCameraProperties "Intrinsic calibration of the stream." - uri: str + uri: str | None = None "A string encoding the subdirectory containing the sensor files." description: str | None = None diff --git a/raillabel/json_format/stream_radar.py b/raillabel/json_format/stream_radar.py index 67dfceb..cdec254 100644 --- a/raillabel/json_format/stream_radar.py +++ b/raillabel/json_format/stream_radar.py @@ -20,7 +20,7 @@ class JSONStreamRadar(_JSONFormatBase): stream_properties: JSONStreamRadarProperties "Intrinsic calibration of the stream." - uri: str + uri: str | None = None "A string encoding the subdirectory containing the sensor files." description: str | None = None diff --git a/tests/scene_builder/test_scene_builder.py b/tests/scene_builder/test_scene_builder.py index 16c1c52..223077e 100644 --- a/tests/scene_builder/test_scene_builder.py +++ b/tests/scene_builder/test_scene_builder.py @@ -146,6 +146,8 @@ def test_add_object__object_id_iteration(): def test_add_sensor__camera_rgb(camera_empty): actual = SceneBuilder.empty().add_sensor("rgb_middle").result + + actual.to_json() assert actual == Scene( metadata=Metadata(schema_version="1.0.0"), sensors={"rgb_middle": camera_empty}, @@ -153,59 +155,71 @@ def test_add_sensor__camera_rgb(camera_empty): def test_add_sensor__camera_ir(camera_empty): - actual = SceneBuilder.empty().add_sensor("ir_left") - assert actual.result == Scene( + actual = SceneBuilder.empty().add_sensor("ir_left").result + + actual.to_json() # check if scene is also valid in JSON + assert actual == Scene( metadata=Metadata(schema_version="1.0.0"), sensors={"ir_left": camera_empty}, ) def test_add_sensor__radar(radar_empty): - actual = SceneBuilder.empty().add_sensor("radar") - assert actual.result == Scene( + actual = SceneBuilder.empty().add_sensor("radar").result + + actual.to_json() # check if scene is also valid in JSON + assert actual == Scene( metadata=Metadata(schema_version="1.0.0"), sensors={"radar": radar_empty}, ) def test_add_sensor__lidar(): - actual = SceneBuilder.empty().add_sensor("lidar") - assert actual.result == Scene( - metadata=Metadata(schema_version="1.0.0"), sensors={"lidar": Lidar()} - ) + actual = SceneBuilder.empty().add_sensor("lidar").result + + actual.to_json() # check if scene is also valid in JSON + assert actual == Scene(metadata=Metadata(schema_version="1.0.0"), sensors={"lidar": Lidar()}) def test_add_sensor__gps_imu(): - actual = SceneBuilder.empty().add_sensor("gps_imu") - assert actual.result == Scene( - metadata=Metadata(schema_version="1.0.0"), sensors={"gps_imu": GpsImu()} - ) + actual = SceneBuilder.empty().add_sensor("gps_imu").result + + actual.to_json() # check if scene is also valid in JSON + assert actual == Scene(metadata=Metadata(schema_version="1.0.0"), sensors={"gps_imu": GpsImu()}) def test_add_sensor__other(): - actual = SceneBuilder.empty().add_sensor("SOMETHING_ELSE") - assert actual.result == Scene( + actual = SceneBuilder.empty().add_sensor("SOMETHING_ELSE").result + + actual.to_json() # check if scene is also valid in JSON + assert actual == Scene( metadata=Metadata(schema_version="1.0.0"), sensors={"SOMETHING_ELSE": OtherSensor()} ) def test_add_frame(): - actual = SceneBuilder.empty().add_frame(1, 1631691173) - assert actual.result == Scene( + actual = SceneBuilder.empty().add_frame(1, 1631691173).result + + actual.to_json() # check if scene is also valid in JSON + assert actual == Scene( metadata=Metadata(schema_version="1.0.0"), frames={1: Frame(timestamp=Decimal(1631691173))} ) def test_add_frame__no_timestamp(): - actual = SceneBuilder.empty().add_frame(1) - assert actual.result == Scene( + actual = SceneBuilder.empty().add_frame(1).result + + actual.to_json() # check if scene is also valid in JSON + assert actual == Scene( metadata=Metadata(schema_version="1.0.0"), frames={1: Frame(timestamp=None)} ) def test_add_frame__no_frame_id(): - actual = SceneBuilder.empty().add_frame().add_frame() - assert actual.result == Scene( + actual = SceneBuilder.empty().add_frame().add_frame().result + + actual.to_json() # check if scene is also valid in JSON + assert actual == Scene( metadata=Metadata(schema_version="1.0.0"), frames={ 1: Frame(), @@ -215,14 +229,20 @@ def test_add_frame__no_frame_id(): def test_add_bbox(camera_empty): - actual = SceneBuilder.empty().add_bbox( - uid=UUID("6c95543d-4d4f-43df-a52d-36bf868e09d8"), - frame_id=2, - object_name="person_0001", - sensor_id="ir_middle", - attributes={"attr": True}, - ) - assert actual.result == Scene( + actual = ( + SceneBuilder.empty() + .add_bbox( + uid=UUID("6c95543d-4d4f-43df-a52d-36bf868e09d8"), + frame_id=2, + object_name="person_0001", + sensor_id="ir_middle", + attributes={"attr": True}, + ) + .result + ) + + actual.to_json() # check if scene is also valid in JSON + assert actual == Scene( metadata=Metadata(schema_version="1.0.0"), objects={ UUID("5c59aad4-0000-4000-0000-000000000000"): Object(name="person_0001", type="person") @@ -245,8 +265,10 @@ def test_add_bbox(camera_empty): def test_add_bbox__just_defaults(camera_empty): - actual = SceneBuilder.empty().add_bbox() - assert actual.result == Scene( + actual = SceneBuilder.empty().add_bbox().result + + actual.to_json() # check if scene is also valid in JSON + assert actual == Scene( metadata=Metadata(schema_version="1.0.0"), objects={ UUID("5c59aad4-0000-4000-0000-000000000000"): Object(name="person_0001", type="person") @@ -269,14 +291,20 @@ def test_add_bbox__just_defaults(camera_empty): def test_add_cuboid(): - actual = SceneBuilder.empty().add_cuboid( - uid=UUID("6c95543d-4d4f-43df-a52d-36bf868e09d8"), - frame_id=2, - object_name="person_0001", - sensor_id="lidar_left", - attributes={"my_attr": 5}, - ) - assert actual.result == Scene( + actual = ( + SceneBuilder.empty() + .add_cuboid( + uid=UUID("6c95543d-4d4f-43df-a52d-36bf868e09d8"), + frame_id=2, + object_name="person_0001", + sensor_id="lidar_left", + attributes={"my_attr": 5}, + ) + .result + ) + + actual.to_json() # check if scene is also valid in JSON + assert actual == Scene( metadata=Metadata(schema_version="1.0.0"), objects={ UUID("5c59aad4-0000-4000-0000-000000000000"): Object(name="person_0001", type="person") @@ -300,8 +328,10 @@ def test_add_cuboid(): def test_add_cuboid__just_defaults(): - actual = SceneBuilder.empty().add_cuboid() - assert actual.result == Scene( + actual = SceneBuilder.empty().add_cuboid().result + + actual.to_json() # check if scene is also valid in JSON + assert actual == Scene( metadata=Metadata(schema_version="1.0.0"), objects={ UUID("5c59aad4-0000-4000-0000-000000000000"): Object(name="person_0001", type="person") @@ -325,14 +355,20 @@ def test_add_cuboid__just_defaults(): def test_add_poly2d(camera_empty): - actual = SceneBuilder.empty().add_poly2d( - uid=UUID("6c95543d-4d4f-43df-a52d-36bf868e09d8"), - frame_id=2, - object_name="person_0001", - sensor_id="ir_left", - attributes={"my_attr": 5}, - ) - assert actual.result == Scene( + actual = ( + SceneBuilder.empty() + .add_poly2d( + uid=UUID("6c95543d-4d4f-43df-a52d-36bf868e09d8"), + frame_id=2, + object_name="person_0001", + sensor_id="ir_left", + attributes={"my_attr": 5}, + ) + .result + ) + + actual.to_json() # check if scene is also valid in JSON + assert actual == Scene( metadata=Metadata(schema_version="1.0.0"), objects={ UUID("5c59aad4-0000-4000-0000-000000000000"): Object(name="person_0001", type="person") @@ -355,8 +391,10 @@ def test_add_poly2d(camera_empty): def test_add_poly2d__just_defaults(camera_empty): - actual = SceneBuilder.empty().add_poly2d() - assert actual.result == Scene( + actual = SceneBuilder.empty().add_poly2d().result + + actual.to_json() # check if scene is also valid in JSON + assert actual == Scene( metadata=Metadata(schema_version="1.0.0"), objects={ UUID("5c59aad4-0000-4000-0000-000000000000"): Object(name="person_0001", type="person") @@ -379,14 +417,20 @@ def test_add_poly2d__just_defaults(camera_empty): def test_add_poly3d(): - actual = SceneBuilder.empty().add_poly3d( - uid=UUID("6c95543d-4d4f-43df-a52d-36bf868e09d8"), - frame_id=2, - object_name="person_0001", - sensor_id="lidar_right", - attributes={"my_attr": 5}, - ) - assert actual.result == Scene( + actual = ( + SceneBuilder.empty() + .add_poly3d( + uid=UUID("6c95543d-4d4f-43df-a52d-36bf868e09d8"), + frame_id=2, + object_name="person_0001", + sensor_id="lidar_right", + attributes={"my_attr": 5}, + ) + .result + ) + + actual.to_json() # check if scene is also valid in JSON + assert actual == Scene( metadata=Metadata(schema_version="1.0.0"), objects={ UUID("5c59aad4-0000-4000-0000-000000000000"): Object(name="person_0001", type="person") @@ -409,8 +453,10 @@ def test_add_poly3d(): def test_add_poly3d__just_defaults(): - actual = SceneBuilder.empty().add_poly3d() - assert actual.result == Scene( + actual = SceneBuilder.empty().add_poly3d().result + + actual.to_json() # check if scene is also valid in JSON + assert actual == Scene( metadata=Metadata(schema_version="1.0.0"), objects={ UUID("5c59aad4-0000-4000-0000-000000000000"): Object(name="person_0001", type="person") @@ -433,14 +479,20 @@ def test_add_poly3d__just_defaults(): def test_add_seg3d(): - actual = SceneBuilder.empty().add_seg3d( - uid=UUID("6c95543d-4d4f-43df-a52d-36bf868e09d8"), - frame_id=2, - object_name="person_0001", - sensor_id="lidar_right", - attributes={"my_attr": 5}, - ) - assert actual.result == Scene( + actual = ( + SceneBuilder.empty() + .add_seg3d( + uid=UUID("6c95543d-4d4f-43df-a52d-36bf868e09d8"), + frame_id=2, + object_name="person_0001", + sensor_id="lidar_right", + attributes={"my_attr": 5}, + ) + .result + ) + + actual.to_json() # check if scene is also valid in JSON + assert actual == Scene( metadata=Metadata(schema_version="1.0.0"), objects={ UUID("5c59aad4-0000-4000-0000-000000000000"): Object(name="person_0001", type="person") @@ -462,8 +514,10 @@ def test_add_seg3d(): def test_add_seg3d__just_defaults(): - actual = SceneBuilder.empty().add_seg3d() - assert actual.result == Scene( + actual = SceneBuilder.empty().add_seg3d().result + + actual.to_json() # check if scene is also valid in JSON + assert actual == Scene( metadata=Metadata(schema_version="1.0.0"), objects={ UUID("5c59aad4-0000-4000-0000-000000000000"): Object(name="person_0001", type="person")