Skip to content

Commit

Permalink
Merge pull request #18 from TheJacksonLaboratory/dev
Browse files Browse the repository at this point in the history
Fix for incorrect data group parsing
  • Loading branch information
fercer authored Oct 28, 2024
2 parents 2321b01 + c710f96 commit 3567d8e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
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

0 comments on commit 3567d8e

Please sign in to comment.