From a1b09effa509c5ec875fb2ccd028dee6b03f7e48 Mon Sep 17 00:00:00 2001 From: David Northover Date: Wed, 24 Sep 2025 21:55:49 -0400 Subject: [PATCH 1/2] Addresses Cannot Backproject from Compressed Image Fixes #27 - Was not actually compression, was certain non-compressed files. - memmap check is to certain dataoffsets at the moment; unsure of precise file format details --- python/ouroboros/pipeline/backproject_pipeline.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/python/ouroboros/pipeline/backproject_pipeline.py b/python/ouroboros/pipeline/backproject_pipeline.py index 8201406..686fddc 100644 --- a/python/ouroboros/pipeline/backproject_pipeline.py +++ b/python/ouroboros/pipeline/backproject_pipeline.py @@ -96,7 +96,15 @@ def _process(self, input_data: any) -> tuple[any, None] | tuple[None, any]: is_compressed = bool(tif.pages[0].compression) FPShape = FrontProjStack(D=len(tif.pages), V=tif.pages[0].shape[0], U=tif.pages[0].shape[1]) - if is_compressed: + cannot_memmap = False + try: + _ = tifffile.memmap(straightened_volume_path, mode="r") + except: # noqa: E722 + # Check here is because memmap needs certain types of dataoffsets, which aren't always there + # separate to compression. + cannot_memmap = True + + if is_compressed or cannot_memmap: print("Input data compressed; Rewriting.") # Create a new path for the straightened volume From 0d3adee5faa814456eaf84c73904912090c31076 Mon Sep 17 00:00:00 2001 From: David Northover Date: Wed, 24 Sep 2025 21:59:34 -0400 Subject: [PATCH 2/2] Expand check to tiff stacks --- python/ouroboros/pipeline/backproject_pipeline.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/python/ouroboros/pipeline/backproject_pipeline.py b/python/ouroboros/pipeline/backproject_pipeline.py index 686fddc..baab382 100644 --- a/python/ouroboros/pipeline/backproject_pipeline.py +++ b/python/ouroboros/pipeline/backproject_pipeline.py @@ -98,10 +98,13 @@ def _process(self, input_data: any) -> tuple[any, None] | tuple[None, any]: cannot_memmap = False try: - _ = tifffile.memmap(straightened_volume_path, mode="r") + if Path(straightened_volume_path).is_dir(): + _ = tifffile.memmap(next(Path(straightened_volume_path).iterdir()), mode="r") + else: + _ = tifffile.memmap(straightened_volume_path, mode="r") except: # noqa: E722 # Check here is because memmap needs certain types of dataoffsets, which aren't always there - # separate to compression. + # separate to compression. cannot_memmap = True if is_compressed or cannot_memmap: