Skip to content

Commit

Permalink
refactor: rename all *_uid fields to *_id
Browse files Browse the repository at this point in the history
  • Loading branch information
unexcellent committed Nov 13, 2024
1 parent f6bd567 commit 2fd4a60
Show file tree
Hide file tree
Showing 20 changed files with 129 additions and 129 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Release
- ```frame_data``` can only contain ```Num``` instances
- ```object_data``` can not contain ```Num``` instances anymore
- Major restructuring of the project directories
- ```FrameInterval.from_frame_uids()```: create ```FrameIntervals``` by providing a list of frame uids
- ```FrameInterval.from_frame_ids()```: create ```FrameIntervals``` by providing a list of frame uids
- ```Object.object_data_pointers()```: generate ```ElementDataPointers```
- ```Scene.frame_intervals()```, ```Object.frame_intervals()```: generate ```FrameIntervals```
- ```Object.asdict()``` now provides also frame intervals and object data pointers, if the frames from the scene are provided
Expand Down
6 changes: 3 additions & 3 deletions raillabel/format/bbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Bbox:
size: Size2d
"The dimensions of the bbox in pixels from the top left corner to the bottom right corner."

object_uid: UUID
object_id: UUID
"The uid of the object, this annotation belongs to."

sensor: str
Expand All @@ -33,12 +33,12 @@ class Bbox:
"Additional information associated with the annotation."

@classmethod
def from_json(cls, json: JSONBbox, object_uid: UUID) -> Bbox:
def from_json(cls, json: JSONBbox, object_id: UUID) -> Bbox:
"""Construct an instant of this class from RailLabel JSON data."""
return Bbox(
pos=Point2d.from_json((json.val[0], json.val[1])),
size=Size2d.from_json((json.val[2], json.val[3])),
object_uid=object_uid,
object_id=object_id,
sensor=json.coordinate_system,
attributes=_attributes_from_json(json.attributes),
)
Expand Down
6 changes: 3 additions & 3 deletions raillabel/format/cuboid.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Cuboid:
size: Size3d
"The size of the cuboid in meters."

object_uid: UUID
object_id: UUID
"The uid of the object, this annotation belongs to."

sensor: str
Expand All @@ -38,13 +38,13 @@ class Cuboid:
"Additional information associated with the annotation."

@classmethod
def from_json(cls, json: JSONCuboid, object_uid: UUID) -> Cuboid:
def from_json(cls, json: JSONCuboid, object_id: UUID) -> Cuboid:
"""Construct an instant of this class from RailLabel JSON data."""
return Cuboid(
pos=Point3d.from_json((json.val[0], json.val[1], json.val[2])),
quat=Quaternion.from_json((json.val[3], json.val[4], json.val[5], json.val[6])),
size=Size3d.from_json((json.val[7], json.val[8], json.val[9])),
object_uid=object_uid,
object_id=object_id,
sensor=json.coordinate_system,
attributes=_attributes_from_json(json.attributes),
)
Expand Down
12 changes: 6 additions & 6 deletions raillabel/format/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,21 @@ def _annotations_from_json(

annotations: dict[UUID, Bbox | Cuboid | Poly2d | Poly3d | Seg3d] = {}

for object_uid, object_data in json_object_data.items():
for object_id, object_data in json_object_data.items():
for json_bbox in _resolve_none_to_empty_list(object_data.bbox):
annotations[json_bbox.uid] = Bbox.from_json(json_bbox, object_uid)
annotations[json_bbox.uid] = Bbox.from_json(json_bbox, object_id)

for json_cuboid in _resolve_none_to_empty_list(object_data.cuboid):
annotations[json_cuboid.uid] = Cuboid.from_json(json_cuboid, object_uid)
annotations[json_cuboid.uid] = Cuboid.from_json(json_cuboid, object_id)

for json_poly2d in _resolve_none_to_empty_list(object_data.poly2d):
annotations[json_poly2d.uid] = Poly2d.from_json(json_poly2d, object_uid)
annotations[json_poly2d.uid] = Poly2d.from_json(json_poly2d, object_id)

for json_poly3d in _resolve_none_to_empty_list(object_data.poly3d):
annotations[json_poly3d.uid] = Poly3d.from_json(json_poly3d, object_uid)
annotations[json_poly3d.uid] = Poly3d.from_json(json_poly3d, object_id)

for json_seg3d in _resolve_none_to_empty_list(object_data.vec):
annotations[json_seg3d.uid] = Seg3d.from_json(json_seg3d, object_uid)
annotations[json_seg3d.uid] = Seg3d.from_json(json_seg3d, object_id)

return annotations

Expand Down
30 changes: 15 additions & 15 deletions raillabel/format/frame_interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,25 @@ def from_json(cls, json: JSONFrameInterval) -> FrameInterval:
)

@classmethod
def from_frame_uids(cls, frame_uids: list[int]) -> list[FrameInterval]:
def from_frame_ids(cls, frame_ids: list[int]) -> list[FrameInterval]:
"""Convert a list of frame uids into FrameIntervals.
Example:
-------
```python
FrameInterval.from_frame_uids([0, 1, 2, 3, 9, 12, 13, 14]) == [
FrameInterval.from_frame_ids([0, 1, 2, 3, 9, 12, 13, 14]) == [
FrameInterval(0, 3),
FrameInterval(9, 9),
FrameInterval(12, 14),
]
```
"""
sorted_frame_uids = sorted(frame_uids)
frame_uid_intervals = _slice_into_intervals(sorted_frame_uids)
sorted_frame_ids = sorted(frame_ids)
frame_id_intervals = _slice_into_intervals(sorted_frame_ids)

return [
FrameInterval(start=interval[0], end=interval[-1]) for interval in frame_uid_intervals
FrameInterval(start=interval[0], end=interval[-1]) for interval in frame_id_intervals
]

def to_json(self) -> JSONFrameInterval:
Expand All @@ -60,23 +60,23 @@ def __len__(self) -> int:
return abs(self.start - self.end) + 1


def _slice_into_intervals(sorted_frame_uids: list[int]) -> list[list[int]]:
if len(sorted_frame_uids) == 0:
def _slice_into_intervals(sorted_frame_ids: list[int]) -> list[list[int]]:
if len(sorted_frame_ids) == 0:
return []

if len(sorted_frame_uids) == 1:
return [sorted_frame_uids]
if len(sorted_frame_ids) == 1:
return [sorted_frame_ids]

intervals = []
interval_start_i = 0
for i, frame_uid in enumerate(sorted_frame_uids[1:]):
previous_frame_uid = sorted_frame_uids[i]
for i, frame_id in enumerate(sorted_frame_ids[1:]):
previous_frame_id = sorted_frame_ids[i]

if frame_uid - previous_frame_uid > 1:
intervals.append(sorted_frame_uids[interval_start_i : i + 1])
if frame_id - previous_frame_id > 1:
intervals.append(sorted_frame_ids[interval_start_i : i + 1])
interval_start_i = i + 1

intervals.append(sorted_frame_uids[interval_start_i : len(sorted_frame_uids)])
interval_start_i = len(sorted_frame_uids)
intervals.append(sorted_frame_ids[interval_start_i : len(sorted_frame_ids)])
interval_start_i = len(sorted_frame_ids)

return intervals
6 changes: 3 additions & 3 deletions raillabel/format/poly2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Poly2d:
closed: bool
"If True, this object represents a polygon and if False, it represents a polyline."

object_uid: UUID
object_id: UUID
"The uid of the object, this annotation belongs to."

sensor: str
Expand All @@ -32,15 +32,15 @@ class Poly2d:
"Additional information associated with the annotation."

@classmethod
def from_json(cls, json: JSONPoly2d, object_uid: UUID) -> Poly2d:
def from_json(cls, json: JSONPoly2d, object_id: UUID) -> Poly2d:
"""Construct an instant of this class from RailLabel JSON data."""
return Poly2d(
points=[
Point2d(x=float(json.val[i]), y=float(json.val[i + 1]))
for i in range(0, len(json.val), 2)
],
closed=json.closed,
object_uid=object_uid,
object_id=object_id,
sensor=json.coordinate_system,
attributes=_attributes_from_json(json.attributes),
)
Expand Down
6 changes: 3 additions & 3 deletions raillabel/format/poly3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Poly3d:
closed: bool
"If True, this object represents a polygon and if False, it represents a polyline."

object_uid: UUID
object_id: UUID
"The uid of the object, this annotation belongs to."

sensor: str
Expand All @@ -32,15 +32,15 @@ class Poly3d:
"Additional information associated with the annotation."

@classmethod
def from_json(cls, json: JSONPoly3d, object_uid: UUID) -> Poly3d:
def from_json(cls, json: JSONPoly3d, object_id: UUID) -> Poly3d:
"""Construct an instant of this class from RailLabel JSON data."""
return Poly3d(
points=[
Point3d(x=float(json.val[i]), y=float(json.val[i + 1]), z=float(json.val[i + 2]))
for i in range(0, len(json.val), 3)
],
closed=json.closed,
object_uid=object_uid,
object_id=object_id,
sensor=json.coordinate_system,
attributes=_attributes_from_json(json.attributes),
)
Expand Down
4 changes: 2 additions & 2 deletions raillabel/format/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ def _objects_from_json(json_objects: dict[UUID, JSONObject] | None) -> dict[UUID
if json_objects is None:
return {}

return {obj_uid: Object.from_json(json_obj) for obj_uid, json_obj in json_objects.items()}
return {obj_id: Object.from_json(json_obj) for obj_id, json_obj in json_objects.items()}


def _frames_from_json(json_frames: dict[int, JSONFrame] | None) -> dict[int, Frame]:
if json_frames is None:
return {}

return {frame_uid: Frame.from_json(json_frame) for frame_uid, json_frame in json_frames.items()}
return {frame_id: Frame.from_json(json_frame) for frame_id, json_frame in json_frames.items()}
6 changes: 3 additions & 3 deletions raillabel/format/seg3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Seg3d:
point_ids: list[int]
"The list of point indices."

object_uid: UUID
object_id: UUID
"The uid of the object, this annotation belongs to."

sensor: str
Expand All @@ -28,11 +28,11 @@ class Seg3d:
"Additional information associated with the annotation."

@classmethod
def from_json(cls, json: JSONVec, object_uid: UUID) -> Seg3d:
def from_json(cls, json: JSONVec, object_id: UUID) -> Seg3d:
"""Construct an instant of this class from RailLabel JSON data."""
return Seg3d(
point_ids=[int(point_id) for point_id in json.val],
object_uid=object_uid,
object_id=object_id,
sensor=json.coordinate_system,
attributes=_attributes_from_json(json.attributes),
)
Expand Down
42 changes: 21 additions & 21 deletions tests/__test_assets__/openlabel_v1_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
"description": "Name of the action. It is a friendly name and not used for indexing.",
"type": "string"
},
"ontology_uid": {
"ontology_id": {
"description": "This is the UID of the ontology where the type of this action is defined.",
"type": "string"
},
"resource_uid": {
"$ref": "#/definitions/resource_uid"
"resource_id": {
"$ref": "#/definitions/resource_id"
},
"type": {
"description": "The type of an action defines the class the action corresponds to.",
Expand Down Expand Up @@ -253,12 +253,12 @@
"description": "Name of the context. It is a friendly name and not used for indexing.",
"type": "string"
},
"ontology_uid": {
"ontology_id": {
"description": "This is the UID of the ontology where the type of this context is defined.",
"type": "string"
},
"resource_uid": {
"$ref": "#/definitions/resource_uid"
"resource_id": {
"$ref": "#/definitions/resource_id"
},
"type": {
"description": "The type of a context defines the class the context corresponds to.",
Expand Down Expand Up @@ -469,12 +469,12 @@
"description": "Name of the event. It is a friendly name and not used for indexing.",
"type": "string"
},
"ontology_uid": {
"ontology_id": {
"description": "This is the UID of the ontology where the type of this event is defined.",
"type": "string"
},
"resource_uid": {
"$ref": "#/definitions/resource_uid"
"resource_id": {
"$ref": "#/definitions/resource_id"
},
"type": {
"description": "The type of an event defines the class the event corresponds to.",
Expand Down Expand Up @@ -907,12 +907,12 @@
"object_data_pointers": {
"$ref": "#/definitions/element_data_pointers"
},
"ontology_uid": {
"ontology_id": {
"description": "This is the UID of the ontology where the type of this object is defined.",
"type": "string"
},
"resource_uid": {
"$ref": "#/definitions/resource_uid"
"resource_id": {
"$ref": "#/definitions/resource_id"
},
"type": {
"description": "The type of an object defines the class the object corresponds to.",
Expand Down Expand Up @@ -1427,7 +1427,7 @@
"description": "Name of the relation. It is a friendly name and not used for indexing.",
"type": "string"
},
"ontology_uid": {
"ontology_id": {
"description": "This is the UID of the ontology where the type of this relation is defined.",
"type": "string"
},
Expand All @@ -1445,8 +1445,8 @@
},
"type": "array"
},
"resource_uid": {
"$ref": "#/definitions/resource_uid"
"resource_id": {
"$ref": "#/definitions/resource_id"
},
"type": {
"description": "The type of a relation defines the class the predicated of the relation corresponds to.",
Expand All @@ -1461,8 +1461,8 @@
],
"type": "object"
},
"resource_uid": {
"description": "This is a JSON object that contains links to external resources. Resource_uid keys are strings containing numerical UIDs or 32 bytes UUIDs. Resource_uid values are strings describing the identifier of the element in the external resource.",
"resource_id": {
"description": "This is a JSON object that contains links to external resources. Resource_id keys are strings containing numerical UIDs or 32 bytes UUIDs. Resource_id values are strings describing the identifier of the element in the external resource.",
"patternProperties": {
"^(-?[0-9]+|[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$": {
"type": "string"
Expand Down Expand Up @@ -1652,12 +1652,12 @@
"additionalProperties": true,
"description": "A tag is a special type of label that can be attached to any type of content, such as images, data containers, folders. In ASAM OpenLABEL the main purpose of a tag is to allow adding metadata to scenario descriptions.",
"properties": {
"ontology_uid": {
"ontology_id": {
"description": "This is the UID of the ontology where the type of this tag is defined.",
"type": "string"
},
"resource_uid": {
"$ref": "#/definitions/resource_uid"
"resource_id": {
"$ref": "#/definitions/resource_id"
},
"tag_data": {
"$ref": "#/definitions/tag_data"
Expand All @@ -1668,7 +1668,7 @@
}
},
"required": [
"ontology_uid",
"ontology_id",
"type"
],
"type": "object"
Expand Down
14 changes: 7 additions & 7 deletions tests/test_raillabel/format/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Copyright DB InfraGO AG and contributors
# SPDX-License-Identifier: Apache-2.0
from .test_attributes import attributes_multiple_types, attributes_multiple_types_json
from .test_bbox import bbox, bbox_json, bbox_uid
from .test_bbox import bbox, bbox_json, bbox_id
from .test_camera import camera, camera_json
from .test_cuboid import cuboid, cuboid_json, cuboid_uid
from .test_cuboid import cuboid, cuboid_json, cuboid_id
from .test_frame import frame, frame_json
from .test_frame_interval import frame_interval, frame_interval_json
from .test_intrinsics_pinhole import intrinsics_pinhole, intrinsics_pinhole_json
Expand All @@ -14,20 +14,20 @@
from .test_object import (
object_person,
object_person_json,
object_person_uid,
object_person_id,
object_track,
object_track_json,
object_track_uid,
object_track_id,
)
from .test_point2d import point2d, point2d_json, another_point2d, another_point2d_json
from .test_point3d import point3d, point3d_json, another_point3d, another_point3d_json
from .test_poly2d import poly2d, poly2d_json, poly2d_uid
from .test_poly3d import poly3d, poly3d_json, poly3d_uid
from .test_poly2d import poly2d, poly2d_json, poly2d_id
from .test_poly3d import poly3d, poly3d_json, poly3d_id
from .test_quaternion import quaternion, quaternion_json
from .test_radar import radar, radar_json
from .test_size2d import size2d, size2d_json
from .test_size3d import size3d, size3d_json
from .test_seg3d import seg3d, seg3d_json, seg3d_uid
from .test_seg3d import seg3d, seg3d_json, seg3d_id
from .test_sensor_reference import (
another_sensor_reference,
another_sensor_reference_json,
Expand Down
Loading

0 comments on commit 2fd4a60

Please sign in to comment.