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 for incorrect data group parsing #18

Merged
merged 4 commits into from
Oct 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
9 changes: 7 additions & 2 deletions src/napari_activelearning/_tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest
from unittest.mock import MagicMock, patch
from pathlib import Path
from pathlib import Path, PureWindowsPath
import numpy as np
import zarr
import zarrdataset as zds
Expand Down Expand Up @@ -82,7 +82,12 @@ def single_scale_disk_zarr(single_scale_array, tmpdir_factory):
z_group = z_root.create_group(data_group)

z_group.create_dataset(name="0", data=sample_data, overwrite=True)
data_group = str(Path(data_group) / "0")
data_group = Path(data_group) / "0"

if isinstance(data_group, PureWindowsPath):
data_group = data_group.as_posix()

data_group = str(data_group)

return z_root, input_filename, data_group, shape

Expand Down
17 changes: 8 additions & 9 deletions src/napari_activelearning/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,9 +496,12 @@ def get_source_data(layer: Layer):
range(len(input_filename_parts))))
if extension_idx:
extension_idx = extension_idx[0]
data_group = Path(
*input_filename_parts[extension_idx + 1:]
)
data_group = input_filename_parts[extension_idx + 1:]
if len(data_group):
data_group = Path(*data_group)
else:
data_group = ""

input_path = Path(
*input_filename_parts[:extension_idx + 1]
)
Expand All @@ -509,6 +512,7 @@ def get_source_data(layer: Layer):
if isinstance(input_path, PureWindowsPath):
input_path = input_path.as_posix()

data_group = str(data_group)
input_path = str(input_path)

if input_scheme:
Expand All @@ -520,14 +524,9 @@ def get_source_data(layer: Layer):
input_filename = input_scheme + input_netloc + input_path

if ".zarr" in input_filename:
if data_group:
data_group = Path(data_group)

z_grp = zarr.open(input_filename, mode="r")
while not isinstance(z_grp[data_group], zarr.Array):
data_group = data_group / "0"

data_group = str(data_group)
data_group = str(Path(data_group) / "0")

else:
return layer.data, None
Expand Down
Loading