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

29 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2025-01-31 11:24 +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 

7 

8 

9def get_name() -> str: 

10 return "single_resolution_float_5d.ome.zarr" 

11 

12 

13def get_path() -> str: 

14 return os.path.realpath(os.path.join(os.path.realpath(__file__), os.pardir, get_name())) 

15 

16 

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

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

19 

20 

21def get_pixel_size_x_y_in_micrometers() -> float: 

22 return 0.5 

23 

24 

25def get_dtype(): 

26 return np.float64 

27 

28 

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

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

31 

32 

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

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

35 

36 

37def _get_pixels() -> np.array: 

38 return np.random.rand(get_shapes()[0].t, get_shapes()[0].c, get_shapes()[0].z, get_shapes()[0].y, get_shapes()[0].x) 

39 

40 

41def _write_image(pixels: np.array): 

42 ## zarr writer fails if dir exists 

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

44 shutil.rmtree(get_path()) 

45 

46 zarr = bioio.writers.OmeZarrWriter(get_path()) 

47 zarr.write_image( 

48 image_data = pixels, 

49 image_name = "single_resolution_float_5d", 

50 channel_names = ["Channel " + str(i) for i in range(get_shapes()[0].c)], 

51 channel_colors = [i for i in range(get_shapes()[0].c)], 

52 physical_pixel_sizes = PhysicalPixelSizes( 

53 X = get_pixel_size_x_y_in_micrometers(), 

54 Y = get_pixel_size_x_y_in_micrometers(), 

55 Z = get_pixel_size_x_y_in_micrometers()) 

56 ) 

57 

58 

59pixels = _get_pixels() 

60_write_image(pixels)