From f2a5f21e4a6f204f301dab8362c2501705c15488 Mon Sep 17 00:00:00 2001 From: alessandrofelder Date: Thu, 15 Aug 2024 11:08:53 +0100 Subject: [PATCH] simplify error handling Co-authored-by: Niko Sirmpilatze --- brainglobe_utils/IO/image/load.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/brainglobe_utils/IO/image/load.py b/brainglobe_utils/IO/image/load.py index afee5f5..c9fb6e1 100644 --- a/brainglobe_utils/IO/image/load.py +++ b/brainglobe_utils/IO/image/load.py @@ -783,17 +783,12 @@ def read_with_dask(path): filenames = [line.rstrip() for line in f.readlines()] else: - filenames_tif = glob.glob(os.path.join(path, "*.tif")) - filenames_tiff = glob.glob(os.path.join(path, "*.tiff")) - if filenames_tif: - filenames = filenames_tif - elif filenames_tiff: - filenames = filenames_tiff - else: - raise ( - ValueError( - f"Folder {path} does not contain any .tif or .tiff files" - ) + filenames = glob.glob(os.path.join(path, "*.tif")) or glob.glob( + os.path.join(path, "*.tiff") + ) + if not filenames: + raise ValueError( + f"Folder {path} does not contain any .tif or .tiff files" ) shape, dtype = get_tiff_meta(filenames[0])