Skip to content

Commit

Permalink
Modify warning (#220)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
ieivanov and ziw-liu authored Jun 12, 2024
1 parent 420f052 commit a623faa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
35 changes: 20 additions & 15 deletions iohub/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
2 changes: 1 addition & 1 deletion tests/ngff/test_ngff.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a623faa

Please sign in to comment.