1313import hypothesis .extra .numpy as npst
1414import hypothesis .strategies as st
1515import numpy as np
16+ import ome_zarr .io
17+ import ome_zarr .reader
1618import pytest
1719import zarr .storage
1820from hypothesis import HealthCheck , assume , given , settings
1921from ngff_zarr import from_ngff_zarr
20- from numpy .testing import assert_array_almost_equal , assert_array_equal
22+ from numpy .testing import assert_allclose , assert_array_equal
2123from numpy .typing import NDArray
2224
2325if TYPE_CHECKING :
@@ -308,7 +310,6 @@ def _temp_ome_zarr_plate(
308310 temp_dir .cleanup ()
309311
310312
311- @pytest .mark .skip (reason = "zarr-python / ome_zarr incompatibility" )
312313@given (
313314 channels_and_random_5d = _channels_and_random_5d (),
314315 arr_name = short_alpha_numeric ,
@@ -321,21 +322,19 @@ def _temp_ome_zarr_plate(
321322)
322323def test_write_ome_zarr (channels_and_random_5d , arr_name , version ):
323324 """Test `iohub.ngff.Position.__setitem__()`"""
324- from ome_zarr .io import parse_url
325- from ome_zarr .reader import Reader
326-
327325 channel_names , random_5d = channels_and_random_5d
328326 with _temp_ome_zarr (
329327 random_5d , channel_names , arr_name , version = version
330328 ) as dataset :
331- assert_array_almost_equal (dataset [arr_name ][:], random_5d )
329+ assert_allclose (dataset [arr_name ][:], random_5d )
332330 # round-trip test with the offical reader implementation
333- ext_reader = Reader (parse_url (dataset .zgroup .store .path ))
331+ ext_reader = ome_zarr .reader .Reader (
332+ ome_zarr .io .parse_url (dataset .zgroup .store .root )
333+ )
334334 node = list (ext_reader ())[0 ]
335335 assert node .metadata ["channel_names" ] == channel_names
336336 assert node .specs [0 ].datasets == [arr_name ]
337- assert node .data [0 ].shape == random_5d .shape
338- assert node .data [0 ].dtype == random_5d .dtype
337+ assert_allclose (node .data [0 ], random_5d )
339338
340339
341340@given (
@@ -397,15 +396,11 @@ def test_ome_zarr_to_dask(channels_and_random_5d, arr_name, version):
397396 with _temp_ome_zarr (
398397 random_5d , channel_names , "0" , version = version
399398 ) as dataset :
400- assert_array_almost_equal (
401- dataset .data .dask_array ().compute (), random_5d
402- )
399+ assert_allclose (dataset .data .dask_array ().compute (), random_5d )
403400 with _temp_ome_zarr (
404401 random_5d , channel_names , arr_name , version = version
405402 ) as dataset :
406- assert_array_almost_equal (
407- dataset [arr_name ].dask_array ().compute (), random_5d
408- )
403+ assert_allclose (dataset [arr_name ].dask_array ().compute (), random_5d )
409404
410405
411406@given (channels_and_random_5d = _channels_and_random_5d ())
@@ -457,7 +452,7 @@ def test_position_data(channels_and_random_5d, arr_name, version):
457452 with _temp_ome_zarr (
458453 random_5d , channel_names , "0" , version = version
459454 ) as dataset :
460- assert_array_almost_equal (dataset .data .numpy (), random_5d )
455+ assert_allclose (dataset .data .numpy (), random_5d )
461456 with pytest .raises (KeyError ):
462457 with _temp_ome_zarr (
463458 random_5d , channel_names , arr_name , version = version
@@ -513,7 +508,7 @@ def test_append_channel(channels_and_random_5d, arr_name, version):
513508 ) as dataset :
514509 dataset .append_channel (channel_names [- 1 ], resize_arrays = True )
515510 dataset [arr_name ][:, - 1 ] = random_5d [:, - 1 ]
516- assert_array_almost_equal (dataset [arr_name ][:], random_5d )
511+ assert_allclose (dataset [arr_name ][:], random_5d )
517512
518513
519514@given (
@@ -617,9 +612,7 @@ def test_update_channel(channels_and_random_5d, arr_name, version):
617612 dataset .update_channel (
618613 chan_name = ch , target = arr_name , data = random_5d [:, - 1 ]
619614 )
620- assert_array_almost_equal (
621- dataset [arr_name ][:, i ], random_5d [:, - 1 ]
622- )
615+ assert_allclose (dataset [arr_name ][:, i ], random_5d [:, - 1 ])
623616
624617
625618@given (
@@ -643,16 +636,12 @@ def test_write_more_channels(channels_and_random_5d, arr_name, version):
643636 pass
644637
645638
646- @pytest .mark .skip (reason = "zarr-python / ome_zarr incompatibility" )
647639@given (
648640 ch_shape_dtype = _channels_and_random_5d_shape_and_dtype (),
649641 arr_name = short_alpha_numeric ,
650642)
651643def test_set_transform_image (ch_shape_dtype , arr_name ):
652644 """Test `iohub.ngff.Position.set_transform()`"""
653- from ome_zarr .io import parse_url
654- from ome_zarr .reader import Reader
655-
656645 channel_names , shape , dtype = ch_shape_dtype
657646 transform = [
658647 TransformationMeta (type = "translation" , translation = (1 , 2 , 3 , 4 , 5 ))
@@ -678,7 +667,9 @@ def test_set_transform_image(ch_shape_dtype, arr_name):
678667 == transform
679668 )
680669 # read data with an external reader
681- ext_reader = Reader (parse_url (dataset .zgroup .store .path ))
670+ ext_reader = ome_zarr .reader .Reader (
671+ ome_zarr .io .parse_url (dataset .zgroup .store .root )
672+ )
682673 node = list (ext_reader ())[0 ]
683674 assert node .metadata ["coordinateTransformations" ][0 ] == [
684675 translate .model_dump (** TO_DICT_SETTINGS ) for translate in transform
@@ -1049,7 +1040,7 @@ def _tile_data(tiles):
10491040 ) as dataset :
10501041 for data , row , column in _tile_data (tiles ):
10511042 read = tiles .get_tile (row , column )
1052- assert_array_almost_equal (data , read )
1043+ assert_allclose (data , read )
10531044
10541045
10551046@given (channel_names = channel_names_st )
@@ -1258,9 +1249,6 @@ def test_position_scale(channels_and_random_5d, version):
12581249 reason = "https://github.com/zarr-developers/zarr-python/issues/2407"
12591250)
12601251def test_combine_fovs_to_hcs ():
1261- from ome_zarr .io import parse_url
1262- from ome_zarr .reader import Reader
1263-
12641252 fovs = {}
12651253 fov_paths = ("A/1/0" , "B/1/0" , "H/12/9" )
12661254 with open_ome_zarr (hcs_ref ) as hcs_store :
@@ -1285,7 +1273,6 @@ def test_combine_fovs_to_hcs():
12851273 assert_array_equal (dataset [fov_path ]["0" ].numpy (), array )
12861274
12871275
1288- @pytest .mark .skip (reason = "zarr-python / ome_zarr incompatibility" )
12891276def test_hcs_external_reader (tmp_path ):
12901277 store_path = tmp_path / "hcs.zarr"
12911278 fov_name_parts = (("A" , "1" , "7" ), ("B" , "1" , "7" ), ("H" , "12" , "7" ))
@@ -1298,7 +1285,9 @@ def test_hcs_external_reader(tmp_path):
12981285 fov .create_zeros ("0" , shape = (1 , 2 , 3 , y_size , x_size ), dtype = int )
12991286 n_rows = len (dataset .metadata .rows )
13001287 n_cols = len (dataset .metadata .columns )
1301- plate = list (Reader (parse_url (store_path ))())[0 ]
1288+ plate = list (
1289+ ome_zarr .reader .Reader (ome_zarr .io .parse_url (store_path ))()
1290+ )[0 ]
13021291 assert plate .data [0 ].shape == (1 , 2 , 3 , y_size * n_rows , x_size * n_cols )
13031292 assert plate .data [0 ].dtype == int
13041293 assert not plate .data [0 ].any ()
@@ -1368,7 +1357,7 @@ def test_ngff_zarr_read(channels_and_random_5d, arr_name, version):
13681357 nz_multiscales = from_ngff_zarr (
13691358 dataset .zgroup .store .root , validate = True
13701359 )
1371- assert_array_almost_equal (
1360+ assert_allclose (
13721361 dataset [arr_name ].dask_array ().compute (),
13731362 nz_multiscales .images [0 ].data ,
13741363 )
0 commit comments