1010from ..client import Context , from_context
1111from ..client .register import IMG_SEQUENCE_EMPTY_NAME_ROOT , register
1212from ..server .app import build_app
13+ from ..structures .array import ArrayStructure , BuiltinDtype
1314from ..utils import ensure_uri
1415
1516COLOR_SHAPE = (11 , 17 , 3 )
17+ rng = numpy .random .default_rng (12345 )
1618
1719
1820@pytest .fixture (scope = "module" )
@@ -21,20 +23,27 @@ def client(tmpdir_module):
2123 sequence_directory .mkdir ()
2224 filepaths = []
2325 for i in range (3 ):
24- data = numpy . random . random ( (5 , 7 , 4 ))
26+ data = rng . integers ( 0 , 255 , size = (5 , 7 , 4 ), dtype = "uint8" )
2527 filepath = sequence_directory / f"temp{ i :05} .tif"
2628 tf .imwrite (filepath , data )
2729 filepaths .append (filepath )
28- color_data = numpy . random . randint (0 , 255 , COLOR_SHAPE , dtype = "uint8" )
30+ color_data = rng . integers (0 , 255 , size = COLOR_SHAPE , dtype = "uint8" )
2931 path = Path (tmpdir_module , "color.tif" )
3032 tf .imwrite (path , color_data )
31-
3233 tree = MapAdapter (
3334 {
3435 "color" : TiffAdapter (ensure_uri (path )),
3536 "sequence" : TiffSequenceAdapter .from_uris (
3637 [ensure_uri (filepath ) for filepath in filepaths ]
3738 ),
39+ "5d_sequence" : TiffSequenceAdapter .from_uris (
40+ [ensure_uri (filepath ) for filepath in filepaths ],
41+ structure = ArrayStructure (
42+ shape = (3 , 1 , 5 , 7 , 4 ),
43+ chunks = ((1 , 1 , 1 ), (1 ,), (5 ,), (7 ,), (4 ,)),
44+ data_type = BuiltinDtype .from_numpy_dtype (numpy .dtype ("uint8" )),
45+ ),
46+ ),
3847 }
3948 )
4049 app = build_app (tree )
@@ -62,6 +71,27 @@ def test_tiff_sequence(client, slice_input, correct_shape):
6271 assert arr .shape == correct_shape
6372
6473
74+ @pytest .mark .parametrize (
75+ "slice_input, correct_shape" ,
76+ [
77+ (None , (3 , 1 , 5 , 7 , 4 )),
78+ (..., (3 , 1 , 5 , 7 , 4 )),
79+ ((), (3 , 1 , 5 , 7 , 4 )),
80+ (0 , (1 , 5 , 7 , 4 )),
81+ (slice (0 , 3 , 2 ), (2 , 1 , 5 , 7 , 4 )),
82+ ((1 , slice (0 , 10 ), slice (0 , 3 ), slice (0 , 3 )), (1 , 3 , 3 , 4 )),
83+ ((slice (0 , 3 ), 0 , slice (0 , 3 ), slice (0 , 3 )), (3 , 3 , 3 , 4 )),
84+ ((..., 0 , 0 , 0 , 0 ), (3 ,)),
85+ ((0 , slice (0 , 1 ), slice (0 , 1 ), slice (0 , 2 ), ...), (1 , 1 , 2 , 4 )),
86+ ((0 , ..., slice (0 , 2 )), (1 , 5 , 7 , 2 )),
87+ ((..., slice (0 , 1 )), (3 , 1 , 5 , 7 , 1 )),
88+ ],
89+ )
90+ def test_forced_reshaping (client , slice_input , correct_shape ):
91+ arr = client ["5d_sequence" ].read (slice = slice_input )
92+ assert arr .shape == correct_shape
93+
94+
6595@pytest .mark .parametrize ("block_input, correct_shape" , [((0 , 0 , 0 , 0 ), (1 , 5 , 7 , 4 ))])
6696def test_tiff_sequence_block (client , block_input , correct_shape ):
6797 arr = client ["sequence" ].read_block (block_input )
0 commit comments