From 8c796d900f06590da477be66d4f1e707c4322061 Mon Sep 17 00:00:00 2001 From: camisowers <38049893+camisowers@users.noreply.github.com> Date: Tue, 5 Sep 2023 13:54:00 -0700 Subject: [PATCH] Prevent image rotation during OME tiff conversion (#36) * swap axes instead of transposing * to_numpy * transpose switch rows and cols --- src/alpineer/load_utils.py | 4 ++-- tests/load_utils_test.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/alpineer/load_utils.py b/src/alpineer/load_utils.py index 9cbf3ae..df901a0 100644 --- a/src/alpineer/load_utils.py +++ b/src/alpineer/load_utils.py @@ -532,7 +532,7 @@ def fov_to_ome( # Reorder the DataArray as OME-TIFFs require [Channel, Y, X] fov_xr: xr.DataArray = load_imgs_from_tree( data_dir=data_dir, img_sub_folder=img_sub_folder, fovs=fovs, channels=channels - ).transpose("fovs", "channels", "cols", "rows") + ).transpose("fovs", "channels", "rows", "cols") _compression: dict = {"algorithm": "zlib", "args": {"level": 6}} @@ -613,6 +613,6 @@ def ome_to_fov(ome: Union[str, pathlib.Path], data_dir: Union[str, pathlib.Path] image_utils.save_image( fname=save_dir / f"{channel}.tiff", - data=ome_tiff_page.asarray().transpose(), + data=ome_tiff_page.asarray(), compression_level=6, ) diff --git a/tests/load_utils_test.py b/tests/load_utils_test.py index ddbe3b2..0027150 100644 --- a/tests/load_utils_test.py +++ b/tests/load_utils_test.py @@ -665,7 +665,8 @@ def create_img_data(tmp_path_factory) -> Iterator[Tuple[pathlib.Path, xr.DataArr # Create OME-TIFFs _compression: dict = {"algorithm": "zlib", "args": {"level": 6}} - data_xr_transposed = data_xr.transpose("fovs", "channels", "cols", "rows") + data_xr_transposed = data_xr.transpose("fovs", "channels", "rows", "cols") + for fov in data_xr_transposed: fov_name: str = fov.fovs.values ome_file_path: pathlib.Path = pathlib.Path(test_dir) / f"{fov_name}.ome.tiff" @@ -726,7 +727,7 @@ def test_fov_to_ome(self, fovs, channels) -> None: # Assert that the channel values in the OME-TIFF are correct. for page, chan in zip(ome_tiff.pages, channels): - actual_data = page.asarray().transpose() + actual_data = page.asarray() desired_data = self.data_xr.sel(fovs=fov_name, channels=chan).values np.testing.assert_equal(actual_data, desired_data)