Skip to content

Commit ce28849

Browse files
committed
assert image dict and add get_mcap_attachment_names function to show all available names
1 parent 4594a3f commit ce28849

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

utils/utils.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ def __getitem__(self, index):
176176
image_dict = get_mcap_image(
177177
dataset_path, self.camera_names, self.mcap_camera_topics, start_ts
178178
)
179+
if len(image_dict) != len(self.camera_names):
180+
raise RuntimeError(
181+
f"Available attachment names are {get_mcap_attachment_names(dataset_path)} but expected: {self.mcap_camera_topics}."
182+
)
179183
bias = self.action_bias
180184
action_start = max(0, start_ts - bias)
181185
action = get_mcap_action(
@@ -574,6 +578,19 @@ def get_mcap_image(
574578
return res
575579

576580

581+
def get_mcap_attachment_names(mcap_file_path: str) -> List[str]:
582+
"""Extract attachment names from a MCAP file."""
583+
file_path = Path(mcap_file_path)
584+
if not file_path.exists():
585+
raise FileNotFoundError(f"MCAP file {file_path.absolute()} not found")
586+
names = []
587+
with file_path.open("rb") as f:
588+
reader = make_reader(f)
589+
for attach in reader.iter_attachments():
590+
names.append(attach.name)
591+
return names
592+
593+
577594
def get_time_index(mcap_file_path: str) -> List[int]:
578595
"""Extract time index from a MCAP file."""
579596
file_path = Path(mcap_file_path)

0 commit comments

Comments
 (0)