Skip to content

Commit

Permalink
feat: implement OtherSensor.from_json()
Browse files Browse the repository at this point in the history
  • Loading branch information
unexcellent committed Nov 11, 2024
1 parent 6885445 commit a3a9da0
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
2 changes: 2 additions & 0 deletions raillabel/format/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -41,6 +42,7 @@
"Metadata",
"Num",
"Object",
"OtherSensor",
"Point2d",
"Point3d",
"Poly2d",
Expand Down
8 changes: 8 additions & 0 deletions raillabel/format/other_sensor.py
Original file line number Diff line number Diff line change
@@ -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."""
5 changes: 4 additions & 1 deletion raillabel/format/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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)

Expand Down
46 changes: 46 additions & 0 deletions tests/test_raillabel/format/test_other_sensor.py
Original file line number Diff line number Diff line change
@@ -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"])

0 comments on commit a3a9da0

Please sign in to comment.