Coverage for tests/res/single_resolution_float_5d_zarr.py: 97%

30 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-10-07 15:29 +0000

1import bioio.writers 

2import os 

3import shutil 

4import numpy as np 

5from bioio_base.types import PhysicalPixelSizes 

6from qubalab.images.metadata.image_shape import ImageShape 

7import bioio_ome_zarr.writers 

8 

9 

10def get_name() -> str: 

11 return "single_resolution_float_5d.ome.zarr" 

12 

13 

14def get_path() -> str: 

15 return os.path.realpath( 

16 os.path.join(os.path.realpath(__file__), os.pardir, get_name()) 

17 ) 

18 

19 

20def get_shapes() -> tuple[ImageShape, ...]: 

21 return (ImageShape(32, 16, 10, 5, 15),) 

22 

23 

24def get_pixel_size_x_y_in_micrometers() -> float: 

25 return 0.5 

26 

27 

28def get_dtype(): 

29 return np.float64 

30 

31 

32def get_downsamples() -> tuple[float, ...]: 

33 return tuple([get_shapes()[0].x / shape.x for shape in get_shapes()]) 

34 

35 

36def get_pixel_value(x: int, y: int, c: int, z: int, t: int) -> int: 

37 return pixels[t, c, z, y, x] 

38 

39 

40def _get_pixels() -> np.array: 

41 return np.random.rand( 

42 get_shapes()[0].t, 

43 get_shapes()[0].c, 

44 get_shapes()[0].z, 

45 get_shapes()[0].y, 

46 get_shapes()[0].x, 

47 ) 

48 

49 

50def _write_image(pixels: np.array): 

51 ## zarr writer fails if dir exists 

52 if os.path.exists(get_path()) and os.path.isdir(get_path()): 

53 shutil.rmtree(get_path()) 

54 

55 zarr = bioio.writers.OMEZarrWriter( 

56 get_path(), 

57 dtype=get_dtype(), 

58 shape=get_shapes()[0].as_tuple(), 

59 image_name="single_resolution_float_5d", 

60 physical_pixel_size=[ 

61 1, ## tczyx 

62 1, 

63 get_pixel_size_x_y_in_micrometers(), 

64 get_pixel_size_x_y_in_micrometers(), 

65 get_pixel_size_x_y_in_micrometers(), 

66 ], 

67 channels=[ 

68 bioio_ome_zarr.writers.Channel(label="Channel " + str(i), color=i) 

69 for i in range(get_shapes()[0].c) 

70 ], 

71 ) 

72 zarr.write_full_volume(input_data=pixels) 

73 

74 

75pixels = _get_pixels() 

76_write_image(pixels)