diff --git a/tools/python_tools/cuvslam_tools/common/edex.py b/tools/python_tools/cuvslam_tools/common/edex.py index 9b84568f..63d1f76a 100644 --- a/tools/python_tools/cuvslam_tools/common/edex.py +++ b/tools/python_tools/cuvslam_tools/common/edex.py @@ -290,9 +290,11 @@ def write(self, filename: Path): # Validate the header and body before writing new_header = EDEXHeader.model_validate(self.header.model_dump()) new_body = EDEXBody.model_validate(self.body.model_dump()) + # by_alias is what puts "size" in the file. Without it pydantic writes the field + # name "resolution", which neither the C++ nor the python reader accepts. data = [ - new_header.model_dump(exclude_none=True), - new_body.model_dump(exclude_none=True), + new_header.model_dump(exclude_none=True, by_alias=True), + new_body.model_dump(exclude_none=True, by_alias=True), ] with open(filename, "w") as f: json.dump(data, f, indent=2, cls=EDEXEncoder) diff --git a/tools/python_tools/cuvslam_tools/tests/test_edex.py b/tools/python_tools/cuvslam_tools/tests/test_edex.py index c20709e1..b061b3be 100644 --- a/tools/python_tools/cuvslam_tools/tests/test_edex.py +++ b/tools/python_tools/cuvslam_tools/tests/test_edex.py @@ -43,6 +43,21 @@ def test_read_edex(self): self.assertEqual(edex.header.cameras[0].intrinsics.resolution.shape, (2,)) self.assertEqual(edex.header.cameras[0].transform.shape, (3, 4)) + def test_write_edex_uses_size_key(self): + # Round tripping through EDEXMetadata accepts either spelling, so check the raw json: + # the C++ reader and dataset_reader.py only know "size". + edex = EDEXMetadata.read(DATA_DIR / "edex") + with tempfile.NamedTemporaryFile( + mode="w+", delete=True, encoding="utf-8" + ) as temp_file: + edex.write(Path(temp_file.name)) + with open(temp_file.name) as f: + header = json.load(f)[0] + + for camera in header["cameras"]: + self.assertIn("size", camera["intrinsics"]) + self.assertNotIn("resolution", camera["intrinsics"]) + def test_read_edex_copy_transform(self): # Read the intrinsics-only EDEX file edex_intrinsics = EDEXMetadata.read(DATA_DIR / "edex_intrinsics")