Skip to content

Commit

Permalink
feat: make uri field optional for JSONStreamRadar and JSONStreamCamera
Browse files Browse the repository at this point in the history
  • Loading branch information
tklockau committed Dec 9, 2024
1 parent 4158ba8 commit 5252610
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 72 deletions.
2 changes: 1 addition & 1 deletion raillabel/json_format/stream_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion raillabel/json_format/stream_radar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
194 changes: 124 additions & 70 deletions tests/scene_builder/test_scene_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,66 +146,80 @@ 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},
)


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(),
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand Down

0 comments on commit 5252610

Please sign in to comment.