Skip to content

Commit

Permalink
sort metadata keys
Browse files Browse the repository at this point in the history
  • Loading branch information
ieivanov committed Feb 22, 2024
1 parent a6e13a8 commit 0468367
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions iohub/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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",
Expand Down

0 comments on commit 0468367

Please sign in to comment.