ngio 0.4.8__py3-none-any.whl → 0.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ngio/__init__.py +5 -2
- ngio/common/__init__.py +11 -6
- ngio/common/_masking_roi.py +34 -54
- ngio/common/_pyramid.py +322 -75
- ngio/common/_roi.py +258 -330
- ngio/experimental/iterators/_feature.py +3 -3
- ngio/experimental/iterators/_rois_utils.py +10 -11
- ngio/hcs/_plate.py +192 -136
- ngio/images/_abstract_image.py +539 -35
- ngio/images/_create_synt_container.py +45 -47
- ngio/images/_create_utils.py +406 -0
- ngio/images/_image.py +524 -248
- ngio/images/_label.py +257 -180
- ngio/images/_masked_image.py +2 -2
- ngio/images/_ome_zarr_container.py +658 -255
- ngio/io_pipes/_io_pipes.py +9 -9
- ngio/io_pipes/_io_pipes_masked.py +7 -7
- ngio/io_pipes/_io_pipes_roi.py +6 -6
- ngio/io_pipes/_io_pipes_types.py +3 -3
- ngio/io_pipes/_match_shape.py +6 -8
- ngio/io_pipes/_ops_slices_utils.py +8 -5
- ngio/ome_zarr_meta/__init__.py +29 -18
- ngio/ome_zarr_meta/_meta_handlers.py +402 -689
- ngio/ome_zarr_meta/ngio_specs/__init__.py +4 -0
- ngio/ome_zarr_meta/ngio_specs/_axes.py +152 -51
- ngio/ome_zarr_meta/ngio_specs/_dataset.py +13 -22
- ngio/ome_zarr_meta/ngio_specs/_ngio_hcs.py +129 -91
- ngio/ome_zarr_meta/ngio_specs/_ngio_image.py +69 -69
- ngio/ome_zarr_meta/v04/__init__.py +5 -1
- ngio/ome_zarr_meta/v04/{_v04_spec_utils.py → _v04_spec.py} +55 -86
- ngio/ome_zarr_meta/v05/__init__.py +27 -0
- ngio/ome_zarr_meta/v05/_custom_models.py +18 -0
- ngio/ome_zarr_meta/v05/_v05_spec.py +495 -0
- ngio/resources/__init__.py +1 -1
- ngio/resources/resource_model.py +1 -1
- ngio/tables/_tables_container.py +82 -24
- ngio/tables/backends/_abstract_backend.py +7 -0
- ngio/tables/backends/_anndata.py +60 -7
- ngio/tables/backends/_anndata_utils.py +2 -4
- ngio/tables/backends/_csv.py +3 -19
- ngio/tables/backends/_json.py +10 -13
- ngio/tables/backends/_parquet.py +3 -31
- ngio/tables/backends/_py_arrow_backends.py +222 -0
- ngio/tables/backends/_utils.py +1 -1
- ngio/tables/v1/_roi_table.py +41 -24
- ngio/utils/__init__.py +8 -12
- ngio/utils/_cache.py +48 -0
- ngio/utils/_zarr_utils.py +354 -236
- {ngio-0.4.8.dist-info → ngio-0.5.0.dist-info}/METADATA +12 -5
- ngio-0.5.0.dist-info/RECORD +88 -0
- ngio/images/_create.py +0 -276
- ngio/tables/backends/_non_zarr_backends.py +0 -196
- ngio/utils/_logger.py +0 -50
- ngio-0.4.8.dist-info/RECORD +0 -85
- {ngio-0.4.8.dist-info → ngio-0.5.0.dist-info}/WHEEL +0 -0
- {ngio-0.4.8.dist-info → ngio-0.5.0.dist-info}/licenses/LICENSE +0 -0
ngio/hcs/_plate.py
CHANGED
|
@@ -15,15 +15,16 @@ from ngio.images import (
|
|
|
15
15
|
list_image_tables_async,
|
|
16
16
|
)
|
|
17
17
|
from ngio.ome_zarr_meta import (
|
|
18
|
+
DefaultNgffVersion,
|
|
18
19
|
ImageInWellPath,
|
|
19
20
|
NgffVersions,
|
|
20
21
|
NgioPlateMeta,
|
|
21
22
|
NgioWellMeta,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
get_plate_meta_handler,
|
|
25
|
-
get_well_meta_handler,
|
|
23
|
+
PlateMetaHandler,
|
|
24
|
+
WellMetaHandler,
|
|
26
25
|
path_in_well_validation,
|
|
26
|
+
update_ngio_plate_meta,
|
|
27
|
+
update_ngio_well_meta,
|
|
27
28
|
)
|
|
28
29
|
from ngio.tables import (
|
|
29
30
|
ConditionTable,
|
|
@@ -40,17 +41,23 @@ from ngio.tables import (
|
|
|
40
41
|
)
|
|
41
42
|
from ngio.utils import (
|
|
42
43
|
AccessModeLiteral,
|
|
44
|
+
NgioCache,
|
|
45
|
+
NgioError,
|
|
43
46
|
NgioValueError,
|
|
44
47
|
StoreOrGroup,
|
|
45
48
|
ZarrGroupHandler,
|
|
46
49
|
)
|
|
47
50
|
|
|
48
51
|
|
|
49
|
-
def
|
|
52
|
+
def _try_get_table_container(
|
|
53
|
+
handler: ZarrGroupHandler, create_mode: bool = True
|
|
54
|
+
) -> TablesContainer | None:
|
|
50
55
|
"""Return a default table container."""
|
|
51
|
-
|
|
52
|
-
|
|
56
|
+
try:
|
|
57
|
+
table_handler = handler.get_handler("tables", create_mode=create_mode)
|
|
53
58
|
return TablesContainer(table_handler)
|
|
59
|
+
except NgioError:
|
|
60
|
+
return None
|
|
54
61
|
|
|
55
62
|
|
|
56
63
|
# Mock lock class that does nothing
|
|
@@ -76,7 +83,7 @@ class OmeZarrWell:
|
|
|
76
83
|
group_handler: The Zarr group handler that contains the Well.
|
|
77
84
|
"""
|
|
78
85
|
self._group_handler = group_handler
|
|
79
|
-
self._meta_handler =
|
|
86
|
+
self._meta_handler = WellMetaHandler(group_handler)
|
|
80
87
|
|
|
81
88
|
def __repr__(self) -> str:
|
|
82
89
|
"""Return a string representation of the well."""
|
|
@@ -90,7 +97,7 @@ class OmeZarrWell:
|
|
|
90
97
|
@property
|
|
91
98
|
def meta(self):
|
|
92
99
|
"""Return the metadata."""
|
|
93
|
-
return self._meta_handler.
|
|
100
|
+
return self._meta_handler.get_meta()
|
|
94
101
|
|
|
95
102
|
@property
|
|
96
103
|
def acquisition_ids(self) -> list[int]:
|
|
@@ -136,7 +143,7 @@ class OmeZarrWell:
|
|
|
136
143
|
Returns:
|
|
137
144
|
OmeZarrContainer: The image.
|
|
138
145
|
"""
|
|
139
|
-
handler = self._group_handler.
|
|
146
|
+
handler = self._group_handler.get_handler(image_path)
|
|
140
147
|
return OmeZarrContainer(handler)
|
|
141
148
|
|
|
142
149
|
def _add_image(
|
|
@@ -158,7 +165,7 @@ class OmeZarrWell:
|
|
|
158
165
|
meta = self.meta.add_image(
|
|
159
166
|
path=image_path, acquisition=acquisition_id, strict=strict
|
|
160
167
|
)
|
|
161
|
-
self.meta_handler.
|
|
168
|
+
self.meta_handler.update_meta(meta)
|
|
162
169
|
self.meta_handler._group_handler.clean_cache()
|
|
163
170
|
|
|
164
171
|
return self._group_handler.get_group(image_path, create_mode=True)
|
|
@@ -237,8 +244,14 @@ class OmeZarrPlate:
|
|
|
237
244
|
table_container: The tables container that contains plate level tables.
|
|
238
245
|
"""
|
|
239
246
|
self._group_handler = group_handler
|
|
240
|
-
self._meta_handler =
|
|
247
|
+
self._meta_handler = PlateMetaHandler(group_handler)
|
|
241
248
|
self._tables_container = table_container
|
|
249
|
+
self._wells_cache: NgioCache[OmeZarrWell] = NgioCache(
|
|
250
|
+
use_cache=self._group_handler.use_cache
|
|
251
|
+
)
|
|
252
|
+
self._images_cache: NgioCache[OmeZarrContainer] = NgioCache(
|
|
253
|
+
use_cache=self._group_handler.use_cache
|
|
254
|
+
)
|
|
242
255
|
|
|
243
256
|
def __repr__(self) -> str:
|
|
244
257
|
"""Return a string representation of the plate."""
|
|
@@ -252,7 +265,7 @@ class OmeZarrPlate:
|
|
|
252
265
|
@property
|
|
253
266
|
def meta(self):
|
|
254
267
|
"""Return the metadata."""
|
|
255
|
-
return self._meta_handler.
|
|
268
|
+
return self._meta_handler.get_meta()
|
|
256
269
|
|
|
257
270
|
@property
|
|
258
271
|
def columns(self) -> list[str]:
|
|
@@ -356,6 +369,24 @@ class OmeZarrPlate:
|
|
|
356
369
|
well = self.get_well(row=row, column=column)
|
|
357
370
|
return well.get_image_acquisition_id(image_path=image_path)
|
|
358
371
|
|
|
372
|
+
def _get_well(self, well_path: str) -> OmeZarrWell:
|
|
373
|
+
"""Get a well from the plate by its path.
|
|
374
|
+
|
|
375
|
+
Args:
|
|
376
|
+
well_path (str): The path of the well.
|
|
377
|
+
|
|
378
|
+
Returns:
|
|
379
|
+
OmeZarrWell: The well.
|
|
380
|
+
|
|
381
|
+
"""
|
|
382
|
+
cached_well = self._wells_cache.get(well_path)
|
|
383
|
+
if cached_well is not None:
|
|
384
|
+
return cached_well
|
|
385
|
+
|
|
386
|
+
group_handler = self._group_handler.get_handler(well_path)
|
|
387
|
+
self._wells_cache.set(well_path, OmeZarrWell(group_handler))
|
|
388
|
+
return OmeZarrWell(group_handler)
|
|
389
|
+
|
|
359
390
|
def get_well(self, row: str, column: int | str) -> OmeZarrWell:
|
|
360
391
|
"""Get a well from the plate.
|
|
361
392
|
|
|
@@ -367,8 +398,7 @@ class OmeZarrPlate:
|
|
|
367
398
|
OmeZarrWell: The well.
|
|
368
399
|
"""
|
|
369
400
|
well_path = self._well_path(row=row, column=column)
|
|
370
|
-
|
|
371
|
-
return OmeZarrWell(group_handler)
|
|
401
|
+
return self._get_well(well_path=well_path)
|
|
372
402
|
|
|
373
403
|
async def get_wells_async(self) -> dict[str, OmeZarrWell]:
|
|
374
404
|
"""Get all wells in the plate asynchronously.
|
|
@@ -380,26 +410,17 @@ class OmeZarrPlate:
|
|
|
380
410
|
dict[str, OmeZarrWell]: A dictionary of wells, where the key is the well
|
|
381
411
|
path and the value is the well object.
|
|
382
412
|
"""
|
|
383
|
-
wells = self._group_handler.get_from_cache("wells")
|
|
384
|
-
if wells is not None:
|
|
385
|
-
assert isinstance(wells, dict)
|
|
386
|
-
return wells
|
|
387
|
-
|
|
388
|
-
def process_well(well_path):
|
|
389
|
-
group_handler = self._group_handler.derive_handler(well_path)
|
|
390
|
-
well = OmeZarrWell(group_handler)
|
|
391
|
-
return well_path, well
|
|
392
|
-
|
|
393
413
|
wells, tasks = {}, []
|
|
394
414
|
for well_path in self.wells_paths():
|
|
395
|
-
task = asyncio.to_thread(
|
|
415
|
+
task = asyncio.to_thread(
|
|
416
|
+
lambda well_path: (well_path, self._get_well(well_path)), well_path
|
|
417
|
+
)
|
|
396
418
|
tasks.append(task)
|
|
397
419
|
|
|
398
420
|
results = await asyncio.gather(*tasks)
|
|
399
421
|
for well_path, well in results:
|
|
400
422
|
wells[well_path] = well
|
|
401
423
|
|
|
402
|
-
self._group_handler.add_to_cache("wells", wells)
|
|
403
424
|
return wells
|
|
404
425
|
|
|
405
426
|
def get_wells(self) -> dict[str, OmeZarrWell]:
|
|
@@ -409,24 +430,25 @@ class OmeZarrPlate:
|
|
|
409
430
|
dict[str, OmeZarrWell]: A dictionary of wells, where the key is the well
|
|
410
431
|
path and the value is the well object.
|
|
411
432
|
"""
|
|
412
|
-
wells = self._group_handler.get_from_cache("wells")
|
|
413
|
-
if wells is not None:
|
|
414
|
-
assert isinstance(wells, dict)
|
|
415
|
-
return wells
|
|
416
|
-
|
|
417
|
-
def process_well(well_path):
|
|
418
|
-
group_handler = self._group_handler.derive_handler(well_path)
|
|
419
|
-
well = OmeZarrWell(group_handler)
|
|
420
|
-
return well_path, well
|
|
421
|
-
|
|
422
433
|
wells = {}
|
|
423
434
|
for well_path in self.wells_paths():
|
|
424
|
-
|
|
425
|
-
wells[well_path] = well
|
|
426
|
-
|
|
427
|
-
self._group_handler.add_to_cache("wells", wells)
|
|
435
|
+
wells[well_path] = self._get_well(well_path)
|
|
428
436
|
return wells
|
|
429
437
|
|
|
438
|
+
def _get_image(self, image_path: str) -> OmeZarrContainer:
|
|
439
|
+
"""Get an image from the plate by its path.
|
|
440
|
+
|
|
441
|
+
Args:
|
|
442
|
+
image_path (str): The path of the image.
|
|
443
|
+
"""
|
|
444
|
+
cached_image = self._images_cache.get(image_path)
|
|
445
|
+
if cached_image is not None:
|
|
446
|
+
return cached_image
|
|
447
|
+
img_group_handler = self._group_handler.get_handler(image_path)
|
|
448
|
+
image = OmeZarrContainer(img_group_handler)
|
|
449
|
+
self._images_cache.set(image_path, image)
|
|
450
|
+
return image
|
|
451
|
+
|
|
430
452
|
async def get_images_async(
|
|
431
453
|
self, acquisition: int | None = None
|
|
432
454
|
) -> dict[str, OmeZarrContainer]:
|
|
@@ -442,30 +464,19 @@ class OmeZarrPlate:
|
|
|
442
464
|
dict[str, OmeZarrContainer]: A dictionary of images, where the key is the
|
|
443
465
|
image path and the value is the image object.
|
|
444
466
|
"""
|
|
445
|
-
images = self._group_handler.get_from_cache("images")
|
|
446
|
-
if images is not None:
|
|
447
|
-
assert isinstance(images, dict)
|
|
448
|
-
return images
|
|
449
|
-
|
|
450
467
|
paths = await self.images_paths_async(acquisition=acquisition)
|
|
451
468
|
|
|
452
|
-
def process_image(image_path):
|
|
453
|
-
"""Process a single image and return the image path and image object."""
|
|
454
|
-
img_group_handler = self._group_handler.derive_handler(image_path)
|
|
455
|
-
image = OmeZarrContainer(img_group_handler)
|
|
456
|
-
return image_path, image
|
|
457
|
-
|
|
458
469
|
images, tasks = {}, []
|
|
459
470
|
for image_path in paths:
|
|
460
|
-
task = asyncio.to_thread(
|
|
471
|
+
task = asyncio.to_thread(
|
|
472
|
+
lambda image_path: (image_path, self._get_image(image_path)), image_path
|
|
473
|
+
)
|
|
461
474
|
tasks.append(task)
|
|
462
475
|
|
|
463
476
|
results = await asyncio.gather(*tasks)
|
|
464
477
|
|
|
465
478
|
for image_path, image in results:
|
|
466
479
|
images[image_path] = image
|
|
467
|
-
|
|
468
|
-
self._group_handler.add_to_cache("images", images)
|
|
469
480
|
return images
|
|
470
481
|
|
|
471
482
|
def get_images(self, acquisition: int | None = None) -> dict[str, OmeZarrContainer]:
|
|
@@ -474,24 +485,11 @@ class OmeZarrPlate:
|
|
|
474
485
|
Args:
|
|
475
486
|
acquisition: The acquisition id to filter the images.
|
|
476
487
|
"""
|
|
477
|
-
images = self._group_handler.get_from_cache("images")
|
|
478
|
-
if images is not None:
|
|
479
|
-
assert isinstance(images, dict)
|
|
480
|
-
return images
|
|
481
488
|
paths = self.images_paths(acquisition=acquisition)
|
|
482
|
-
|
|
483
|
-
def process_image(image_path):
|
|
484
|
-
"""Process a single image and return the image path and image object."""
|
|
485
|
-
img_group_handler = self._group_handler.derive_handler(image_path)
|
|
486
|
-
image = OmeZarrContainer(img_group_handler)
|
|
487
|
-
return image_path, image
|
|
488
|
-
|
|
489
489
|
images = {}
|
|
490
490
|
for image_path in paths:
|
|
491
|
-
|
|
492
|
-
images[image_path] = image
|
|
491
|
+
images[image_path] = self._get_image(image_path)
|
|
493
492
|
|
|
494
|
-
self._group_handler.add_to_cache("images", images)
|
|
495
493
|
return images
|
|
496
494
|
|
|
497
495
|
def get_image(
|
|
@@ -508,8 +506,7 @@ class OmeZarrPlate:
|
|
|
508
506
|
OmeZarrContainer: The image.
|
|
509
507
|
"""
|
|
510
508
|
image_path = self._image_path(row=row, column=column, path=image_path)
|
|
511
|
-
|
|
512
|
-
return OmeZarrContainer(group_handler)
|
|
509
|
+
return self._get_image(image_path)
|
|
513
510
|
|
|
514
511
|
def get_image_store(
|
|
515
512
|
self, row: str, column: int | str, image_path: str
|
|
@@ -538,7 +535,7 @@ class OmeZarrPlate:
|
|
|
538
535
|
for image_paths in self.well_images_paths(
|
|
539
536
|
row=row, column=column, acquisition=acquisition
|
|
540
537
|
):
|
|
541
|
-
group_handler = self._group_handler.
|
|
538
|
+
group_handler = self._group_handler.get_handler(image_paths)
|
|
542
539
|
images[image_paths] = OmeZarrContainer(group_handler)
|
|
543
540
|
return images
|
|
544
541
|
|
|
@@ -567,11 +564,11 @@ class OmeZarrPlate:
|
|
|
567
564
|
meta = meta.add_acquisition(
|
|
568
565
|
acquisition_id=acquisition_id, acquisition_name=acquisition_name
|
|
569
566
|
)
|
|
570
|
-
self.meta_handler.
|
|
567
|
+
self.meta_handler.update_meta(meta)
|
|
571
568
|
self.meta_handler._group_handler.clean_cache()
|
|
572
569
|
|
|
573
570
|
well_path = self.meta.get_well_path(row=row, column=column)
|
|
574
|
-
group_handler = self._group_handler.
|
|
571
|
+
group_handler = self._group_handler.get_handler(well_path)
|
|
575
572
|
|
|
576
573
|
if atomic:
|
|
577
574
|
well_lock = group_handler.lock
|
|
@@ -586,18 +583,19 @@ class OmeZarrPlate:
|
|
|
586
583
|
well_meta = NgioWellMeta.default_init()
|
|
587
584
|
version = self.meta.plate.version
|
|
588
585
|
version = version if version is not None else "0.4"
|
|
589
|
-
|
|
586
|
+
update_ngio_well_meta(group_handler, well_meta)
|
|
587
|
+
meta_handler = WellMetaHandler(group_handler=group_handler)
|
|
590
588
|
else:
|
|
591
|
-
meta_handler =
|
|
592
|
-
well_meta = meta_handler.
|
|
589
|
+
meta_handler = WellMetaHandler(group_handler=group_handler)
|
|
590
|
+
well_meta = meta_handler.get_meta()
|
|
593
591
|
|
|
594
|
-
group_handler = self._group_handler.
|
|
592
|
+
group_handler = self._group_handler.get_handler(well_path)
|
|
595
593
|
|
|
596
594
|
if image_path is not None:
|
|
597
595
|
well_meta = well_meta.add_image(
|
|
598
596
|
path=image_path, acquisition=acquisition_id, strict=False
|
|
599
597
|
)
|
|
600
|
-
meta_handler.
|
|
598
|
+
meta_handler.update_meta(well_meta)
|
|
601
599
|
meta_handler._group_handler.clean_cache()
|
|
602
600
|
|
|
603
601
|
if image_path is not None:
|
|
@@ -674,7 +672,7 @@ class OmeZarrPlate:
|
|
|
674
672
|
) -> "OmeZarrPlate":
|
|
675
673
|
"""Add a column to an ome-zarr plate."""
|
|
676
674
|
meta, _ = self.meta.add_column(column)
|
|
677
|
-
self.meta_handler.
|
|
675
|
+
self.meta_handler.update_meta(meta)
|
|
678
676
|
self.meta_handler._group_handler.clean_cache()
|
|
679
677
|
return self
|
|
680
678
|
|
|
@@ -684,7 +682,7 @@ class OmeZarrPlate:
|
|
|
684
682
|
) -> "OmeZarrPlate":
|
|
685
683
|
"""Add a row to an ome-zarr plate."""
|
|
686
684
|
meta, _ = self.meta.add_row(row)
|
|
687
|
-
self.meta_handler.
|
|
685
|
+
self.meta_handler.update_meta(meta)
|
|
688
686
|
self.meta_handler._group_handler.clean_cache()
|
|
689
687
|
return self
|
|
690
688
|
|
|
@@ -704,7 +702,7 @@ class OmeZarrPlate:
|
|
|
704
702
|
meta = self.meta.add_acquisition(
|
|
705
703
|
acquisition_id=acquisition_id, acquisition_name=acquisition_name
|
|
706
704
|
)
|
|
707
|
-
self.meta_handler.
|
|
705
|
+
self.meta_handler.update_meta(meta)
|
|
708
706
|
self.meta_handler._group_handler.clean_cache()
|
|
709
707
|
return self
|
|
710
708
|
|
|
@@ -723,7 +721,7 @@ class OmeZarrPlate:
|
|
|
723
721
|
with plate_lock:
|
|
724
722
|
meta = self.meta
|
|
725
723
|
meta = meta.remove_well(row, column)
|
|
726
|
-
self.meta_handler.
|
|
724
|
+
self.meta_handler.update_meta(meta)
|
|
727
725
|
self.meta_handler._group_handler.clean_cache()
|
|
728
726
|
|
|
729
727
|
def _remove_image(
|
|
@@ -744,7 +742,7 @@ class OmeZarrPlate:
|
|
|
744
742
|
with well_lock:
|
|
745
743
|
well_meta = well.meta
|
|
746
744
|
well_meta = well_meta.remove_image(path=image_path)
|
|
747
|
-
well.meta_handler.
|
|
745
|
+
well.meta_handler.update_meta(well_meta)
|
|
748
746
|
well.meta_handler._group_handler.clean_cache()
|
|
749
747
|
if len(well_meta.paths()) == 0:
|
|
750
748
|
self._remove_well(row, column, atomic=atomic)
|
|
@@ -781,41 +779,42 @@ class OmeZarrPlate:
|
|
|
781
779
|
self,
|
|
782
780
|
store: StoreOrGroup,
|
|
783
781
|
plate_name: str | None = None,
|
|
784
|
-
version: NgffVersions =
|
|
782
|
+
version: NgffVersions | None = None,
|
|
783
|
+
ngff_version: NgffVersions = DefaultNgffVersion,
|
|
785
784
|
keep_acquisitions: bool = False,
|
|
786
785
|
cache: bool = False,
|
|
787
786
|
overwrite: bool = False,
|
|
788
|
-
parallel_safe: bool = True,
|
|
789
787
|
) -> "OmeZarrPlate":
|
|
790
788
|
"""Derive a new OME-Zarr plate from an existing one.
|
|
791
789
|
|
|
792
790
|
Args:
|
|
793
791
|
store (StoreOrGroup): The Zarr store or group that stores the plate.
|
|
794
792
|
plate_name (str | None): The name of the new plate.
|
|
795
|
-
version (NgffVersion):
|
|
793
|
+
version (NgffVersion | None): Deprecated. Please use 'ngff_version' instead.
|
|
794
|
+
ngff_version (NgffVersion): The NGFF version to use for the new plate.
|
|
796
795
|
keep_acquisitions (bool): Whether to keep the acquisitions in the new plate.
|
|
797
796
|
cache (bool): Whether to use a cache for the zarr group metadata.
|
|
798
797
|
overwrite (bool): Whether to overwrite the existing plate.
|
|
799
|
-
parallel_safe (bool): Whether the group handler is parallel safe.
|
|
800
798
|
"""
|
|
801
799
|
return derive_ome_zarr_plate(
|
|
802
800
|
ome_zarr_plate=self,
|
|
803
801
|
store=store,
|
|
804
802
|
plate_name=plate_name,
|
|
803
|
+
ngff_version=ngff_version,
|
|
805
804
|
version=version,
|
|
806
805
|
keep_acquisitions=keep_acquisitions,
|
|
807
806
|
cache=cache,
|
|
808
807
|
overwrite=overwrite,
|
|
809
|
-
parallel_safe=parallel_safe,
|
|
810
808
|
)
|
|
811
809
|
|
|
812
|
-
def _get_tables_container(self) -> TablesContainer | None:
|
|
810
|
+
def _get_tables_container(self, create_mode: bool = True) -> TablesContainer | None:
|
|
813
811
|
"""Return the tables container."""
|
|
814
|
-
if self._tables_container is None:
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
812
|
+
if self._tables_container is not None:
|
|
813
|
+
return self._tables_container
|
|
814
|
+
_tables_container = _try_get_table_container(
|
|
815
|
+
self._group_handler, create_mode=create_mode
|
|
816
|
+
)
|
|
817
|
+
self._tables_container = _tables_container
|
|
819
818
|
return self._tables_container
|
|
820
819
|
|
|
821
820
|
@property
|
|
@@ -830,17 +829,20 @@ class OmeZarrPlate:
|
|
|
830
829
|
|
|
831
830
|
def list_tables(self, filter_types: TypedTable | str | None = None) -> list[str]:
|
|
832
831
|
"""List all tables in the image."""
|
|
832
|
+
_tables_container = self._get_tables_container(create_mode=False)
|
|
833
|
+
if _tables_container is None:
|
|
834
|
+
return []
|
|
833
835
|
return self.tables_container.list(filter_types=filter_types)
|
|
834
836
|
|
|
835
837
|
def list_roi_tables(self) -> list[str]:
|
|
836
838
|
"""List all ROI tables in the image."""
|
|
837
|
-
masking_roi = self.tables_container.list(
|
|
838
|
-
filter_types="masking_roi_table",
|
|
839
|
-
)
|
|
840
839
|
roi = self.tables_container.list(
|
|
841
840
|
filter_types="roi_table",
|
|
842
841
|
)
|
|
843
|
-
|
|
842
|
+
masking_roi = self.tables_container.list(
|
|
843
|
+
filter_types="masking_roi_table",
|
|
844
|
+
)
|
|
845
|
+
return roi + masking_roi
|
|
844
846
|
|
|
845
847
|
def get_roi_table(self, name: str) -> RoiTable:
|
|
846
848
|
"""Get a ROI table from the image.
|
|
@@ -917,8 +919,8 @@ class OmeZarrPlate:
|
|
|
917
919
|
"""
|
|
918
920
|
if check_type is not None:
|
|
919
921
|
warnings.warn(
|
|
920
|
-
"The 'check_type' argument is deprecated
|
|
921
|
-
"ngio=0.
|
|
922
|
+
"The 'check_type' argument is deprecated and will be removed in "
|
|
923
|
+
"ngio=0.6. Please use 'get_table_as' instead or one of the "
|
|
922
924
|
"type specific get_*table() methods.",
|
|
923
925
|
DeprecationWarning,
|
|
924
926
|
stacklevel=2,
|
|
@@ -957,6 +959,25 @@ class OmeZarrPlate:
|
|
|
957
959
|
name=name, table=table, backend=backend, overwrite=overwrite
|
|
958
960
|
)
|
|
959
961
|
|
|
962
|
+
def delete_table(self, name: str, missing_ok: bool = False) -> None:
|
|
963
|
+
"""Delete a table from the group.
|
|
964
|
+
|
|
965
|
+
Args:
|
|
966
|
+
name (str): The name of the table to delete.
|
|
967
|
+
missing_ok (bool): If True, do not raise an error if the table does not
|
|
968
|
+
exist.
|
|
969
|
+
|
|
970
|
+
"""
|
|
971
|
+
table_container = self._get_tables_container(create_mode=False)
|
|
972
|
+
if table_container is None and missing_ok:
|
|
973
|
+
return
|
|
974
|
+
if table_container is None:
|
|
975
|
+
raise NgioValueError(
|
|
976
|
+
f"No tables found in the image, cannot delete {name}. "
|
|
977
|
+
"Set missing_ok=True to ignore this error."
|
|
978
|
+
)
|
|
979
|
+
table_container.delete(name=name, missing_ok=missing_ok)
|
|
980
|
+
|
|
960
981
|
def list_image_tables(
|
|
961
982
|
self,
|
|
962
983
|
acquisition: int | None = None,
|
|
@@ -1143,7 +1164,6 @@ def open_ome_zarr_plate(
|
|
|
1143
1164
|
store: StoreOrGroup,
|
|
1144
1165
|
cache: bool = False,
|
|
1145
1166
|
mode: AccessModeLiteral = "r+",
|
|
1146
|
-
parallel_safe: bool = True,
|
|
1147
1167
|
) -> OmeZarrPlate:
|
|
1148
1168
|
"""Open an OME-Zarr plate.
|
|
1149
1169
|
|
|
@@ -1152,27 +1172,32 @@ def open_ome_zarr_plate(
|
|
|
1152
1172
|
cache (bool): Whether to use a cache for the zarr group metadata.
|
|
1153
1173
|
mode (AccessModeLiteral): The
|
|
1154
1174
|
access mode for the image. Defaults to "r+".
|
|
1155
|
-
parallel_safe (bool): Whether the group handler is parallel safe.
|
|
1156
1175
|
"""
|
|
1157
|
-
group_handler = ZarrGroupHandler(
|
|
1158
|
-
store=store, cache=cache, mode=mode, parallel_safe=parallel_safe
|
|
1159
|
-
)
|
|
1176
|
+
group_handler = ZarrGroupHandler(store=store, cache=cache, mode=mode)
|
|
1160
1177
|
return OmeZarrPlate(group_handler)
|
|
1161
1178
|
|
|
1162
1179
|
|
|
1163
1180
|
def _create_empty_plate_from_meta(
|
|
1164
1181
|
store: StoreOrGroup,
|
|
1165
1182
|
meta: NgioPlateMeta,
|
|
1166
|
-
version: NgffVersions = "0.4",
|
|
1167
1183
|
overwrite: bool = False,
|
|
1168
1184
|
) -> ZarrGroupHandler:
|
|
1169
|
-
"""Create an empty OME-Zarr plate from metadata.
|
|
1185
|
+
"""Create an empty OME-Zarr plate from metadata.
|
|
1186
|
+
|
|
1187
|
+
Args:
|
|
1188
|
+
store: The Zarr store or group to create the plate in.
|
|
1189
|
+
meta: The plate metadata to use.
|
|
1190
|
+
overwrite: Whether to overwrite an existing plate.
|
|
1191
|
+
|
|
1192
|
+
Returns:
|
|
1193
|
+
The ZarrGroupHandler for the created plate.
|
|
1194
|
+
"""
|
|
1170
1195
|
mode = "w" if overwrite else "w-"
|
|
1196
|
+
zarr_format = 2 if meta.plate.version == "0.4" else 3
|
|
1171
1197
|
group_handler = ZarrGroupHandler(
|
|
1172
|
-
store=store, cache=True, mode=mode,
|
|
1198
|
+
store=store, cache=True, mode=mode, zarr_format=zarr_format
|
|
1173
1199
|
)
|
|
1174
|
-
|
|
1175
|
-
meta_handler.write_meta(meta)
|
|
1200
|
+
update_ngio_plate_meta(group_handler, meta)
|
|
1176
1201
|
return group_handler
|
|
1177
1202
|
|
|
1178
1203
|
|
|
@@ -1180,20 +1205,38 @@ def create_empty_plate(
|
|
|
1180
1205
|
store: StoreOrGroup,
|
|
1181
1206
|
name: str,
|
|
1182
1207
|
images: list[ImageInWellPath] | None = None,
|
|
1183
|
-
version: NgffVersions =
|
|
1208
|
+
version: NgffVersions | None = None,
|
|
1209
|
+
ngff_version: NgffVersions = DefaultNgffVersion,
|
|
1184
1210
|
cache: bool = False,
|
|
1185
1211
|
overwrite: bool = False,
|
|
1186
|
-
parallel_safe: bool = True,
|
|
1187
1212
|
) -> OmeZarrPlate:
|
|
1188
|
-
"""Initialize and create an empty OME-Zarr plate.
|
|
1213
|
+
"""Initialize and create an empty OME-Zarr plate.
|
|
1214
|
+
|
|
1215
|
+
Args:
|
|
1216
|
+
store (StoreOrGroup): The Zarr store or group that stores the plate.
|
|
1217
|
+
name (str): The name of the plate.
|
|
1218
|
+
images (list[ImageInWellPath] | None): A list of images to add to the plate.
|
|
1219
|
+
If None, no images are added. Defaults to None.
|
|
1220
|
+
version (NgffVersion | None): Deprecated. Please use 'ngff_version' instead.
|
|
1221
|
+
ngff_version (NgffVersion): The NGFF version to use for the new plate.
|
|
1222
|
+
cache (bool): Whether to use a cache for the zarr group metadata.
|
|
1223
|
+
overwrite (bool): Whether to overwrite the existing plate.
|
|
1224
|
+
"""
|
|
1225
|
+
if version is not None:
|
|
1226
|
+
warnings.warn(
|
|
1227
|
+
"The 'version' argument is deprecated and will be removed in ngio=0.6. "
|
|
1228
|
+
"Please use 'ngff_version' instead.",
|
|
1229
|
+
DeprecationWarning,
|
|
1230
|
+
stacklevel=2,
|
|
1231
|
+
)
|
|
1232
|
+
ngff_version = version
|
|
1189
1233
|
plate_meta = NgioPlateMeta.default_init(
|
|
1190
1234
|
name=name,
|
|
1191
|
-
|
|
1235
|
+
ngff_version=ngff_version,
|
|
1192
1236
|
)
|
|
1193
1237
|
group_handler = _create_empty_plate_from_meta(
|
|
1194
1238
|
store=store,
|
|
1195
1239
|
meta=plate_meta,
|
|
1196
|
-
version=version,
|
|
1197
1240
|
overwrite=overwrite,
|
|
1198
1241
|
)
|
|
1199
1242
|
|
|
@@ -1211,7 +1254,6 @@ def create_empty_plate(
|
|
|
1211
1254
|
store=store,
|
|
1212
1255
|
cache=cache,
|
|
1213
1256
|
mode="r+",
|
|
1214
|
-
parallel_safe=parallel_safe,
|
|
1215
1257
|
)
|
|
1216
1258
|
|
|
1217
1259
|
|
|
@@ -1219,11 +1261,11 @@ def derive_ome_zarr_plate(
|
|
|
1219
1261
|
ome_zarr_plate: OmeZarrPlate,
|
|
1220
1262
|
store: StoreOrGroup,
|
|
1221
1263
|
plate_name: str | None = None,
|
|
1222
|
-
version: NgffVersions =
|
|
1264
|
+
version: NgffVersions | None = None,
|
|
1265
|
+
ngff_version: NgffVersions = DefaultNgffVersion,
|
|
1223
1266
|
keep_acquisitions: bool = False,
|
|
1224
1267
|
cache: bool = False,
|
|
1225
1268
|
overwrite: bool = False,
|
|
1226
|
-
parallel_safe: bool = True,
|
|
1227
1269
|
) -> OmeZarrPlate:
|
|
1228
1270
|
"""Derive a new OME-Zarr plate from an existing one.
|
|
1229
1271
|
|
|
@@ -1231,31 +1273,38 @@ def derive_ome_zarr_plate(
|
|
|
1231
1273
|
ome_zarr_plate (OmeZarrPlate): The existing OME-Zarr plate.
|
|
1232
1274
|
store (StoreOrGroup): The Zarr store or group that stores the plate.
|
|
1233
1275
|
plate_name (str | None): The name of the new plate.
|
|
1234
|
-
version (NgffVersion):
|
|
1276
|
+
version (NgffVersion | None): Deprecated. Please use 'ngff_version' instead.
|
|
1277
|
+
ngff_version (NgffVersion): The NGFF version to use for the new plate.
|
|
1235
1278
|
keep_acquisitions (bool): Whether to keep the acquisitions in the new plate.
|
|
1236
1279
|
cache (bool): Whether to use a cache for the zarr group metadata.
|
|
1237
1280
|
overwrite (bool): Whether to overwrite the existing plate.
|
|
1238
|
-
parallel_safe (bool): Whether the group handler is parallel safe.
|
|
1239
1281
|
"""
|
|
1282
|
+
if version is not None:
|
|
1283
|
+
warnings.warn(
|
|
1284
|
+
"The 'version' argument is deprecated and will be removed in ngio=0.6. "
|
|
1285
|
+
"Please use 'ngff_version' instead.",
|
|
1286
|
+
DeprecationWarning,
|
|
1287
|
+
stacklevel=2,
|
|
1288
|
+
)
|
|
1289
|
+
ngff_version = version
|
|
1290
|
+
|
|
1240
1291
|
if plate_name is None:
|
|
1241
1292
|
plate_name = ome_zarr_plate.meta.plate.name
|
|
1242
1293
|
|
|
1243
1294
|
new_meta = ome_zarr_plate.meta.derive(
|
|
1244
1295
|
name=plate_name,
|
|
1245
|
-
|
|
1296
|
+
ngff_version=ngff_version,
|
|
1246
1297
|
keep_acquisitions=keep_acquisitions,
|
|
1247
1298
|
)
|
|
1248
1299
|
_ = _create_empty_plate_from_meta(
|
|
1249
1300
|
store=store,
|
|
1250
1301
|
meta=new_meta,
|
|
1251
1302
|
overwrite=overwrite,
|
|
1252
|
-
version=version,
|
|
1253
1303
|
)
|
|
1254
1304
|
return open_ome_zarr_plate(
|
|
1255
1305
|
store=store,
|
|
1256
1306
|
cache=cache,
|
|
1257
1307
|
mode="r+",
|
|
1258
|
-
parallel_safe=parallel_safe,
|
|
1259
1308
|
)
|
|
1260
1309
|
|
|
1261
1310
|
|
|
@@ -1263,7 +1312,6 @@ def open_ome_zarr_well(
|
|
|
1263
1312
|
store: StoreOrGroup,
|
|
1264
1313
|
cache: bool = False,
|
|
1265
1314
|
mode: AccessModeLiteral = "r+",
|
|
1266
|
-
parallel_safe: bool = True,
|
|
1267
1315
|
) -> OmeZarrWell:
|
|
1268
1316
|
"""Open an OME-Zarr well.
|
|
1269
1317
|
|
|
@@ -1271,40 +1319,48 @@ def open_ome_zarr_well(
|
|
|
1271
1319
|
store (StoreOrGroup): The Zarr store or group that stores the plate.
|
|
1272
1320
|
cache (bool): Whether to use a cache for the zarr group metadata.
|
|
1273
1321
|
mode (AccessModeLiteral): The access mode for the image. Defaults to "r+".
|
|
1274
|
-
parallel_safe (bool): Whether the group handler is parallel safe.
|
|
1275
1322
|
"""
|
|
1276
1323
|
group_handler = ZarrGroupHandler(
|
|
1277
|
-
store=store,
|
|
1324
|
+
store=store,
|
|
1325
|
+
cache=cache,
|
|
1326
|
+
mode=mode,
|
|
1278
1327
|
)
|
|
1279
1328
|
return OmeZarrWell(group_handler)
|
|
1280
1329
|
|
|
1281
1330
|
|
|
1282
1331
|
def create_empty_well(
|
|
1283
1332
|
store: StoreOrGroup,
|
|
1284
|
-
version: NgffVersions =
|
|
1333
|
+
version: NgffVersions | None = None,
|
|
1334
|
+
ngff_version: NgffVersions = DefaultNgffVersion,
|
|
1285
1335
|
cache: bool = False,
|
|
1286
1336
|
overwrite: bool = False,
|
|
1287
|
-
parallel_safe: bool = True,
|
|
1288
1337
|
) -> OmeZarrWell:
|
|
1289
1338
|
"""Create an empty OME-Zarr well.
|
|
1290
1339
|
|
|
1291
1340
|
Args:
|
|
1292
1341
|
store (StoreOrGroup): The Zarr store or group that stores the well.
|
|
1293
|
-
version (NgffVersion):
|
|
1342
|
+
version (NgffVersion | None): Deprecated. Please use 'ngff_version' instead.
|
|
1343
|
+
ngff_version (NgffVersion): The version of the new well.
|
|
1294
1344
|
cache (bool): Whether to use a cache for the zarr group metadata.
|
|
1295
1345
|
overwrite (bool): Whether to overwrite the existing well.
|
|
1296
|
-
parallel_safe (bool): Whether the group handler is parallel safe.
|
|
1297
1346
|
"""
|
|
1347
|
+
if version is not None:
|
|
1348
|
+
warnings.warn(
|
|
1349
|
+
"The 'version' argument is deprecated and will be removed in ngio=0.6. "
|
|
1350
|
+
"Please use 'ngff_version' instead.",
|
|
1351
|
+
DeprecationWarning,
|
|
1352
|
+
stacklevel=2,
|
|
1353
|
+
)
|
|
1354
|
+
ngff_version = version
|
|
1298
1355
|
group_handler = ZarrGroupHandler(
|
|
1299
|
-
store=store, cache=True, mode="w" if overwrite else "w-"
|
|
1356
|
+
store=store, cache=True, mode="w" if overwrite else "w-"
|
|
1357
|
+
)
|
|
1358
|
+
update_ngio_well_meta(
|
|
1359
|
+
group_handler, NgioWellMeta.default_init(ngff_version=ngff_version)
|
|
1300
1360
|
)
|
|
1301
|
-
meta_handler = get_well_meta_handler(group_handler, version=version)
|
|
1302
|
-
meta = NgioWellMeta.default_init()
|
|
1303
|
-
meta_handler.write_meta(meta)
|
|
1304
1361
|
|
|
1305
1362
|
return open_ome_zarr_well(
|
|
1306
1363
|
store=store,
|
|
1307
1364
|
cache=cache,
|
|
1308
1365
|
mode="r+",
|
|
1309
|
-
parallel_safe=parallel_safe,
|
|
1310
1366
|
)
|