1
1
import dask .array as da
2
2
import pytest
3
+ import zarr
3
4
from devtools import debug
4
5
5
6
from fractal_tasks_core .pyramids import build_pyramid
@@ -9,31 +10,40 @@ def test_build_pyramid(tmp_path):
9
10
10
11
# Fail because only 2D,3D,4D are supported / A
11
12
zarrurl = str (tmp_path / "A.zarr" )
12
- da .ones (shape = (16 ,)).to_zarr (f"{ zarrurl } /0" )
13
+ # Specify the dimension separator as '/'
14
+ store = zarr .DirectoryStore (f"{ zarrurl } /0" , dimension_separator = "/" )
15
+ # Save the Dask array to the Zarr store
16
+ da .ones (shape = (16 ,)).to_zarr (store )
13
17
with pytest .raises (ValueError ) as e :
14
18
build_pyramid (zarrurl = zarrurl )
15
19
debug (e .value )
16
20
assert "ndims" in str (e .value )
17
21
18
22
# Fail because only 2D,3D,4D are supported / B
19
23
zarrurl = str (tmp_path / "B.zarr" )
20
- da .ones (shape = (2 , 2 , 2 , 2 , 2 )).to_zarr (f"{ zarrurl } /0" )
24
+ # Specify the dimension separator as '/'
25
+ store = zarr .DirectoryStore (f"{ zarrurl } /0" , dimension_separator = "/" )
26
+ da .ones (shape = (2 , 2 , 2 , 2 , 2 )).to_zarr (store )
21
27
with pytest .raises (ValueError ) as e :
22
28
build_pyramid (zarrurl = zarrurl )
23
29
debug (e .value )
24
30
assert "ndims" in str (e .value )
25
31
26
32
# Fail because there is not enough data for coarsening
27
33
zarrurl = str (tmp_path / "C.zarr" )
28
- da .ones (shape = (4 , 4 )).to_zarr (f"{ zarrurl } /0" )
34
+ # Specify the dimension separator as '/'
35
+ store = zarr .DirectoryStore (f"{ zarrurl } /0" , dimension_separator = "/" )
36
+ da .ones (shape = (4 , 4 )).to_zarr (store )
29
37
with pytest .raises (ValueError ) as e :
30
38
build_pyramid (zarrurl = zarrurl , coarsening_xy = 10 )
31
39
debug (e .value )
32
40
assert "but previous level has shape" in str (e .value )
33
41
34
42
# Succeed
35
43
zarrurl = str (tmp_path / "D.zarr" )
36
- da .ones (shape = (8 , 8 )).to_zarr (f"{ zarrurl } /0" )
44
+ # Specify the dimension separator as '/'
45
+ store = zarr .DirectoryStore (f"{ zarrurl } /0" , dimension_separator = "/" )
46
+ da .ones (shape = (8 , 8 )).to_zarr (store )
37
47
build_pyramid (zarrurl = zarrurl , coarsening_xy = 2 , num_levels = 3 )
38
48
level_1 = da .from_zarr (f"{ zarrurl } /1" )
39
49
level_2 = da .from_zarr (f"{ zarrurl } /2" )
@@ -44,7 +54,9 @@ def test_build_pyramid(tmp_path):
44
54
45
55
# Succeed
46
56
zarrurl = str (tmp_path / "E.zarr" )
47
- da .ones (shape = (243 + 2 , 243 )).to_zarr (f"{ zarrurl } /0" )
57
+ # Specify the dimension separator as '/'
58
+ store = zarr .DirectoryStore (f"{ zarrurl } /0" , dimension_separator = "/" )
59
+ da .ones (shape = (243 + 2 , 243 )).to_zarr (store )
48
60
build_pyramid (zarrurl = zarrurl , coarsening_xy = 3 , num_levels = 6 , chunksize = 9 )
49
61
level_1 = da .from_zarr (f"{ zarrurl } /1" )
50
62
level_2 = da .from_zarr (f"{ zarrurl } /2" )
@@ -67,7 +79,9 @@ def test_build_pyramid(tmp_path):
67
79
68
80
# check that open_array_kwargs has an effect
69
81
zarrurl = tmp_path / "F.zarr"
70
- da .ones (shape = (8 , 8 )).to_zarr (f"{ zarrurl } /0" )
82
+ # Specify the dimension separator as '/'
83
+ store = zarr .DirectoryStore (f"{ zarrurl } /0" , dimension_separator = "/" )
84
+ da .ones (shape = (8 , 8 )).to_zarr (store )
71
85
build_pyramid (
72
86
zarrurl = zarrurl ,
73
87
coarsening_xy = 2 ,
@@ -79,7 +93,9 @@ def test_build_pyramid(tmp_path):
79
93
assert (zarrurl / "2/0/0" ).exists ()
80
94
81
95
zarrurl = tmp_path / "G.zarr"
82
- da .zeros (shape = (8 , 8 )).to_zarr (f"{ zarrurl } /0" )
96
+ # Specify the dimension separator as '/'
97
+ store = zarr .DirectoryStore (f"{ zarrurl } /0" , dimension_separator = "/" )
98
+ da .zeros (shape = (8 , 8 )).to_zarr (store )
83
99
build_pyramid (
84
100
zarrurl = zarrurl ,
85
101
coarsening_xy = 2 ,
@@ -93,8 +109,10 @@ def test_build_pyramid(tmp_path):
93
109
94
110
def test_build_pyramid_overwrite (tmp_path ):
95
111
# Succeed
96
- zarrurl = str (tmp_path / "D.zarr" )
97
- da .ones (shape = (8 , 8 )).to_zarr (f"{ zarrurl } /0" )
112
+ zarrurl = str (tmp_path / "K.zarr" )
113
+ # Specify the dimension separator as '/'
114
+ store = zarr .DirectoryStore (f"{ zarrurl } /0" , dimension_separator = "/" )
115
+ da .ones (shape = (8 , 8 )).to_zarr (store )
98
116
build_pyramid (zarrurl = zarrurl , coarsening_xy = 2 , num_levels = 3 )
99
117
# Should fail because overwrite is not set
100
118
with pytest .raises (ValueError ):
0 commit comments