Skip to content

Commit e762a8a

Browse files
authored
Merge pull request #7 from funkelab/fix_n5_multiscale
Remove paths and only use stores
2 parents 4edfc7b + 1cc46e4 commit e762a8a

File tree

1 file changed

+4
-57
lines changed

1 file changed

+4
-57
lines changed

funlib/persistence/arrays/datasets.py

Lines changed: 4 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -14,50 +14,6 @@
1414
logger = logging.getLogger(__name__)
1515

1616

17-
def get_url(node: Union[zarr.Group, zarr.Array]) -> str:
18-
store = node.store
19-
if hasattr(store, "path"):
20-
if hasattr(store, "fs"):
21-
if isinstance(store.fs.protocol, Sequence):
22-
protocol = store.fs.protocol[0]
23-
else:
24-
protocol = store.fs.protocol
25-
else:
26-
protocol = "file"
27-
28-
# fsstore keeps the protocol in the path, but not s3store
29-
if "://" in store.path:
30-
store_path = store.path.split("://")[-1]
31-
else:
32-
store_path = store.path
33-
return f"{protocol}://{store_path}"
34-
else:
35-
raise ValueError(
36-
f"The store associated with this object has type {type(store)}, which "
37-
"cannot be resolved to a url"
38-
)
39-
40-
41-
def separate_store_path(store, path):
42-
"""
43-
sometimes you can pass a total os path to node, leading to
44-
an empty('') node.path attribute.
45-
the correct way is to separate path to container(.n5, .zarr)
46-
from path to array within a container.
47-
48-
Args:
49-
store (string): path to store
50-
path (string): path array/group (.n5 or .zarr)
51-
52-
Returns:
53-
(string, string): returns regularized store and group/array path
54-
"""
55-
new_store, path_prefix = os.path.split(store)
56-
if ".zarr" in path_prefix or ".n5" in path_prefix:
57-
return store, path
58-
return separate_store_path(new_store, os.path.join(path_prefix, path))
59-
60-
6117
def access_parent(node):
6218
"""
6319
Get the parent (zarr.Group) of an input zarr array(ds).
@@ -73,16 +29,9 @@ def access_parent(node):
7329
Returns:
7430
zarr.hierarchy.Group : parent group that contains input group/array
7531
"""
76-
77-
path = get_url(node)
78-
79-
store_path, node_path = separate_store_path(path, node.path)
80-
if node_path == "":
81-
raise RuntimeError(f"{node.name} is in the root group of the {path} store.")
82-
else:
83-
if store_path.endswith(".n5"):
84-
store_path = N5FSStore(store_path)
85-
return zarr.open(store=store_path, path=os.path.split(node_path)[0], mode="r")
32+
group_path = node.path
33+
parent_path = os.path.split(node.path)[0]
34+
return zarr.hierarchy.group(store=node.store, path=parent_path)
8635

8736

8837
def check_for_multiscale(group):
@@ -238,9 +187,7 @@ def check_for_attrs_multiscale(ds, multiscale_group, multiscales):
238187

239188
if multiscales is not None:
240189
logger.info("Found multiscales attributes")
241-
scale = os.path.relpath(
242-
separate_store_path(get_url(ds), ds.path)[1], multiscale_group.path
243-
)
190+
scale = os.path.split(ds.path)[1]
244191
if isinstance(ds.store, (zarr.n5.N5Store, zarr.n5.N5FSStore)):
245192
for level in multiscales[0]["datasets"]:
246193
if level["path"] == scale:

0 commit comments

Comments
 (0)