Coverage for tests/images/test_bioio_server.py: 100%
189 statements
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-31 11:24 +0000
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-31 11:24 +0000
1import numpy as np
2from qubalab.images.bioio_server import BioIOServer
3from qubalab.images.region_2d import Region2D
4from qubalab.images.metadata.pixel_calibration import PixelCalibration, PixelLength
5from ..res import multi_resolution_uint8_3channels, single_resolution_float_5d, single_resolution_float_5d_zarr, single_resolution_rgb_image
8def test_uint8_3channels_image_name():
9 bioio_server = BioIOServer(multi_resolution_uint8_3channels.get_path())
11 name = bioio_server.metadata.name
13 assert name == multi_resolution_uint8_3channels.get_name()
15 bioio_server.close()
18def test_uint8_3channels_image_shapes():
19 bioio_server = BioIOServer(multi_resolution_uint8_3channels.get_path())
21 shapes = bioio_server.metadata.shapes
23 assert shapes == (multi_resolution_uint8_3channels.get_shapes()[0], ) # The BioIO library does not properly support pyramids
25 bioio_server.close()
28def test_uint8_3channels_image_pixel_calibration():
29 bioio_server = BioIOServer(multi_resolution_uint8_3channels.get_path())
31 pixel_calibration = bioio_server.metadata.pixel_calibration
33 assert pixel_calibration == PixelCalibration(
34 PixelLength(multi_resolution_uint8_3channels.get_pixel_size_x_y_in_micrometers()), # The BioIO library does not currently handle unit attachment
35 PixelLength(multi_resolution_uint8_3channels.get_pixel_size_x_y_in_micrometers())
36 )
38 bioio_server.close()
41def test_uint8_3channels_image_is_rgb():
42 bioio_server = BioIOServer(multi_resolution_uint8_3channels.get_path())
44 is_rgb = bioio_server.metadata.is_rgb
46 assert is_rgb
48 bioio_server.close()
51def test_uint8_3channels_image_dtype():
52 bioio_server = BioIOServer(multi_resolution_uint8_3channels.get_path())
54 dtype = bioio_server.metadata.dtype
56 assert dtype == multi_resolution_uint8_3channels.get_dtype()
58 bioio_server.close()
61def test_uint8_3channels_image_downsamples():
62 bioio_server = BioIOServer(multi_resolution_uint8_3channels.get_path())
64 downsamples = bioio_server.metadata.downsamples
66 assert downsamples == (multi_resolution_uint8_3channels.get_downsamples()[0], ) # The BioIO library does not properly support pyramids
68 bioio_server.close()
71def test_read_uint8_3channels_image():
72 level = 0
73 full_resolution = multi_resolution_uint8_3channels.get_shapes()[level]
74 downsample = multi_resolution_uint8_3channels.get_downsamples()[level]
75 bioio_server = BioIOServer(multi_resolution_uint8_3channels.get_path())
76 expected_pixels = np.array(
77 [[[multi_resolution_uint8_3channels.get_pixel_value(downsample, x, y, c)
78 for x in range(full_resolution.x)]
79 for y in range(full_resolution.y)]
80 for c in range(full_resolution.c)],
81 multi_resolution_uint8_3channels.get_dtype()
82 )
84 image = bioio_server.read_region(
85 downsample,
86 Region2D(width=bioio_server.metadata.width, height=bioio_server.metadata.height)
87 )
89 np.testing.assert_array_equal(image, expected_pixels)
91 bioio_server.close()
94def test_read_uint8_3channels_image_with_dask():
95 level = 0
96 full_resolution = multi_resolution_uint8_3channels.get_shapes()[level]
97 downsample = multi_resolution_uint8_3channels.get_downsamples()[level]
98 bioio_server = BioIOServer(multi_resolution_uint8_3channels.get_path())
99 expected_pixels = np.array(
100 [[[multi_resolution_uint8_3channels.get_pixel_value(downsample, x, y, c)
101 for x in range(full_resolution.x)]
102 for y in range(full_resolution.y)]
103 for c in range(full_resolution.c)],
104 multi_resolution_uint8_3channels.get_dtype()
105 )
107 image = bioio_server.level_to_dask(level).compute()
109 np.testing.assert_array_equal(image, expected_pixels)
111 bioio_server.close()
114def test_float_5d_image_name():
115 bioio_server = BioIOServer(single_resolution_float_5d.get_path())
117 name = bioio_server.metadata.name
119 assert name == single_resolution_float_5d.get_name()
121 bioio_server.close()
124def test_float_5d_image_shapes():
125 bioio_server = BioIOServer(single_resolution_float_5d.get_path())
127 shapes = bioio_server.metadata.shapes
129 assert shapes == single_resolution_float_5d.get_shapes()
131 bioio_server.close()
134def test_float_5d_image_pixel_calibration():
135 bioio_server = BioIOServer(single_resolution_float_5d.get_path())
137 pixel_calibration = bioio_server.metadata.pixel_calibration
139 assert pixel_calibration == PixelCalibration(
140 PixelLength(single_resolution_float_5d.get_pixel_size_x_y_in_micrometers()), # The BioIO library does not currently handle unit attachment
141 PixelLength(single_resolution_float_5d.get_pixel_size_x_y_in_micrometers())
142 )
144 bioio_server.close()
147def test_float_5d_image_is_not_rgb():
148 bioio_server = BioIOServer(single_resolution_float_5d.get_path())
150 is_rgb = bioio_server.metadata.is_rgb
152 assert not(is_rgb)
154 bioio_server.close()
157def test_float_5d_image_dtype():
158 bioio_server = BioIOServer(single_resolution_float_5d.get_path())
160 dtype = bioio_server.metadata.dtype
162 assert dtype == single_resolution_float_5d.get_dtype()
164 bioio_server.close()
167def test_float_5d_image_downsamples():
168 bioio_server = BioIOServer(single_resolution_float_5d.get_path())
170 downsamples = bioio_server.metadata.downsamples
172 assert downsamples == single_resolution_float_5d.get_downsamples()
174 bioio_server.close()
177def test_read_float_5d_image():
178 full_resolution = single_resolution_float_5d.get_shapes()[0]
179 z = int(full_resolution.z / 2)
180 t = int(full_resolution.t / 2)
181 bioio_server = BioIOServer(single_resolution_float_5d.get_path())
182 expected_pixels = np.array(
183 [[[single_resolution_float_5d.get_pixel_value(x, y, c, z, t)
184 for x in range(full_resolution.x)]
185 for y in range(full_resolution.y)]
186 for c in range(full_resolution.c)],
187 single_resolution_float_5d.get_dtype()
188 )
190 image = bioio_server.read_region(
191 1,
192 Region2D(width=bioio_server.metadata.width, height=bioio_server.metadata.height, z=z, t=t)
193 )
195 np.testing.assert_array_equal(image, expected_pixels)
197 bioio_server.close()
200def test_read_float_5d_image_with_dask():
201 full_resolution = single_resolution_float_5d.get_shapes()[0]
202 bioio_server = BioIOServer(single_resolution_float_5d.get_path())
203 expected_pixels = np.array(
204 [[[[[single_resolution_float_5d.get_pixel_value(x, y, c, z, t)
205 for x in range(full_resolution.x)]
206 for y in range(full_resolution.y)]
207 for z in range(full_resolution.z)]
208 for c in range(full_resolution.c)]
209 for t in range(full_resolution.t)],
210 single_resolution_float_5d.get_dtype()
211 )
213 image = bioio_server.level_to_dask(0).compute()
215 np.testing.assert_array_equal(image, expected_pixels)
217 bioio_server.close()
221def test_float_5d_zarr_image_name():
222 bioio_server = BioIOServer(single_resolution_float_5d_zarr.get_path())
224 name = bioio_server.metadata.name
226 assert name == single_resolution_float_5d_zarr.get_name()
228 bioio_server.close()
231def test_float_5d_zarr_image_shapes():
232 bioio_server = BioIOServer(single_resolution_float_5d_zarr.get_path())
234 shapes = bioio_server.metadata.shapes
236 assert shapes == single_resolution_float_5d_zarr.get_shapes()
238 bioio_server.close()
241def test_float_5d_zarr_image_pixel_calibration():
242 bioio_server = BioIOServer(single_resolution_float_5d_zarr.get_path())
244 pixel_calibration = bioio_server.metadata.pixel_calibration
246 assert pixel_calibration == PixelCalibration(
247 PixelLength(single_resolution_float_5d_zarr.get_pixel_size_x_y_in_micrometers()), # The BioIO library does not currently handle unit attachment
248 PixelLength(single_resolution_float_5d_zarr.get_pixel_size_x_y_in_micrometers()),
249 PixelLength(single_resolution_float_5d_zarr.get_pixel_size_x_y_in_micrometers())
250 )
252 bioio_server.close()
255def test_float_5d_zarr_image_is_not_rgb():
256 bioio_server = BioIOServer(single_resolution_float_5d_zarr.get_path())
258 is_rgb = bioio_server.metadata.is_rgb
260 assert not(is_rgb)
262 bioio_server.close()
265def test_float_5d_zarr_image_dtype():
266 bioio_server = BioIOServer(single_resolution_float_5d_zarr.get_path())
268 dtype = bioio_server.metadata.dtype
270 assert dtype == single_resolution_float_5d_zarr.get_dtype()
272 bioio_server.close()
275def test_float_5d_zarr_image_downsamples():
276 bioio_server = BioIOServer(single_resolution_float_5d_zarr.get_path())
278 downsamples = bioio_server.metadata.downsamples
280 assert downsamples == single_resolution_float_5d_zarr.get_downsamples()
282 bioio_server.close()
285def test_read_float_5d_zarr_image():
286 full_resolution = single_resolution_float_5d_zarr.get_shapes()[0]
287 z = int(full_resolution.z / 2)
288 t = int(full_resolution.t / 2)
289 bioio_server = BioIOServer(single_resolution_float_5d_zarr.get_path())
290 expected_pixels = np.array(
291 [[[single_resolution_float_5d_zarr.get_pixel_value(x, y, c, z, t)
292 for x in range(full_resolution.x)]
293 for y in range(full_resolution.y)]
294 for c in range(full_resolution.c)],
295 single_resolution_float_5d_zarr.get_dtype()
296 )
298 image = bioio_server.read_region(
299 1,
300 Region2D(width=bioio_server.metadata.width, height=bioio_server.metadata.height, z=z, t=t)
301 )
303 np.testing.assert_array_equal(image, expected_pixels)
305 bioio_server.close()
308def test_read_float_5d_zarr_image_with_dask():
309 full_resolution = single_resolution_float_5d_zarr.get_shapes()[0]
310 bioio_server = BioIOServer(single_resolution_float_5d_zarr.get_path())
311 expected_pixels = np.array(
312 [[[[[single_resolution_float_5d_zarr.get_pixel_value(x, y, c, z, t)
313 for x in range(full_resolution.x)]
314 for y in range(full_resolution.y)]
315 for z in range(full_resolution.z)]
316 for c in range(full_resolution.c)]
317 for t in range(full_resolution.t)],
318 single_resolution_float_5d_zarr.get_dtype()
319 )
321 image = bioio_server.level_to_dask(0).compute()
323 np.testing.assert_array_equal(image, expected_pixels)
325 bioio_server.close()
328def test_rgb_image_name():
329 bioio_server = BioIOServer(single_resolution_rgb_image.get_path())
331 name = bioio_server.metadata.name
333 assert name == single_resolution_rgb_image.get_name()
335 bioio_server.close()
338def test_rgb_image_shapes():
339 bioio_server = BioIOServer(single_resolution_rgb_image.get_path())
341 shapes = bioio_server.metadata.shapes
343 assert shapes == single_resolution_rgb_image.get_shapes()
345 bioio_server.close()
348def test_rgb_image_pixel_calibration():
349 bioio_server = BioIOServer(single_resolution_rgb_image.get_path())
351 pixel_calibration = bioio_server.metadata.pixel_calibration
353 assert pixel_calibration == PixelCalibration(
354 PixelLength(single_resolution_rgb_image.get_pixel_size_x_y_in_micrometers()), # The BioIO library does not currently handle unit attachment
355 PixelLength(single_resolution_rgb_image.get_pixel_size_x_y_in_micrometers())
356 )
358 bioio_server.close()
361def test_rgb_image_is_rgb():
362 bioio_server = BioIOServer(single_resolution_rgb_image.get_path())
364 is_rgb = bioio_server.metadata.is_rgb
366 assert is_rgb
368 bioio_server.close()
371def test_rgb_image_dtype():
372 bioio_server = BioIOServer(single_resolution_rgb_image.get_path())
374 dtype = bioio_server.metadata.dtype
376 assert dtype == single_resolution_rgb_image.get_dtype()
378 bioio_server.close()
381def test_rgb_image_downsamples():
382 bioio_server = BioIOServer(single_resolution_rgb_image.get_path())
384 downsamples = bioio_server.metadata.downsamples
386 assert downsamples == single_resolution_rgb_image.get_downsamples()
388 bioio_server.close()
391def test_read_rgb_image():
392 full_resolution = single_resolution_rgb_image.get_shapes()[0]
393 bioio_server = BioIOServer(single_resolution_rgb_image.get_path())
394 expected_pixels = np.array(
395 [[[single_resolution_rgb_image.get_pixel_value(x, y, c)
396 for x in range(full_resolution.x)]
397 for y in range(full_resolution.y)]
398 for c in range(full_resolution.c)],
399 single_resolution_rgb_image.get_dtype()
400 )
402 image = bioio_server.read_region(
403 1,
404 Region2D(width=bioio_server.metadata.width, height=bioio_server.metadata.height)
405 )
407 np.testing.assert_array_equal(image, expected_pixels)
409 bioio_server.close()
412def test_read_rgb_image_with_dask():
413 full_resolution = single_resolution_rgb_image.get_shapes()[0]
414 bioio_server = BioIOServer(single_resolution_rgb_image.get_path())
415 expected_pixels = np.array(
416 [[[single_resolution_rgb_image.get_pixel_value(x, y, c)
417 for x in range(full_resolution.x)]
418 for y in range(full_resolution.y)]
419 for c in range(full_resolution.c)],
420 single_resolution_rgb_image.get_dtype()
421 )
423 image = bioio_server.level_to_dask(0).compute()
425 np.testing.assert_array_equal(image, expected_pixels)
427 bioio_server.close()