Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix smart load | Make extension check case-insensitive #368

Merged
merged 4 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plantseg/core/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@
if isinstance(path, str):
path = Path(path)

if path.suffix not in H5_EXTENSIONS:
if path.suffix.lower() not in H5_EXTENSIONS:

Check warning on line 334 in plantseg/core/image.py

View check run for this annotation

Codecov / codecov/patch

plantseg/core/image.py#L334

Added line #L334 was not covered by tests
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
Expand Down
2 changes: 1 addition & 1 deletion plantseg/headless/headless.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}.")

Expand Down
4 changes: 2 additions & 2 deletions plantseg/io/h5.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

Check warning on line 16 in plantseg/io/h5.py

View check run for this annotation

Codecov / codecov/patch

plantseg/io/h5.py#L16

Added line #L16 was not covered by tests
assert path.exists(), f"File not found: {path}"


Expand Down Expand Up @@ -73,7 +73,7 @@
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:
Expand Down
10 changes: 5 additions & 5 deletions plantseg/io/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
>>> data = smart_load('path/to/file.h5', key='raw')

"""
ext = path.suffix
ext = (path.suffix).lower()
if key == "":
key = None

Expand Down Expand Up @@ -72,7 +72,7 @@
>>> data = smart_load('path/to/file.h5', key='raw')

"""
ext = path.suffix
ext = (path.suffix).lower()
if key == "":
key = None

Expand All @@ -85,9 +85,9 @@
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:
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

Check warning on line 93 in plantseg/io/io.py

View check run for this annotation

Codecov / codecov/patch

plantseg/io/io.py#L92-L93

Added lines #L92 - L93 were not covered by tests
2 changes: 1 addition & 1 deletion plantseg/viewer_napari/widgets/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion plantseg/viewer_napari/widgets/proofreading.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@
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:

Check warning on line 373 in plantseg/viewer_napari/widgets/proofreading.py

View check run for this annotation

Codecov / codecov/patch

plantseg/viewer_napari/widgets/proofreading.py#L373

Added line #L373 was not covered by tests
log(
f'Invalid file extension: {filepath.suffix}. Please use a valid HDF5 file extensions: {H5_EXTENSIONS}',
thread='Save State',
Expand Down