diff --git a/iohub/convert.py b/iohub/convert.py index 2528a15d..3d10c28f 100644 --- a/iohub/convert.py +++ b/iohub/convert.py @@ -320,6 +320,7 @@ def _create_zeros_array( def _convert_image_plane_metadata(self, fov, zarr_name: str): position_image_plane_metadata = {} + sorted_keys = [] for t_idx, c_idx in product( range(self.t), range(self.c), @@ -344,9 +345,16 @@ def _convert_image_plane_metadata(self, fov, zarr_name: str): "incomplete." ) continue + if not sorted_keys: + # Sort keys, ordering keys without dashes first + sorted_keys = sorted( + metadata.keys(), key=lambda x: ('-' in x, x) + ) + + sorted_metadata = {key: metadata[key] for key in sorted_keys} # T/C/Z frame_key = "/".join([str(i) for i in (t_idx, c_idx, z_idx)]) - position_image_plane_metadata[frame_key] = metadata + position_image_plane_metadata[frame_key] = sorted_metadata with open( self.output_dir / zarr_name / "image_plane_metadata.json", mode="x",