From 04683677d17f2ee318f3b62f648bb0d6b38670e7 Mon Sep 17 00:00:00 2001 From: LabelFree Date: Wed, 21 Feb 2024 17:56:55 -0800 Subject: [PATCH] sort metadata keys --- iohub/convert.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/iohub/convert.py b/iohub/convert.py index e3380909..e26c0117 100644 --- a/iohub/convert.py +++ b/iohub/convert.py @@ -307,6 +307,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), @@ -331,9 +332,13 @@ def _convert_image_plane_metadata(self, fov, zarr_name: str): "incomplete." ) continue - # T/C/Z - frame_key = "/".join([str(i) for i in (t_idx, c_idx, z_idx)]) - position_image_plane_metadata[frame_key] = metadata + 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} + frame_key = "/".join([str(i) for i in (t_idx, c_idx, z_idx)]) # T/C/Z + position_image_plane_metadata[frame_key] = sorted_metadata with open( self.output_dir / zarr_name / "image_plane_metadata.json", mode="x",