14
14
logger = logging .getLogger (__name__ )
15
15
16
16
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
-
61
17
def access_parent (node ):
62
18
"""
63
19
Get the parent (zarr.Group) of an input zarr array(ds).
@@ -73,16 +29,9 @@ def access_parent(node):
73
29
Returns:
74
30
zarr.hierarchy.Group : parent group that contains input group/array
75
31
"""
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 )
86
35
87
36
88
37
def check_for_multiscale (group ):
@@ -238,9 +187,7 @@ def check_for_attrs_multiscale(ds, multiscale_group, multiscales):
238
187
239
188
if multiscales is not None :
240
189
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 ]
244
191
if isinstance (ds .store , (zarr .n5 .N5Store , zarr .n5 .N5FSStore )):
245
192
for level in multiscales [0 ]["datasets" ]:
246
193
if level ["path" ] == scale :
0 commit comments