From 420f052f7ab78621357bcbf32aea0a58fc28dd6a Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Mon, 15 Apr 2024 16:55:54 -0700 Subject: [PATCH] Sort keys in metadata .json files (#211) * wip: draft mmstack ome-tiff fov * MM FOV base class * tests * bump tifffile * comment * fix indent after rebase * use get default * test pixel indexing * set MM metadata * style * update dependencies * add xarray * move old readers to the `_deprecated` namespace * uapi for ndtiff * refactor test setup to parametrize by dataset use globals instead of fixtures since parametrization happens before fixture evaluation * convert mmstack * fix and test chunking * fix metadata conversion and test ndtiff * update cli * fix scaling * test 1.4 and incomplete ome-tiffs * move reader tests * deprecate reader tests * update deprecated tests * update ngff tests * isort * update black target to 3.10 * lint * fix download paths * update docs references and theme * untrack autogenerated file * ignore execution time file * add github icon * update docstring * update docstring * show channel names and chunk size in info * print plate chunk size if verbose * fallback for pixel size * remove log level setting * do not filter logs and warnings in reader * avoid root logger * isort * set default logging level to INFO * format docstring * improve conversion messages * black * fix ome-tiff channel name indexing * fix ndtiff channel name indexing * update converter test * remove use of os.path in `reader` * expand _check_ndtiff checks * fix iteration * fix python 3.10 using `Path.glob(*/)` to get subdirs was added in 3.11 * bump zarr version to include resizing fix https://github.com/zarr-developers/zarr-python/pull/1540 * fix cli default * set log level with an environment variable * fix unset * catch non-existent page * implement fallback for incomplete channel names workaround for the Dragonfly microscope where the multi-camera setup only has one channel name written * add debug logs * handle virtual frames * try reading pages from TiffFile directly * filter error logs about ImageJ metadata being broken this is a known MM limitation when writing OME-TIFFs * fix regex * remove use of os.path in `convert.py` * better channel indexing in `_get_summary_metadata` * style * safer NoneType check * private default axis names for NDTiff * sort metadata keys * Squashed commit of the following: commit fac2c136a0f5ee544d27d348bba86f0b4f0d4179 Author: Ivan Ivanov Date: Tue Apr 9 11:25:36 2024 -0700 Fix bug reading dragonfly acquisitions (#215) * fix bug reading dragonfly acquisitions * fix typo * style * bugfix commit 0c6984e700682b91fc93c65774ef8d8a5bc20398 Author: Ivan Ivanov Date: Mon Mar 11 12:35:51 2024 -0700 Fix bug determining number of rows and cols (#214) * fix bug determining number of rows and cols * add another XY Stage variation * add docs and fix style commit 3ab89ba1f4c07c6930bce6198023dd4a8f9a4aa2 Author: Ziwen Liu <67518483+ziw-liu@users.noreply.github.com> Date: Mon Mar 4 11:02:49 2024 -0800 Universal API implementations for Micro-Manager OME-TIFF and NDTiff (#185) * wip: draft mmstack ome-tiff fov * MM FOV base class * tests * bump tifffile * comment * fix indent after rebase * use get default * test pixel indexing * set MM metadata * style * update dependencies * add xarray * move old readers to the `_deprecated` namespace * uapi for ndtiff * refactor test setup to parametrize by dataset use globals instead of fixtures since parametrization happens before fixture evaluation * convert mmstack * fix and test chunking * fix metadata conversion and test ndtiff * update cli * fix scaling * test 1.4 and incomplete ome-tiffs * move reader tests * deprecate reader tests * update deprecated tests * update ngff tests * isort * update black target to 3.10 * lint * fix download paths * update docs references and theme * untrack autogenerated file * ignore execution time file * add github icon * update docstring * update docstring * show channel names and chunk size in info * print plate chunk size if verbose * fallback for pixel size * remove log level setting * do not filter logs and warnings in reader * avoid root logger * isort * set default logging level to INFO * format docstring * improve conversion messages * black * fix ome-tiff channel name indexing * fix ndtiff channel name indexing * update converter test * remove use of os.path in `reader` * expand _check_ndtiff checks * fix iteration * fix python 3.10 using `Path.glob(*/)` to get subdirs was added in 3.11 * bump zarr version to include resizing fix https://github.com/zarr-developers/zarr-python/pull/1540 * fix cli default * set log level with an environment variable * fix unset * catch non-existent page * implement fallback for incomplete channel names workaround for the Dragonfly microscope where the multi-camera setup only has one channel name written * add debug logs * handle virtual frames * try reading pages from TiffFile directly * filter error logs about ImageJ metadata being broken this is a known MM limitation when writing OME-TIFFs * fix regex * remove use of os.path in `convert.py` * better channel indexing in `_get_summary_metadata` * style * safer NoneType check * private default axis names for NDTiff * update documentation to reflect new entry point * add repr to MM FOV and dataset types * rename mm_meta and expose summary metadata * add MicroManagerFOVMapping.root * add MicroManagerFOVMapping.zyx_scale * add warning log for failed position grid * fix grid layout * suppress hypothesis flakiness * different health check suppression --------- Co-authored-by: Ivan Ivanov * black * bugfix --------- Co-authored-by: Ziwen Liu <67518483+ziw-liu@users.noreply.github.com> --- iohub/convert.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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",