From a623faa0c11f0cab470315081232dabf7715126c Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Wed, 12 Jun 2024 13:08:41 -0700 Subject: [PATCH] Modify warning (#220) * issue one warning per (t_idx, c_idx) * update messaging and prettify logging * fix ome-zarr-py breakage in round-trip test --------- Co-authored-by: Ziwen Liu <67518483+ziw-liu@users.noreply.github.com> --- iohub/convert.py | 35 ++++++++++++++++++++--------------- tests/ngff/test_ngff.py | 2 +- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/iohub/convert.py b/iohub/convert.py index 3d10c28f..c9dc3fa7 100644 --- a/iohub/convert.py +++ b/iohub/convert.py @@ -7,6 +7,7 @@ from dask.array import to_zarr from tqdm import tqdm from tqdm.contrib.itertools import product +from tqdm.contrib.logging import logging_redirect_tqdm from iohub._version import version as iohub_version from iohub.ngff import Position, TransformationMeta, open_ome_zarr @@ -336,14 +337,17 @@ def _convert_image_plane_metadata(self, fov, zarr_name: str): if self.reader.str_channel_axis else c_idx ) + missing_data_warning_issued = False for z_idx in range(self.z): metadata = fov.frame_metadata(t=t_idx, c=c_key, z=z_idx) if metadata is None: - _logger.warning( - f"Cannot load data at timepoint {t_idx}, channel " - f"{c_idx}, filling with zeros. Raw data may be " - "incomplete." - ) + if not missing_data_warning_issued: + missing_data_warning_issued = True + _logger.warning( + f"Cannot load data at P: {zarr_name}, T: {t_idx}, " + f"C: {c_idx}, filling with zeros. Raw data may be " + "incomplete." + ) continue if not sorted_keys: # Sort keys, ordering keys without dashes first @@ -375,16 +379,17 @@ def __call__(self) -> None: self._init_zarr_arrays() # Run through every coordinate and convert in acquisition order _logger.debug("Converting images.") - for zarr_pos_name, (_, fov) in tqdm( - zip(self.zarr_position_names, self.reader, strict=True), - total=len(self.reader), - desc="Converting images", - unit="FOV", - ncols=80, - ): - zarr_img = self.writer[zarr_pos_name]["0"] - to_zarr(fov.xdata.data.rechunk(self.chunks), zarr_img) - self._convert_image_plane_metadata(fov, zarr_img.path) + with logging_redirect_tqdm(): + for zarr_pos_name, (_, fov) in tqdm( + zip(self.zarr_position_names, self.reader, strict=True), + total=len(self.reader), + desc="Converting images", + unit="FOV", + ncols=80, + ): + zarr_img = self.writer[zarr_pos_name]["0"] + to_zarr(fov.xdata.data.rechunk(self.chunks), zarr_img) + self._convert_image_plane_metadata(fov, zarr_img.path) self.writer.zgroup.attrs.update(self.metadata) self.writer.close() self.reader.close() diff --git a/tests/ngff/test_ngff.py b/tests/ngff/test_ngff.py index 6c58863e..b280b9e7 100644 --- a/tests/ngff/test_ngff.py +++ b/tests/ngff/test_ngff.py @@ -200,7 +200,7 @@ def test_write_ome_zarr(channels_and_random_5d, arr_name): # round-trip test with the offical reader implementation ext_reader = Reader(parse_url(dataset.zgroup.store.path)) node = list(ext_reader())[0] - assert node.metadata["name"] == channel_names + assert node.metadata["channel_names"] == channel_names assert node.specs[0].datasets == [arr_name] assert node.data[0].shape == random_5d.shape assert node.data[0].dtype == random_5d.dtype