diff --git a/brainglobe_utils/IO/image/load.py b/brainglobe_utils/IO/image/load.py index 9c11e8d..99ecbee 100644 --- a/brainglobe_utils/IO/image/load.py +++ b/brainglobe_utils/IO/image/load.py @@ -777,10 +777,12 @@ def read_z_stack(path): ) axes = tiff.series[0].axes.lower() - if set(axes) != {"x", "y", "z"} or axes[0] != "z": - raise ValueError( - f"Attempted to load {path} but didn't find a zyx or " - f"zxy stack. Found {axes} axes" + if set(axes) != {"x", "y", "z"}: + # log that metadata does not specify expected axes + logging.debug( + f"Axis metadata is {axes}, " + "which is not the expected set of x,y,z in any order. " + "Assume z,y,x" ) return tifffile.imread(path) diff --git a/tests/tests/test_IO/test_image_io.py b/tests/tests/test_IO/test_image_io.py index 1dd112c..6e67f04 100644 --- a/tests/tests/test_IO/test_image_io.py +++ b/tests/tests/test_IO/test_image_io.py @@ -1,9 +1,11 @@ import random from collections import namedtuple +from unittest import mock import numpy as np import psutil import pytest +import tifffile from brainglobe_utils.IO.image import load, save, utils @@ -68,6 +70,16 @@ def shuffled_txt_path(txt_path): return txt_path +@pytest.fixture +def array3d_as_tiff_stack_with_missing_metadata(array_3d, tmp_path): + tiff_path = tmp_path / "test_missing_metadata.tif" + metadata = {"axes": ""} + tifffile.imwrite( + tiff_path, array_3d, photometric="minisblack", metadata=metadata + ) + return tiff_path + + @pytest.mark.parametrize("use_path", [True, False], ids=["Path", "String"]) def test_tiff_io(tmp_path, array_3d, use_path): """ @@ -406,3 +418,25 @@ def test_read_with_dask_glob_txt_equal(array_3D_as_2d_tiffs_path, txt_path): glob_stack = load.read_with_dask(array_3D_as_2d_tiffs_path) txt_stack = load.read_with_dask(txt_path) np.testing.assert_array_equal(glob_stack, txt_stack) + + +def test_read_z_stack_with_missing_metadata( + array3d_as_tiff_stack_with_missing_metadata, +): + with mock.patch( + "brainglobe_utils.IO.image.load.logging.debug" + ) as mock_debug: + load.read_z_stack(str(array3d_as_tiff_stack_with_missing_metadata)) + mock_debug.assert_called_once() + + +def test_get_size_image_with_missing_metadata( + array3d_as_tiff_stack_with_missing_metadata, +): + with mock.patch( + "brainglobe_utils.IO.image.load.logging.debug" + ) as mock_debug: + load.get_size_image_from_file_paths( + str(array3d_as_tiff_stack_with_missing_metadata) + ) + mock_debug.assert_called_once()