From 92fcf8a824c94d33fee6926c5563981abc7bfec4 Mon Sep 17 00:00:00 2001 From: Martin Helm Date: Fri, 27 Feb 2026 12:11:39 +0100 Subject: [PATCH 1/2] Change parsing defaults! Remove auto parsing style option entirely. By default, all tif files inside a folder and all its subdirectories are parsed into a single Image element inside a SpatialData object. Only if the user specifically requests parsing subfolders, then the first level underneath the specified directory defines the image elements. All tifs in these directories, and subdirectores, will be parsed into separate image elements, with corresponding tables and coordinate systems. --- src/spatialdata_io/readers/macsima.py | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/src/spatialdata_io/readers/macsima.py b/src/spatialdata_io/readers/macsima.py index 2b4493f4..3fb0a1dd 100644 --- a/src/spatialdata_io/readers/macsima.py +++ b/src/spatialdata_io/readers/macsima.py @@ -47,7 +47,6 @@ class MACSimaParsingStyle(ModeEnum): PROCESSED_SINGLE_FOLDER = "processed_single_folder" PROCESSED_MULTIPLE_FOLDERS = "processed_multiple_folders" RAW = "raw" - AUTO = "auto" @dataclass @@ -223,7 +222,7 @@ def get_stack(self) -> da.Array: def macsima( path: str | Path, - parsing_style: MACSimaParsingStyle | str = MACSimaParsingStyle.AUTO, + parsing_style: MACSimaParsingStyle | str = MACSimaParsingStyle.PROCESSED_SINGLE_FOLDER, filter_folder_names: list[str] | None = None, imread_kwargs: Mapping[str, Any] = MappingProxyType({}), subset: int | None = None, @@ -294,18 +293,6 @@ def macsima( if not isinstance(parsing_style, MACSimaParsingStyle): parsing_style = MACSimaParsingStyle(parsing_style) - if parsing_style == MACSimaParsingStyle.AUTO: - assert path.is_dir(), f"Path {path} is not a directory." - - if any(p.suffix in [".tif", ".tiff"] for p in path.iterdir()): - # if path contains tifs, do parse_processed_folder on path - parsing_style = MACSimaParsingStyle.PROCESSED_SINGLE_FOLDER - elif all(p.is_dir() for p in path.iterdir() if not p.name.startswith(".")): - # if path contains only folders or hidden files, do parse_processed_folder on each folder - parsing_style = MACSimaParsingStyle.PROCESSED_MULTIPLE_FOLDERS - else: - raise ValueError(f"Cannot determine parsing style for path {path}. Please specify the parsing style.") - if parsing_style == MACSimaParsingStyle.PROCESSED_SINGLE_FOLDER: return parse_processed_folder( path=path, @@ -624,7 +611,7 @@ def parse_processed_folder( nuclei_channel_name: str = "DAPI", split_threshold_nuclei_channel: int | None = 2, skip_rounds: list[int] | None = None, - file_pattern: str = "*.tif*", + file_pattern: str = "**/*.tif*", include_cycle_in_channel_name: bool = False, ) -> SpatialData: """Parse a single folder containing images from a cyclical imaging platform.""" From 861155aba3e995d885be8ee896f199c9766515eb Mon Sep 17 00:00:00 2001 From: Martin Helm Date: Fri, 27 Feb 2026 12:27:07 +0100 Subject: [PATCH 2/2] Skip empty folders when parsing multiple folders --- src/spatialdata_io/readers/macsima.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/spatialdata_io/readers/macsima.py b/src/spatialdata_io/readers/macsima.py index 3fb0a1dd..3e234b73 100644 --- a/src/spatialdata_io/readers/macsima.py +++ b/src/spatialdata_io/readers/macsima.py @@ -318,6 +318,9 @@ def macsima( for p in path.iterdir() if p.is_dir() and (not filter_folder_names or not any(f in p.name for f in filter_folder_names)) ]: + if not len(list(p.glob("*.tif*"))): + warnings.warn(f"No tif files found in {p}, skipping it!", UserWarning, stacklevel=2) + continue sdatas[p.stem] = parse_processed_folder( path=p, imread_kwargs=imread_kwargs,