Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ncore/impl/data/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def transform(
# (backwards polynomial is a pixel-distance to angle map, so the domain needs to be scaled).
# Potentially anisotropic scaling is handled by the linear term.
scaled_pixel_map = np.polynomial.Polynomial([0.0, 1.0 / image_domain_scale_factors[1]])
pixeldist_to_angle_poly = np.polynomial.Polynomial(self.pixeldist_to_angle_poly)(scaled_pixel_map).coef.astype( # type: ignore
pixeldist_to_angle_poly = np.polynomial.Polynomial(self.pixeldist_to_angle_poly)(scaled_pixel_map).coef.astype(
np.float32
)

Expand Down
6 changes: 3 additions & 3 deletions ncore/impl/data/v4/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ def _get_frame_group(
"""Returns the group of a frame, initializing it if required"""

if isinstance(timestamps_us, np.ndarray):
frame_id = timestamps_us[1].item() # end-of-frame timestamp is frame ID
frame_id = cast(np.ndarray, timestamps_us)[1].item() # end-of-frame timestamp is frame ID
else:
frame_id = timestamps_us

Expand Down Expand Up @@ -1081,7 +1081,7 @@ def _get_frame_group(
"""Returns the group of a frame"""

if isinstance(timestamps_us, np.ndarray):
frame_id = timestamps_us[1].item() # end-of-frame timestamp is frame ID
frame_id = cast(np.ndarray, timestamps_us)[1].item() # end-of-frame timestamp is frame ID
else:
frame_id = timestamps_us

Expand Down Expand Up @@ -1251,7 +1251,7 @@ def get_frame_ray_bundle_return_count(self, timestamp_us: int) -> int:
def get_frame_ray_bundle_return_data_names(self, timestamp_us: int) -> List[str]:
"""List of all ray bundle return data names for a frame"""

return list(cast(zarr.Group, self._get_ray_bundle_returns_group(timestamp_us)).keys())
return list(self._get_ray_bundle_returns_group(timestamp_us).keys())

def has_frame_ray_bundle_return_data(self, timestamp_us: int, name: str) -> bool:
"""Signals if named ray bundle return data exists for a frame"""
Expand Down
30 changes: 19 additions & 11 deletions ncore/impl/data/v4/components_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import tempfile
import unittest

from typing import Dict, Literal, Tuple
from typing import Dict, Literal, Tuple, cast

import numpy as np
import PIL.Image as PILImage
Expand Down Expand Up @@ -87,7 +87,7 @@ def test_reload(self, store_type, open_consolidated):
ref_sequence_timestamp_interval_us := HalfClosedInterval(int(0 * 1e6), int(1 * 1e6) + 1)
),
store_type=store_type,
generic_meta_data=(ref_generic_sequence_meta_data := {"some": 1, "key": 1.2}),
generic_meta_data=cast(Dict[str, JsonLike], ref_generic_sequence_meta_data := {"some": 1, "key": 1.2}),
)

# Store pose / extrinsics
Expand Down Expand Up @@ -166,7 +166,7 @@ def test_reload(self, store_type, open_consolidated):
PosesComponent.Writer,
ref_poses_id := "some_poses_type",
group_name=None, # use default component group
generic_meta_data=(ref_pose_generic_meta_data := {"some": "thing"}),
generic_meta_data=cast(Dict[str, JsonLike], ref_pose_generic_meta_data := {"some": "thing"}),
).store_dynamic_pose(
source_frame_id="rig",
target_frame_id="world",
Expand Down Expand Up @@ -364,7 +364,9 @@ def test_reload(self, store_type, open_consolidated):
"png",
ref_camera_timestamps_us0 := np.array([0 * 1e6, 0.1 * 1e6], dtype=np.uint64),
ref_camera_generic_data0 := {"some-frame-data": np.random.rand(6, 2)},
ref_camera_generic_metadata0 := {"some-frame-meta-data": {"something": 1, "else": 2}},
ref_camera_generic_metadata0 := cast(
Dict[str, JsonLike], {"some-frame-meta-data": {"something": 1, "else": 2}}
),
)

with io.BytesIO() as buffer:
Expand All @@ -377,7 +379,9 @@ def test_reload(self, store_type, open_consolidated):
"png",
ref_camera_timestamps_us1 := np.array([0.1 * 1e6, 0.2 * 1e6], dtype=np.uint64),
ref_camera_generic_data1 := {"some-frame-data": np.random.rand(6, 2)},
ref_camera_generic_metadata1 := {"some-more-frame-meta-data": {"even": True, "more": None}},
ref_camera_generic_metadata1 := cast(
Dict[str, JsonLike], {"some-more-frame-meta-data": {"even": True, "more": None}}
),
)

# Store lidar data
Expand All @@ -402,7 +406,9 @@ def normalize_points(vectors: np.ndarray) -> Tuple[np.ndarray, np.ndarray]:
ref_lidar_intensity0 := np.random.rand(1, 5).astype(np.float32),
ref_lidar_timestamps_us0 := np.array([0 * 1e6, 0.5 * 1e6], dtype=np.uint64),
ref_lidar_generic_data0 := {"some-other-frame-data": np.random.rand(6, 2)},
ref_lidar_generic_metadata0 := {"some-more-meta-data": {"yes": None, "no": True}},
ref_lidar_generic_metadata0 := cast(
Dict[str, JsonLike], {"some-more-meta-data": {"yes": None, "no": True}}
),
)

ref_lidar_valid_mask0 = np.ones((1, 5), dtype=bool)
Expand Down Expand Up @@ -432,7 +438,7 @@ def normalize_points(vectors: np.ndarray) -> Tuple[np.ndarray, np.ndarray]:
ref_lidar_intensity1,
ref_lidar_timestamps_us1 := np.array([0.5 * 1e6, 1 * 1e6], dtype=np.uint64),
ref_lidar_generic_data1 := {"some-other-frame-data": np.random.rand(2, 2)},
ref_lidar_generic_metadata1 := {"even-more-meta-data": {"yesno": None}},
ref_lidar_generic_metadata1 := cast(Dict[str, JsonLike], {"even-more-meta-data": {"yesno": None}}),
)

# Store radar data
Expand All @@ -451,7 +457,9 @@ def normalize_points(vectors: np.ndarray) -> Tuple[np.ndarray, np.ndarray]:
ref_radar_distance_m0 := radar_distance_m0[np.newaxis, :],
ref_radar_timestamps_us0 := np.array([0.1 * 1e6, 0.1 * 1e6], dtype=np.uint64),
ref_radar_generic_data0 := {"some-other-frame-data": np.random.rand(6, 2)},
ref_radar_generic_metadata0 := {"some-more-meta-data": {"funny": "yes", "no": True}},
ref_radar_generic_metadata0 := cast(
Dict[str, JsonLike], {"some-more-meta-data": {"funny": "yes", "no": True}}
),
)

ref_radar_direction_m1, radar_distance_m1 = normalize_points(np.random.rand(8, 3).astype(np.float32) + 0.2)
Expand All @@ -462,7 +470,7 @@ def normalize_points(vectors: np.ndarray) -> Tuple[np.ndarray, np.ndarray]:
ref_radar_distance_m1 := np.stack((radar_distance_m1, radar_distance_m1 + 0.2)),
ref_radar_timestamps_us1 := np.array([0.2 * 1e6, 0.2 * 1e6], dtype=np.uint64),
ref_radar_generic_data1 := {"some-radar-frame-data": np.random.rand(6, 2)},
ref_radar_generic_metadata1 := {"some-more-meta-data": {"funny": ":("}},
ref_radar_generic_metadata1 := cast(Dict[str, JsonLike], {"some-more-meta-data": {"funny": ":("}}),
)

## Finalize writers up to here
Expand All @@ -481,7 +489,7 @@ def normalize_points(vectors: np.ndarray) -> Tuple[np.ndarray, np.ndarray]:
CuboidsComponent.Writer,
ref_cuboids_id := "default",
"cuboids",
ref_cuboids_generic_meta_data := {"track-set-meta-data": "some-value"},
ref_cuboids_generic_meta_data := cast(Dict[str, JsonLike], {"track-set-meta-data": "some-value"}),
)

ref_observation = CuboidTrackObservation(
Expand Down Expand Up @@ -1807,7 +1815,7 @@ def test_generic_data_and_metadata(self):
# generic_meta_data
loaded_gmd = reader.get_pc_generic_meta_data(0)
self.assertEqual(loaded_gmd["source"], "lidar_top")
self.assertAlmostEqual(loaded_gmd["quality"], 0.99)
self.assertAlmostEqual(cast(float, loaded_gmd["quality"]), 0.99)
self.assertEqual(loaded_gmd["tags"], ["outdoor", "sunny"])

tmpdir.cleanup()
Loading