11import dask .array as da
22import pytest
3+ import zarr
34from devtools import debug
45
56from fractal_tasks_core .pyramids import build_pyramid
@@ -9,31 +10,40 @@ def test_build_pyramid(tmp_path):
910
1011 # Fail because only 2D,3D,4D are supported / A
1112 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 )
1317 with pytest .raises (ValueError ) as e :
1418 build_pyramid (zarrurl = zarrurl )
1519 debug (e .value )
1620 assert "ndims" in str (e .value )
1721
1822 # Fail because only 2D,3D,4D are supported / B
1923 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 )
2127 with pytest .raises (ValueError ) as e :
2228 build_pyramid (zarrurl = zarrurl )
2329 debug (e .value )
2430 assert "ndims" in str (e .value )
2531
2632 # Fail because there is not enough data for coarsening
2733 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 )
2937 with pytest .raises (ValueError ) as e :
3038 build_pyramid (zarrurl = zarrurl , coarsening_xy = 10 )
3139 debug (e .value )
3240 assert "but previous level has shape" in str (e .value )
3341
3442 # Succeed
3543 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 )
3747 build_pyramid (zarrurl = zarrurl , coarsening_xy = 2 , num_levels = 3 )
3848 level_1 = da .from_zarr (f"{ zarrurl } /1" )
3949 level_2 = da .from_zarr (f"{ zarrurl } /2" )
@@ -44,7 +54,9 @@ def test_build_pyramid(tmp_path):
4454
4555 # Succeed
4656 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 )
4860 build_pyramid (zarrurl = zarrurl , coarsening_xy = 3 , num_levels = 6 , chunksize = 9 )
4961 level_1 = da .from_zarr (f"{ zarrurl } /1" )
5062 level_2 = da .from_zarr (f"{ zarrurl } /2" )
@@ -67,7 +79,9 @@ def test_build_pyramid(tmp_path):
6779
6880 # check that open_array_kwargs has an effect
6981 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 )
7185 build_pyramid (
7286 zarrurl = zarrurl ,
7387 coarsening_xy = 2 ,
@@ -79,7 +93,9 @@ def test_build_pyramid(tmp_path):
7993 assert (zarrurl / "2/0/0" ).exists ()
8094
8195 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 )
8399 build_pyramid (
84100 zarrurl = zarrurl ,
85101 coarsening_xy = 2 ,
@@ -93,8 +109,10 @@ def test_build_pyramid(tmp_path):
93109
94110def test_build_pyramid_overwrite (tmp_path ):
95111 # 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 )
98116 build_pyramid (zarrurl = zarrurl , coarsening_xy = 2 , num_levels = 3 )
99117 # Should fail because overwrite is not set
100118 with pytest .raises (ValueError ):
0 commit comments