From ed40e386f091a28742acb6d41694014aa3a21f0a Mon Sep 17 00:00:00 2001 From: alessandrofelder Date: Fri, 3 May 2024 16:16:07 +0100 Subject: [PATCH] allow no axis metadata for 3D tiff files --- brainglobe_utils/image_io/load.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/brainglobe_utils/image_io/load.py b/brainglobe_utils/image_io/load.py index f094b52..2ad4969 100644 --- a/brainglobe_utils/image_io/load.py +++ b/brainglobe_utils/image_io/load.py @@ -698,15 +698,28 @@ def get_size_image_from_file_paths(file_path, file_extension="tif"): shape = tiff.series[0].shape axes = tiff.series[0].axes.lower() - # axes is e.g. "zxy" - if set(axes) != {"x", "y", "z"}: + + if len(shape) != 3: raise ValueError( f"Attempted to load {file_path} but didn't find a " - f"xyz-stack. Found {axes} axes with shape {shape}" + f"3-dimensional stack. Found {axes} axes " + f"with shape {shape}" ) - - image_shape = {ax: n for ax, n in zip(axes, shape)} - return image_shape + # axes is e.g. "zxy" + if set(axes) == {"x", "y", "z"}: + image_shape = {ax: n for ax, n in zip(axes, shape)} + return image_shape + else: # metadata does not specify axes as expected, + logging.debug( + f"Axis metadata is {axes}, " + "which is not the expected set of x,y,z in any order. " + "Assume z,y,x" + ) + image_shape = { + ax: n + for ax, n in zip(["z", "y", "x"], tiff.series[0].shape) + } + return image_shape img_paths = get_sorted_file_paths(file_path, file_extension=file_extension) z_shape = len(img_paths)