Skip to content

Commit

Permalink
Do not sort keys when loading calibration toml
Browse files Browse the repository at this point in the history
  • Loading branch information
roomrys committed Dec 6, 2024
1 parent ef9751a commit bbbf9a0
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions sleap/io/cameras.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,11 @@ def load(cls, filename) -> "CameraCluster":
Returns:
`CameraCluster` object.
"""
cgroup: CameraGroup = super().load(filename)
return cls(cameras=cgroup.cameras, metadata=cgroup.metadata)

calibration_dict = toml.load(filename)
camera_cluster = cls.from_calibration_dict(calibration_dict)

return camera_cluster

@classmethod
def from_calibration_dict(cls, calibration_dict: Dict[str, str]) -> "CameraCluster":
Expand All @@ -366,12 +369,12 @@ def from_calibration_dict(cls, calibration_dict: Dict[str, str]) -> "CameraClust
`CameraCluster` object.
"""

# Save the calibration dictionary to a temp file and load as `CameraGroup`
with tempfile.TemporaryDirectory() as temp_dir:
temp_file = str(Path(temp_dir, "calibration.toml"))
with open(temp_file, "w") as f:
toml.dump(calibration_dict, f)
cgroup: CameraGroup = super().load(temp_file)
# Taken from aniposelib.cameras.CameraGroup.load, but without sorting keys
keys = calibration_dict.keys()
items = [calibration_dict[k] for k in keys if k != "metadata"]
cgroup = CameraGroup.from_dicts(items)
if "metadata" in calibration_dict:
cgroup.metadata = calibration_dict["metadata"]

return cls(cameras=cgroup.cameras, metadata=cgroup.metadata)

Expand Down

0 comments on commit bbbf9a0

Please sign in to comment.