From 3e85d3ba458e2946b5bbb8bd0baa1a36553288dc Mon Sep 17 00:00:00 2001 From: Qin Yu Date: Thu, 28 Nov 2024 19:03:42 +0100 Subject: [PATCH 1/4] fix(io): default loader wrong return type --- plantseg/io/io.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plantseg/io/io.py b/plantseg/io/io.py index f69093ea..28c4e22a 100644 --- a/plantseg/io/io.py +++ b/plantseg/io/io.py @@ -89,5 +89,5 @@ def smart_load_with_vs(path: Path, key: str | None = None, default=load_tiff) -> return load_zarr(path, key), read_zarr_voxel_size(path, key) else: - logger.warning(f"No default found for {ext}, reverting to default loader.") - return default(path) + logger.warning(f"No default found for {ext}, reverting to default loader with no voxel size reader.") + return default(path), None From 75d03675998054cc0bdd0e1252a15478414425b9 Mon Sep 17 00:00:00 2001 From: Qin Yu Date: Thu, 28 Nov 2024 19:05:53 +0100 Subject: [PATCH 2/4] fix(io): image file suffixes in capital letter aren't recognised --- plantseg/io/io.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plantseg/io/io.py b/plantseg/io/io.py index 28c4e22a..2b90f6dc 100644 --- a/plantseg/io/io.py +++ b/plantseg/io/io.py @@ -32,7 +32,7 @@ def smart_load(path: Path, key: str | None = None, default=load_tiff) -> np.ndar >>> data = smart_load('path/to/file.h5', key='raw') """ - ext = path.suffix + ext = (path.suffix).lower() if key == "": key = None @@ -72,7 +72,7 @@ def smart_load_with_vs(path: Path, key: str | None = None, default=load_tiff) -> >>> data = smart_load('path/to/file.h5', key='raw') """ - ext = path.suffix + ext = (path.suffix).lower() if key == "": key = None From c552b63240c5fdea7111a1be9607cc0df24d2679 Mon Sep 17 00:00:00 2001 From: Qin Yu Date: Thu, 28 Nov 2024 19:26:18 +0100 Subject: [PATCH 3/4] fix(io): make `.zarr` extension check consistenet --- plantseg/io/io.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plantseg/io/io.py b/plantseg/io/io.py index 2b90f6dc..b0ffa483 100644 --- a/plantseg/io/io.py +++ b/plantseg/io/io.py @@ -85,7 +85,7 @@ def smart_load_with_vs(path: Path, key: str | None = None, default=load_tiff) -> if ext in PIL_EXTENSIONS: return load_pil(path), None - if ".zarr" in path.suffixes: + if ext in ZARR_EXTENSIONS: return load_zarr(path, key), read_zarr_voxel_size(path, key) else: From 63d38eb0b55faef204657075c7ed4e9adc50223a Mon Sep 17 00:00:00 2001 From: Qin Yu Date: Thu, 28 Nov 2024 19:27:14 +0100 Subject: [PATCH 4/4] fix(io): make all extension check case-insensitive --- plantseg/core/image.py | 2 +- plantseg/headless/headless.py | 2 +- plantseg/io/h5.py | 4 ++-- plantseg/viewer_napari/widgets/io.py | 2 +- plantseg/viewer_napari/widgets/proofreading.py | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/plantseg/core/image.py b/plantseg/core/image.py index 25b67c0c..4c60eab5 100644 --- a/plantseg/core/image.py +++ b/plantseg/core/image.py @@ -331,7 +331,7 @@ def to_h5(self, path: Path | str, key: str | None, mode: Literal["a", "w", "w-"] if isinstance(path, str): path = Path(path) - if path.suffix not in H5_EXTENSIONS: + if path.suffix.lower() not in H5_EXTENSIONS: raise ValueError(f"File format {path.suffix} not supported, should be one of {H5_EXTENSIONS}") key = key if key is not None else self.name diff --git a/plantseg/headless/headless.py b/plantseg/headless/headless.py index 116b721f..d6fc9890 100644 --- a/plantseg/headless/headless.py +++ b/plantseg/headless/headless.py @@ -51,7 +51,7 @@ def parse_import_image_task(input_path, allow_dir: bool) -> list[Path]: else: raise ValueError(f"Path {input_path} is not a file or a directory.") - list_files = [f for f in list_files if f.suffix in allowed_data_format] + list_files = [f for f in list_files if f.suffix.lower() in allowed_data_format] if not list_files: raise ValueError(f"No valid files found in {input_path}.") diff --git a/plantseg/io/h5.py b/plantseg/io/h5.py index a471a6d4..efe0469d 100644 --- a/plantseg/io/h5.py +++ b/plantseg/io/h5.py @@ -13,7 +13,7 @@ def _validate_h5_file(path: Path) -> None: - assert path.suffix in H5_EXTENSIONS, f"File extension not supported. Supported extensions: {H5_EXTENSIONS}" + assert path.suffix.lower() in H5_EXTENSIONS, f"File extension not supported. Supported extensions: {H5_EXTENSIONS}" assert path.exists(), f"File not found: {path}" @@ -73,7 +73,7 @@ def load_h5( np.ndarray: dataset as numpy array """ - assert path.suffix in H5_EXTENSIONS, f"File extension not supported. Supported extensions: {H5_EXTENSIONS}" + assert path.suffix.lower() in H5_EXTENSIONS, f"File extension not supported. Supported extensions: {H5_EXTENSIONS}" assert path.exists(), f"File not found: {path}" with h5py.File(path, "r") as f: diff --git a/plantseg/viewer_napari/widgets/io.py b/plantseg/viewer_napari/widgets/io.py index b7317a4d..7a3d689d 100644 --- a/plantseg/viewer_napari/widgets/io.py +++ b/plantseg/viewer_napari/widgets/io.py @@ -126,7 +126,7 @@ def generate_layer_name(path: Path, dataset_key: str) -> str: def look_up_dataset_keys(path: Path): path = _return_value_if_widget(path) - ext = path.suffix + ext = path.suffix.lower() if ext in H5_EXTENSIONS: widget_open_file.dataset_key.show() diff --git a/plantseg/viewer_napari/widgets/proofreading.py b/plantseg/viewer_napari/widgets/proofreading.py index 8899ea35..66eadbec 100644 --- a/plantseg/viewer_napari/widgets/proofreading.py +++ b/plantseg/viewer_napari/widgets/proofreading.py @@ -370,7 +370,7 @@ def redo(self): def save_state_to_disk(self, filepath: Path, raw: Image | None, pmap: Image | None = None): """Saves the current state to disk as an HDF5 file.""" - if filepath.suffix not in H5_EXTENSIONS: + if filepath.suffix.lower() not in H5_EXTENSIONS: log( f'Invalid file extension: {filepath.suffix}. Please use a valid HDF5 file extensions: {H5_EXTENSIONS}', thread='Save State',