Skip to content

Commit

Permalink
feat(t4-devkit): remove SensorChannel and replace it by str (#132)
Browse files Browse the repository at this point in the history
* feat: remove `SensorChannel` and replace it with `str`

Signed-off-by: ktro2828 <[email protected]>

* docs: update documents

Signed-off-by: ktro2828 <[email protected]>

* fix: invalid method access

Signed-off-by: ktro2828 <[email protected]>

---------

Signed-off-by: ktro2828 <[email protected]>
  • Loading branch information
ktro2828 authored Jul 26, 2024
1 parent 7ab892a commit 2698f8f
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 144 deletions.
4 changes: 2 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions t4-devkit/docs/apis/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

::: t4_devkit.schema.tables
options:
filters: ["!SchemaBase", "!FileFormat", "!SensorModality", "!SensorChannel", "!VisibilityLevel"]
filters: ["!SchemaBase", "!FileFormat", "!SensorModality", "!VisibilityLevel"]
show_root_toc_entry: false
merge_init_into_class: false
show_signature_annotations: false
Expand All @@ -34,7 +34,7 @@

::: t4_devkit.schema.tables
options:
members: ["FileFormat", "SensorModality", "SensorChannel", "VisibilityLevel"]
members: ["FileFormat", "SensorModality", "VisibilityLevel"]
show_root_toc_entry: false
merge_init_into_class: false
show_signature_annotations: false
Expand Down
7 changes: 3 additions & 4 deletions t4-devkit/docs/tutorials/initialize.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ data/tier4/
│   ├── CAM_FRONT_LEFT
│   ├── CAM_FRONT_RIGHT
│   ├── LIDAR_CONCAT
│   └── ...Other sensor channels (must be defined in `SensorChannel`)
│   └── ...Other sensor channels
...
```

Expand Down Expand Up @@ -71,7 +71,7 @@ Done loading in 0.061 seconds.
```

You can access to the `sample_data` associated with this `sample`.
`sample.data` returns a `dict` object consists of `{SensorChannel: <SAMPLE_DATA_TOKEN (str)>}`.
`sample.data` returns a `dict` object consists of `{str: <SAMPLE_DATA_TOKEN (str)>}`.

```python
>>> my_sample.data
Expand All @@ -82,8 +82,7 @@ You can access to the `sample_data` associated with this `sample`.
`sample_data` is references to a family of data that is collected from specific sensors.

```python
from t4_devkit.schema import SensorChannel
>>> sensor = SensorChannel.CAM_FRONT # "CAM_FRONT": <str> is also available
>>> sensor = "CAM_FRONT"
>>> t4.get("sample_data", my_sample.data[sensor])
```

Expand Down
9 changes: 3 additions & 6 deletions t4-devkit/t4_devkit/schema/tables/sample.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
from __future__ import annotations

from dataclasses import dataclass, field
from typing import TYPE_CHECKING, Any
from typing import Any

from typing_extensions import Self

from .base import SchemaBase
from .registry import SCHEMAS
from ..name import SchemaName

if TYPE_CHECKING:
from .sensor import SensorChannel

__all__ = ("Sample",)


Expand All @@ -29,7 +26,7 @@ class Sample(SchemaBase):
Shortcuts:
---------
data (dict[SensorChannel, str]): Sensor channel and its token.
data (dict[str, str]): Sensor channel and its token.
This should be set after instantiated.
ann_3ds (list[str]): List of foreign keys pointing the sample annotations.
This should be set after instantiated.
Expand All @@ -44,7 +41,7 @@ class Sample(SchemaBase):
prev: str

# shortcuts
data: dict[SensorChannel, str] = field(default_factory=dict, init=False)
data: dict[str, str] = field(default_factory=dict, init=False)
ann_3ds: list[str] = field(default_factory=list, init=False)
ann_2ds: list[str] = field(default_factory=list, init=False)

Expand Down
6 changes: 3 additions & 3 deletions t4-devkit/t4_devkit/schema/tables/sample_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class StrEnum(str, Enum):
from enum import StrEnum

if TYPE_CHECKING:
from .sensor import SensorChannel, SensorModality
from .sensor import SensorModality

__all__ = ("SampleData", "FileFormat")

Expand Down Expand Up @@ -97,7 +97,7 @@ class SampleData(SchemaBase):
Shortcuts:
---------
modality (SensorModality): Sensor modality. This should be set after instantiated.
channel (SensorChannel): Sensor channel. This should be set after instantiated.
channel (str): Sensor channel. This should be set after instantiated.
"""

token: str
Expand All @@ -116,7 +116,7 @@ class SampleData(SchemaBase):

# shortcuts
modality: SensorModality = field(init=False)
channel: SensorChannel = field(init=False)
channel: str = field(init=False)

@staticmethod
def shortcuts() -> tuple[str, str]:
Expand Down
59 changes: 4 additions & 55 deletions t4-devkit/t4_devkit/schema/tables/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class StrEnum(str, Enum):
from enum import StrEnum


__all__ = ("Sensor", "SensorModality", "SensorChannel")
__all__ = ("Sensor", "SensorModality")


class SensorModality(StrEnum):
Expand All @@ -37,76 +37,25 @@ class SensorModality(StrEnum):
RADAR = "radar"


class SensorChannel(StrEnum):
"""An enum to represent sensor channels.
Attributes:
CAM_FRONT: Front center camera.
CAM_FRONT_RIGHT: Front right camera.
CAM_FRONT_LEFT: Front left camera.
CAM_BACK: Back center camera.
CAM_BACK_RIGHT: Back right camera.
CAM_BACK_LEFT: Back left camera.
CAM_TRAFFIC_LIGHT_NEAR: Camera for nearer traffic light recognition.
CAM_TRAFFIC_LIGHT_FAR: Camera for farther traffic light recognition.
LIDAR_TOP: Top lidar.
LIDAR_CONCAT: Concatenated lidar.
RADAR_FRONT: Front center radar.
RADAR_FRONT_RIGHT: Front right radar.
RADAR_FRONT_LEFT: Front left radar.
RADAR_BACK: Back center radar.
RADAR_BACK_RIGHT: Back right radar.
RADAR_BACK_LEFT: Back left radar.
"""

CAM_FRONT = "CAM_FRONT"
CAM_FRONT_RIGHT = "CAM_FRONT_RIGHT"
CAM_FRONT_LEFT = "CAM_FRONT_LEFT"
CAM_BACK = "CAM_BACK"
CAM_BACK_RIGHT = "CAM_BACK_RIGHT"
CAM_BACK_LEFT = "CAM_BACK_LEFT"
CAM_TRAFFIC_LIGHT_NEAR = "CAM_TRAFFIC_LIGHT_NEAR"
CAM_TRAFFIC_LIGHT_FAR = "CAM_TRAFFIC_LIGHT_FAR"
LIDAR_TOP = "LIDAR_TOP"
LIDAR_CONCAT = "LIDAR_CONCAT"
RADAR_FRONT = "RADAR_FRONT"
RADAR_FRONT_RIGHT = "RADAR_FRONT_RIGHT"
RADAR_FRONT_LEFT = "RADAR_FRONT_LEFT"
RADAR_BACK = "RADAR_BACK"
RADAR_BACK_RIGHT = "RADAR_BACK_RIGHT"
RADAR_BACK_LEFT = "RADAR_BACK_LEFT"

@property
def modality(self) -> SensorModality:
if "CAM" in self:
return SensorModality.CAMERA
elif "LIDAR" in self:
return SensorModality.LIDAR
elif "RADAR" in self:
return SensorModality.RADAR
else:
raise ValueError(f"Cannot find modality for {self.value}")


@dataclass
@SCHEMAS.register(SchemaName.SENSOR)
class Sensor(SchemaBase):
"""A dataclass to represent schema table of `sensor.json`.
Attributes:
token (str): Unique record identifier.
channel (SensorChannel): Sensor channel name.
channel (str): Sensor channel name.
modality (SensorModality): Sensor modality.
"""

token: str
channel: SensorChannel
channel: str
modality: SensorModality

@classmethod
def from_dict(cls, data: dict[str, Any]) -> Self:
token: str = data["token"]
channel = SensorChannel(data["channel"])
channel = data["channel"]
modality = SensorModality(data["modality"])

return cls(token=token, channel=channel, modality=modality)
Loading

0 comments on commit 2698f8f

Please sign in to comment.