From a3a9da048b0359c03bd5de5e524c3524825e61d5 Mon Sep 17 00:00:00 2001 From: unexcellent <> Date: Mon, 11 Nov 2024 20:21:32 +0100 Subject: [PATCH] feat: implement OtherSensor.from_json() --- raillabel/format/__init__.py | 2 + raillabel/format/other_sensor.py | 8 ++++ raillabel/format/scene.py | 5 +- .../format/test_other_sensor.py | 46 +++++++++++++++++++ 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 raillabel/format/other_sensor.py create mode 100644 tests/test_raillabel/format/test_other_sensor.py diff --git a/raillabel/format/__init__.py b/raillabel/format/__init__.py index cb56171..caab9fc 100644 --- a/raillabel/format/__init__.py +++ b/raillabel/format/__init__.py @@ -14,6 +14,7 @@ from .metadata import Metadata from .num import Num from .object import Object +from .other_sensor import OtherSensor from .point2d import Point2d from .point3d import Point3d from .poly2d import Poly2d @@ -41,6 +42,7 @@ "Metadata", "Num", "Object", + "OtherSensor", "Point2d", "Point3d", "Poly2d", diff --git a/raillabel/format/other_sensor.py b/raillabel/format/other_sensor.py new file mode 100644 index 0000000..385214c --- /dev/null +++ b/raillabel/format/other_sensor.py @@ -0,0 +1,8 @@ +# Copyright DB InfraGO AG and contributors +# SPDX-License-Identifier: Apache-2.0 + +from ._sensor_without_intrinsics import _SensorWithoutIntrinsics + + +class OtherSensor(_SensorWithoutIntrinsics): + """A sensor that is not represented by the available options.""" diff --git a/raillabel/format/scene.py b/raillabel/format/scene.py index 44ab918..d163de1 100644 --- a/raillabel/format/scene.py +++ b/raillabel/format/scene.py @@ -8,8 +8,11 @@ from .camera import Camera from .frame import Frame from .frame_interval import FrameInterval +from .gps_imu import GpsImu +from .lidar import Lidar from .metadata import Metadata from .object import Object +from .other_sensor import OtherSensor from .radar import Radar @@ -36,7 +39,7 @@ class Scene: """ metadata: Metadata - sensors: dict[str, Camera | Radar] = field(default_factory=dict) + sensors: dict[str, Camera | Lidar | Radar | GpsImu | OtherSensor] = field(default_factory=dict) objects: dict[str, Object] = field(default_factory=dict) frames: dict[int, Frame] = field(default_factory=dict) diff --git a/tests/test_raillabel/format/test_other_sensor.py b/tests/test_raillabel/format/test_other_sensor.py new file mode 100644 index 0000000..25e30b5 --- /dev/null +++ b/tests/test_raillabel/format/test_other_sensor.py @@ -0,0 +1,46 @@ +# Copyright DB InfraGO AG and contributors +# SPDX-License-Identifier: Apache-2.0 + +from __future__ import annotations + +import pytest + +from raillabel.format import OtherSensor +from raillabel.json_format import JSONCoordinateSystem, JSONStreamOther + +# == Fixtures ========================= + + +@pytest.fixture +def other_json(transform_json) -> tuple[JSONStreamOther, JSONCoordinateSystem]: + return ( + JSONStreamOther( + type="other", + uri="/path/to/sensor/data", + description="A very nice generic sensor", + ), + JSONCoordinateSystem( + parent="base", type="sensor", pose_wrt_parent=transform_json, children=[] + ), + ) + + +@pytest.fixture +def other(transform) -> dict: + return OtherSensor( + extrinsics=transform, + uri="/path/to/sensor/data", + description="A very nice generic sensor", + ) + + +# == Tests ============================ + + +def test_from_json(other, other_json): + actual = OtherSensor.from_json(other_json[0], other_json[1]) + assert actual == other + + +if __name__ == "__main__": + pytest.main([__file__, "--disable-pytest-warnings", "--cache-clear", "-v"])