Skip to content

HCS API Documentation

Open a Plate

ngio.open_ome_zarr_plate

open_ome_zarr_plate(
    store: StoreOrGroup,
    cache: bool = False,
    mode: AccessModeLiteral = "r+",
) -> OmeZarrPlate

Open an OME-Zarr plate.

Parameters:

  • store (StoreOrGroup) –

    The Zarr store or group that stores the plate.

  • cache (bool, default: False ) –

    Whether to use a cache for the zarr group metadata.

  • mode (AccessModeLiteral, default: 'r+' ) –

    The access mode for the image. Defaults to "r+".

Source code in src/ngio/hcs/_plate.py
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
def open_ome_zarr_plate(
    store: StoreOrGroup,
    cache: bool = False,
    mode: AccessModeLiteral = "r+",
) -> OmeZarrPlate:
    """Open an OME-Zarr plate.

    Args:
        store (StoreOrGroup): The Zarr store or group that stores the plate.
        cache (bool): Whether to use a cache for the zarr group metadata.
        mode (AccessModeLiteral): The
            access mode for the image. Defaults to "r+".
    """
    group_handler = ZarrGroupHandler(store=store, cache=cache, mode=mode)
    return OmeZarrPlate(group_handler)

ngio.OmeZarrPlate Class Reference

ngio.OmeZarrPlate

OmeZarrPlate(
    group_handler: ZarrGroupHandler,
    table_container: TablesContainer | None = None,
)

A class to handle the Plate Sequence in an OME-Zarr file.

Initialize the LabelGroupHandler.

Parameters:

  • group_handler (ZarrGroupHandler) –

    The Zarr group handler that contains the Plate.

  • table_container (TablesContainer | None, default: None ) –

    The tables container that contains plate level tables.

Source code in src/ngio/hcs/_plate.py
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
def __init__(
    self,
    group_handler: ZarrGroupHandler,
    table_container: TablesContainer | None = None,
) -> None:
    """Initialize the LabelGroupHandler.

    Args:
        group_handler: The Zarr group handler that contains the Plate.
        table_container: The tables container that contains plate level tables.
    """
    self._group_handler = group_handler
    self._meta_handler = PlateMetaHandler(group_handler)
    self._tables_container = table_container
    self._wells_cache: NgioCache[OmeZarrWell] = NgioCache(
        use_cache=self._group_handler.use_cache
    )
    self._images_cache: NgioCache[OmeZarrContainer] = NgioCache(
        use_cache=self._group_handler.use_cache
    )

meta_handler property

meta_handler

Return the metadata handler.

meta property

meta

Return the metadata.

columns property

columns: list[str]

Return the number of columns in the plate.

rows property

rows: list[str]

Return the number of rows in the plate.

acquisitions_names property

acquisitions_names: list[str | None]

Return the acquisitions in the plate.

acquisition_ids property

acquisition_ids: list[int]

Return the acquisitions ids in the plate.

tables_container property

tables_container: TablesContainer

Return the tables container.

wells_paths

wells_paths() -> list[str]

Return the wells paths in the plate.

Source code in src/ngio/hcs/_plate.py
305
306
307
def wells_paths(self) -> list[str]:
    """Return the wells paths in the plate."""
    return self.meta.wells_paths

images_paths_async async

images_paths_async(
    acquisition: int | None = None,
) -> list[str]

Return the images paths in the plate asynchronously.

If acquisition is None, return all images paths in the plate. Else, return the images paths in the plate for the given acquisition.

Parameters:

  • acquisition (int | None, default: None ) –

    The acquisition id to filter the images.

Source code in src/ngio/hcs/_plate.py
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
async def images_paths_async(self, acquisition: int | None = None) -> list[str]:
    """Return the images paths in the plate asynchronously.

    If acquisition is None, return all images paths in the plate.
    Else, return the images paths in the plate for the given acquisition.

    Args:
        acquisition (int | None): The acquisition id to filter the images.
    """
    wells = await self.get_wells_async()
    paths = []
    for well_path, well in wells.items():
        for img_path in well.paths(acquisition):
            paths.append(f"{well_path}/{img_path}")
    return paths

images_paths

images_paths(acquisition: int | None = None) -> list[str]

Return the images paths in the plate.

If acquisition is None, return all images paths in the plate. Else, return the images paths in the plate for the given acquisition.

Parameters:

  • acquisition (int | None, default: None ) –

    The acquisition id to filter the images.

Source code in src/ngio/hcs/_plate.py
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
def images_paths(self, acquisition: int | None = None) -> list[str]:
    """Return the images paths in the plate.

    If acquisition is None, return all images paths in the plate.
    Else, return the images paths in the plate for the given acquisition.

    Args:
        acquisition (int | None): The acquisition id to filter the images.
    """
    wells = self.get_wells()
    images = []
    for well_path, well in wells.items():
        for img_path in well.paths(acquisition):
            images.append(f"{well_path}/{img_path}")
    return images

well_images_paths

well_images_paths(
    row: str,
    column: int | str,
    acquisition: int | None = None,
) -> list[str]

Return the images paths in a well.

If acquisition is None, return all images paths in the well. Else, return the images paths in the well for the given acquisition.

Parameters:

  • row (str) –

    The row of the well.

  • column (int | str) –

    The column of the well.

  • acquisition (int | None, default: None ) –

    The acquisition id to filter the images.

Source code in src/ngio/hcs/_plate.py
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
def well_images_paths(
    self, row: str, column: int | str, acquisition: int | None = None
) -> list[str]:
    """Return the images paths in a well.

    If acquisition is None, return all images paths in the well.
    Else, return the images paths in the well for the given acquisition.

    Args:
        row (str): The row of the well.
        column (int | str): The column of the well.
        acquisition (int | None): The acquisition id to filter the images.
    """
    images = []
    well = self.get_well(row=row, column=column)
    for path in well.paths(acquisition):
        images.append(self._image_path(row=row, column=column, path=path))
    return images

get_image_acquisition_id

get_image_acquisition_id(
    row: str, column: int | str, image_path: str
) -> int | None

Get the acquisition id of an image in a well.

Parameters:

  • row (str) –

    The row of the well.

  • column (int | str) –

    The column of the well.

  • image_path (str) –

    The path of the image.

Returns:

  • int | None

    int | None: The acquisition id of the image.

Source code in src/ngio/hcs/_plate.py
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
def get_image_acquisition_id(
    self, row: str, column: int | str, image_path: str
) -> int | None:
    """Get the acquisition id of an image in a well.

    Args:
        row (str): The row of the well.
        column (int | str): The column of the well.
        image_path (str): The path of the image.

    Returns:
        int | None: The acquisition id of the image.
    """
    well = self.get_well(row=row, column=column)
    return well.get_image_acquisition_id(image_path=image_path)

get_well

get_well(row: str, column: int | str) -> OmeZarrWell

Get a well from the plate.

Parameters:

  • row (str) –

    The row of the well.

  • column (int | str) –

    The column of the well.

Returns:

Source code in src/ngio/hcs/_plate.py
394
395
396
397
398
399
400
401
402
403
404
405
def get_well(self, row: str, column: int | str) -> OmeZarrWell:
    """Get a well from the plate.

    Args:
        row (str): The row of the well.
        column (int | str): The column of the well.

    Returns:
        OmeZarrWell: The well.
    """
    well_path = self._well_path(row=row, column=column)
    return self._get_well(well_path=well_path)

get_wells_async async

get_wells_async() -> dict[str, OmeZarrWell]

Get all wells in the plate asynchronously.

This method processes wells in parallel for improved performance when working with a large number of wells.

Returns:

  • dict[str, OmeZarrWell]

    dict[str, OmeZarrWell]: A dictionary of wells, where the key is the well path and the value is the well object.

Source code in src/ngio/hcs/_plate.py
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
async def get_wells_async(self) -> dict[str, OmeZarrWell]:
    """Get all wells in the plate asynchronously.

    This method processes wells in parallel for improved performance
    when working with a large number of wells.

    Returns:
        dict[str, OmeZarrWell]: A dictionary of wells, where the key is the well
            path and the value is the well object.
    """
    wells, tasks = {}, []
    for well_path in self.wells_paths():
        task = asyncio.to_thread(
            lambda well_path: (well_path, self._get_well(well_path)), well_path
        )
        tasks.append(task)

    results = await asyncio.gather(*tasks)
    for well_path, well in results:
        wells[well_path] = well

    return wells

get_wells

get_wells() -> dict[str, OmeZarrWell]

Get all wells in the plate.

Returns:

  • dict[str, OmeZarrWell]

    dict[str, OmeZarrWell]: A dictionary of wells, where the key is the well path and the value is the well object.

Source code in src/ngio/hcs/_plate.py
430
431
432
433
434
435
436
437
438
439
440
def get_wells(self) -> dict[str, OmeZarrWell]:
    """Get all wells in the plate.

    Returns:
        dict[str, OmeZarrWell]: A dictionary of wells, where the key is the well
            path and the value is the well object.
    """
    wells = {}
    for well_path in self.wells_paths():
        wells[well_path] = self._get_well(well_path)
    return wells

get_images_async async

get_images_async(
    acquisition: int | None = None,
) -> dict[str, OmeZarrContainer]

Get all images in the plate asynchronously.

This method processes images in parallel for improved performance when working with a large number of images.

Parameters:

  • acquisition (int | None, default: None ) –

    The acquisition id to filter the images.

Returns:

  • dict[str, OmeZarrContainer]

    dict[str, OmeZarrContainer]: A dictionary of images, where the key is the image path and the value is the image object.

Source code in src/ngio/hcs/_plate.py
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
async def get_images_async(
    self, acquisition: int | None = None
) -> dict[str, OmeZarrContainer]:
    """Get all images in the plate asynchronously.

    This method processes images in parallel for improved performance
    when working with a large number of images.

    Args:
        acquisition: The acquisition id to filter the images.

    Returns:
        dict[str, OmeZarrContainer]: A dictionary of images, where the key is the
            image path and the value is the image object.
    """
    paths = await self.images_paths_async(acquisition=acquisition)

    images, tasks = {}, []
    for image_path in paths:
        task = asyncio.to_thread(
            lambda image_path: (image_path, self._get_image(image_path)), image_path
        )
        tasks.append(task)

    results = await asyncio.gather(*tasks)

    for image_path, image in results:
        images[image_path] = image
    return images

get_images

get_images(
    acquisition: int | None = None,
) -> dict[str, OmeZarrContainer]

Get all images in the plate.

Parameters:

  • acquisition (int | None, default: None ) –

    The acquisition id to filter the images.

Source code in src/ngio/hcs/_plate.py
486
487
488
489
490
491
492
493
494
495
496
497
def get_images(self, acquisition: int | None = None) -> dict[str, OmeZarrContainer]:
    """Get all images in the plate.

    Args:
        acquisition: The acquisition id to filter the images.
    """
    paths = self.images_paths(acquisition=acquisition)
    images = {}
    for image_path in paths:
        images[image_path] = self._get_image(image_path)

    return images

get_image

get_image(
    row: str, column: int | str, image_path: str
) -> OmeZarrContainer

Get an image from the plate.

Parameters:

  • row (str) –

    The row of the well.

  • column (int | str) –

    The column of the well.

  • image_path (str) –

    The path of the image.

Returns:

Source code in src/ngio/hcs/_plate.py
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
def get_image(
    self, row: str, column: int | str, image_path: str
) -> OmeZarrContainer:
    """Get an image from the plate.

    Args:
        row (str): The row of the well.
        column (int | str): The column of the well.
        image_path (str): The path of the image.

    Returns:
        OmeZarrContainer: The image.
    """
    image_path = self._image_path(row=row, column=column, path=image_path)
    return self._get_image(image_path)

get_image_store

get_image_store(
    row: str, column: int | str, image_path: str
) -> StoreOrGroup

Get the image store from the plate.

Parameters:

  • row (str) –

    The row of the well.

  • column (int | str) –

    The column of the well.

  • image_path (str) –

    The path of the image.

Source code in src/ngio/hcs/_plate.py
515
516
517
518
519
520
521
522
523
524
525
526
def get_image_store(
    self, row: str, column: int | str, image_path: str
) -> StoreOrGroup:
    """Get the image store from the plate.

    Args:
        row (str): The row of the well.
        column (int | str): The column of the well.
        image_path (str): The path of the image.
    """
    well = self.get_well(row=row, column=column)
    return well.get_image_store(image_path=image_path)

get_well_images

get_well_images(
    row: str,
    column: str | int,
    acquisition: int | None = None,
) -> dict[str, OmeZarrContainer]

Get all images in a well.

Parameters:

  • row (str) –

    The row of the well.

  • column (str | int) –

    The column of the well.

  • acquisition (int | None, default: None ) –

    The acquisition id to filter the images.

Source code in src/ngio/hcs/_plate.py
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
def get_well_images(
    self, row: str, column: str | int, acquisition: int | None = None
) -> dict[str, OmeZarrContainer]:
    """Get all images in a well.

    Args:
        row: The row of the well.
        column: The column of the well.
        acquisition: The acquisition id to filter the images.
    """
    images = {}
    for image_paths in self.well_images_paths(
        row=row, column=column, acquisition=acquisition
    ):
        group_handler = self._group_handler.get_handler(image_paths)
        images[image_paths] = OmeZarrContainer(group_handler)
    return images

atomic_add_image

atomic_add_image(
    row: str,
    column: int | str,
    image_path: str,
    acquisition_id: int | None = None,
    acquisition_name: str | None = None,
) -> str

Parallel safe version of add_image.

Source code in src/ngio/hcs/_plate.py
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
def atomic_add_image(
    self,
    row: str,
    column: int | str,
    image_path: str,
    acquisition_id: int | None = None,
    acquisition_name: str | None = None,
) -> str:
    """Parallel safe version of add_image."""
    if image_path is None:
        raise ValueError(
            "Image path cannot be None for atomic add_image. "
            "If your intent is to add a well, use add_well instead."
        )
    path = self._add_image(
        row=row,
        column=column,
        image_path=image_path,
        acquisition_id=acquisition_id,
        acquisition_name=acquisition_name,
        atomic=True,
    )
    return path

add_image

add_image(
    row: str,
    column: int | str,
    image_path: str,
    acquisition_id: int | None = None,
    acquisition_name: str | None = None,
) -> str

Add an image to an ome-zarr plate.

Source code in src/ngio/hcs/_plate.py
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
def add_image(
    self,
    row: str,
    column: int | str,
    image_path: str,
    acquisition_id: int | None = None,
    acquisition_name: str | None = None,
) -> str:
    """Add an image to an ome-zarr plate."""
    if image_path is None:
        raise ValueError(
            "Image path cannot be None for atomic add_image. "
            "If your intent is to add a well, use add_well instead."
        )
    path = self._add_image(
        row=row,
        column=column,
        image_path=image_path,
        acquisition_id=acquisition_id,
        acquisition_name=acquisition_name,
        atomic=False,
    )
    return path

add_well

add_well(row: str, column: int | str) -> OmeZarrWell

Add a well to an ome-zarr plate.

Source code in src/ngio/hcs/_plate.py
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
def add_well(
    self,
    row: str,
    column: int | str,
) -> OmeZarrWell:
    """Add a well to an ome-zarr plate."""
    _ = self._add_image(
        row=row,
        column=column,
        image_path=None,
        acquisition_id=None,
        acquisition_name=None,
        atomic=False,
    )
    return self.get_well(row=row, column=column)

add_column

add_column(column: int | str) -> OmeZarrPlate

Add a column to an ome-zarr plate.

Source code in src/ngio/hcs/_plate.py
673
674
675
676
677
678
679
680
681
def add_column(
    self,
    column: int | str,
) -> "OmeZarrPlate":
    """Add a column to an ome-zarr plate."""
    meta, _ = self.meta.add_column(column)
    self.meta_handler.update_meta(meta)
    self.meta_handler._group_handler.clean_cache()
    return self

add_row

add_row(row: str) -> OmeZarrPlate

Add a row to an ome-zarr plate.

Source code in src/ngio/hcs/_plate.py
683
684
685
686
687
688
689
690
691
def add_row(
    self,
    row: str,
) -> "OmeZarrPlate":
    """Add a row to an ome-zarr plate."""
    meta, _ = self.meta.add_row(row)
    self.meta_handler.update_meta(meta)
    self.meta_handler._group_handler.clean_cache()
    return self

add_acquisition

add_acquisition(
    acquisition_id: int, acquisition_name: str
) -> OmeZarrPlate

Add an acquisition to an ome-zarr plate.

Be aware that this is not a parallel safe operation.

Parameters:

  • acquisition_id (int) –

    The acquisition id.

  • acquisition_name (str) –

    The acquisition name.

Source code in src/ngio/hcs/_plate.py
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
def add_acquisition(
    self,
    acquisition_id: int,
    acquisition_name: str,
) -> "OmeZarrPlate":
    """Add an acquisition to an ome-zarr plate.

    Be aware that this is not a parallel safe operation.

    Args:
        acquisition_id (int): The acquisition id.
        acquisition_name (str): The acquisition name.
    """
    meta = self.meta.add_acquisition(
        acquisition_id=acquisition_id, acquisition_name=acquisition_name
    )
    self.meta_handler.update_meta(meta)
    self.meta_handler._group_handler.clean_cache()
    return self

atomic_remove_image

atomic_remove_image(
    row: str, column: int | str, image_path: str
)

Parallel safe version of remove_image.

Source code in src/ngio/hcs/_plate.py
754
755
756
757
758
759
760
761
762
763
764
765
766
def atomic_remove_image(
    self,
    row: str,
    column: int | str,
    image_path: str,
):
    """Parallel safe version of remove_image."""
    return self._remove_image(
        row=row,
        column=column,
        image_path=image_path,
        atomic=True,
    )

remove_image

remove_image(row: str, column: int | str, image_path: str)

Remove an image from an ome-zarr plate.

Source code in src/ngio/hcs/_plate.py
768
769
770
771
772
773
774
775
776
777
778
779
780
def remove_image(
    self,
    row: str,
    column: int | str,
    image_path: str,
):
    """Remove an image from an ome-zarr plate."""
    return self._remove_image(
        row=row,
        column=column,
        image_path=image_path,
        atomic=False,
    )

derive_plate

derive_plate(
    store: StoreOrGroup,
    plate_name: str | None = None,
    version: NgffVersions | None = None,
    ngff_version: NgffVersions = DefaultNgffVersion,
    keep_acquisitions: bool = False,
    cache: bool = False,
    overwrite: bool = False,
) -> OmeZarrPlate

Derive a new OME-Zarr plate from an existing one.

Parameters:

  • store (StoreOrGroup) –

    The Zarr store or group that stores the plate.

  • plate_name (str | None, default: None ) –

    The name of the new plate.

  • version (NgffVersion | None, default: None ) –

    Deprecated. Please use 'ngff_version' instead.

  • ngff_version (NgffVersion, default: DefaultNgffVersion ) –

    The NGFF version to use for the new plate.

  • keep_acquisitions (bool, default: False ) –

    Whether to keep the acquisitions in the new plate.

  • cache (bool, default: False ) –

    Whether to use a cache for the zarr group metadata.

  • overwrite (bool, default: False ) –

    Whether to overwrite the existing plate.

Source code in src/ngio/hcs/_plate.py
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
def derive_plate(
    self,
    store: StoreOrGroup,
    plate_name: str | None = None,
    version: NgffVersions | None = None,
    ngff_version: NgffVersions = DefaultNgffVersion,
    keep_acquisitions: bool = False,
    cache: bool = False,
    overwrite: bool = False,
) -> "OmeZarrPlate":
    """Derive a new OME-Zarr plate from an existing one.

    Args:
        store (StoreOrGroup): The Zarr store or group that stores the plate.
        plate_name (str | None): The name of the new plate.
        version (NgffVersion | None): Deprecated. Please use 'ngff_version' instead.
        ngff_version (NgffVersion): The NGFF version to use for the new plate.
        keep_acquisitions (bool): Whether to keep the acquisitions in the new plate.
        cache (bool): Whether to use a cache for the zarr group metadata.
        overwrite (bool): Whether to overwrite the existing plate.
    """
    return derive_ome_zarr_plate(
        ome_zarr_plate=self,
        store=store,
        plate_name=plate_name,
        ngff_version=ngff_version,
        version=version,
        keep_acquisitions=keep_acquisitions,
        cache=cache,
        overwrite=overwrite,
    )

list_tables

list_tables(
    filter_types: TypedTable | str | None = None,
) -> list[str]

List all tables in the image.

Source code in src/ngio/hcs/_plate.py
834
835
836
837
838
839
def list_tables(self, filter_types: TypedTable | str | None = None) -> list[str]:
    """List all tables in the image."""
    _tables_container = self._get_tables_container(create_mode=False)
    if _tables_container is None:
        return []
    return self.tables_container.list(filter_types=filter_types)

list_roi_tables

list_roi_tables() -> list[str]

List all ROI tables in the image.

Source code in src/ngio/hcs/_plate.py
841
842
843
844
845
846
847
848
849
def list_roi_tables(self) -> list[str]:
    """List all ROI tables in the image."""
    roi = self.tables_container.list(
        filter_types="roi_table",
    )
    masking_roi = self.tables_container.list(
        filter_types="masking_roi_table",
    )
    return roi + masking_roi

get_roi_table

get_roi_table(name: str) -> RoiTable

Get a ROI table from the image.

Parameters:

  • name (str) –

    The name of the table.

Source code in src/ngio/hcs/_plate.py
851
852
853
854
855
856
857
858
859
860
def get_roi_table(self, name: str) -> RoiTable:
    """Get a ROI table from the image.

    Args:
        name (str): The name of the table.
    """
    table = self.tables_container.get(name=name, strict=True)
    if not isinstance(table, RoiTable):
        raise NgioValueError(f"Table {name} is not a ROI table. Got {type(table)}")
    return table

get_masking_roi_table

get_masking_roi_table(name: str) -> MaskingRoiTable

Get a masking ROI table from the image.

Parameters:

  • name (str) –

    The name of the table.

Source code in src/ngio/hcs/_plate.py
862
863
864
865
866
867
868
869
870
871
872
873
def get_masking_roi_table(self, name: str) -> MaskingRoiTable:
    """Get a masking ROI table from the image.

    Args:
        name (str): The name of the table.
    """
    table = self.tables_container.get(name=name, strict=True)
    if not isinstance(table, MaskingRoiTable):
        raise NgioValueError(
            f"Table {name} is not a masking ROI table. Got {type(table)}"
        )
    return table

get_feature_table

get_feature_table(name: str) -> FeatureTable

Get a feature table from the image.

Parameters:

  • name (str) –

    The name of the table.

Source code in src/ngio/hcs/_plate.py
875
876
877
878
879
880
881
882
883
884
885
886
def get_feature_table(self, name: str) -> FeatureTable:
    """Get a feature table from the image.

    Args:
        name (str): The name of the table.
    """
    table = self.tables_container.get(name=name, strict=True)
    if not isinstance(table, FeatureTable):
        raise NgioValueError(
            f"Table {name} is not a feature table. Got {type(table)}"
        )
    return table

get_generic_roi_table

get_generic_roi_table(name: str) -> GenericRoiTable

Get a generic ROI table from the image.

Parameters:

  • name (str) –

    The name of the table.

Source code in src/ngio/hcs/_plate.py
888
889
890
891
892
893
894
895
896
897
898
899
def get_generic_roi_table(self, name: str) -> GenericRoiTable:
    """Get a generic ROI table from the image.

    Args:
        name (str): The name of the table.
    """
    table = self.tables_container.get(name=name, strict=True)
    if not isinstance(table, GenericRoiTable):
        raise NgioValueError(
            f"Table {name} is not a generic ROI table. Got {type(table)}"
        )
    return table

get_condition_table

get_condition_table(name: str) -> ConditionTable

Get a condition table from the image.

Parameters:

  • name (str) –

    The name of the table.

Source code in src/ngio/hcs/_plate.py
901
902
903
904
905
906
907
908
909
910
911
912
def get_condition_table(self, name: str) -> ConditionTable:
    """Get a condition table from the image.

    Args:
        name (str): The name of the table.
    """
    table = self.tables_container.get(name=name, strict=True)
    if not isinstance(table, ConditionTable):
        raise NgioValueError(
            f"Table {name} is not a condition table. Got {type(table)}"
        )
    return table

get_table

get_table(
    name: str, check_type: TypedTable | None = None
) -> Table

Get a table from the image.

Parameters:

  • name (str) –

    The name of the table.

  • check_type (TypedTable | None, default: None ) –

    Deprecated. Please use 'get_table_as' instead, or one of the type specific get_*table() methods.

Source code in src/ngio/hcs/_plate.py
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
def get_table(self, name: str, check_type: TypedTable | None = None) -> Table:
    """Get a table from the image.

    Args:
        name (str): The name of the table.
        check_type (TypedTable | None): Deprecated. Please use
            'get_table_as' instead, or one of the type specific
            get_*table() methods.

    """
    if check_type is not None:
        warnings.warn(
            "The 'check_type' argument is deprecated and will be removed in "
            "ngio=0.6. Please use 'get_table_as' instead or one of the "
            "type specific get_*table() methods.",
            NgioDeprecationWarning,
            stacklevel=2,
        )
    return self.tables_container.get(name=name, strict=False)

get_table_as

get_table_as(
    name: str,
    table_cls: type[TableType],
    backend: TableBackend | None = None,
) -> TableType

Get a table from the image as a specific type.

Parameters:

  • name (str) –

    The name of the table.

  • table_cls (type[TableType]) –

    The type of the table.

  • backend (TableBackend | None, default: None ) –

    The backend to use. If None, the default backend is used.

Source code in src/ngio/hcs/_plate.py
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
def get_table_as(
    self,
    name: str,
    table_cls: type[TableType],
    backend: TableBackend | None = None,
) -> TableType:
    """Get a table from the image as a specific type.

    Args:
        name (str): The name of the table.
        table_cls (type[TableType]): The type of the table.
        backend (TableBackend | None): The backend to use. If None,
            the default backend is used.
    """
    return self.tables_container.get_as(
        name=name,
        table_cls=table_cls,
        backend=backend,
    )

add_table

add_table(
    name: str,
    table: Table,
    backend: TableBackend = DefaultTableBackend,
    overwrite: bool = False,
) -> None

Add a table to the image.

Source code in src/ngio/hcs/_plate.py
954
955
956
957
958
959
960
961
962
963
964
def add_table(
    self,
    name: str,
    table: Table,
    backend: TableBackend = DefaultTableBackend,
    overwrite: bool = False,
) -> None:
    """Add a table to the image."""
    self.tables_container.add(
        name=name, table=table, backend=backend, overwrite=overwrite
    )

delete_table

delete_table(name: str, missing_ok: bool = False) -> None

Delete a table from the group.

Parameters:

  • name (str) –

    The name of the table to delete.

  • missing_ok (bool, default: False ) –

    If True, do not raise an error if the table does not exist.

Source code in src/ngio/hcs/_plate.py
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
def delete_table(self, name: str, missing_ok: bool = False) -> None:
    """Delete a table from the group.

    Args:
        name (str): The name of the table to delete.
        missing_ok (bool): If True, do not raise an error if the table does not
            exist.

    """
    table_container = self._get_tables_container(create_mode=False)
    if table_container is None and missing_ok:
        return
    if table_container is None:
        raise NgioValueError(
            f"No tables found in the image, cannot delete {name}. "
            "Set missing_ok=True to ignore this error."
        )
    table_container.delete(name=name, missing_ok=missing_ok)

list_image_tables

list_image_tables(
    acquisition: int | None = None,
    filter_types: str | None = None,
    mode: Literal["common", "all"] = "common",
) -> list[str]

List all image tables in the image.

Parameters:

  • acquisition (int | None, default: None ) –

    The acquisition id to filter the images.

  • filter_types (str | None, default: None ) –

    The type of tables to filter. If None, return all tables. Defaults to None.

  • mode (Literal['common', 'all'], default: 'common' ) –

    The mode to use for listing the tables. If 'common', return only common tables between all images. If 'all', return all tables. Defaults to 'common'.

Source code in src/ngio/hcs/_plate.py
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
def list_image_tables(
    self,
    acquisition: int | None = None,
    filter_types: str | None = None,
    mode: Literal["common", "all"] = "common",
) -> list[str]:
    """List all image tables in the image.

    Args:
        acquisition (int | None): The acquisition id to filter the images.
        filter_types (str | None): The type of tables to filter. If None,
            return all tables. Defaults to None.
        mode (Literal["common", "all"]): The mode to use for listing the tables.
            If 'common', return only common tables between all images.
            If 'all', return all tables. Defaults to 'common'.
    """
    images = tuple(self.get_images(acquisition=acquisition).values())
    return list_image_tables(
        images=images,
        filter_types=filter_types,
        mode=mode,
    )

list_image_tables_async async

list_image_tables_async(
    acquisition: int | None = None,
    filter_types: str | None = None,
    mode: Literal["common", "all"] = "common",
) -> list[str]

List all image tables in the image asynchronously.

Parameters:

  • acquisition (int | None, default: None ) –

    The acquisition id to filter the images.

  • filter_types (str | None, default: None ) –

    The type of tables to filter. If None, return all tables. Defaults to None.

  • mode (Literal['common', 'all'], default: 'common' ) –

    The mode to use for listing the tables. If 'common', return only common tables between all images. If 'all', return all tables. Defaults to 'common'.

Source code in src/ngio/hcs/_plate.py
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
async def list_image_tables_async(
    self,
    acquisition: int | None = None,
    filter_types: str | None = None,
    mode: Literal["common", "all"] = "common",
) -> list[str]:
    """List all image tables in the image asynchronously.

    Args:
        acquisition (int | None): The acquisition id to filter the images.
        filter_types (str | None): The type of tables to filter. If None,
            return all tables. Defaults to None.
        mode (Literal["common", "all"]): The mode to use for listing the tables.
            If 'common', return only common tables between all images.
            If 'all', return all tables. Defaults to 'common'.
    """
    images = await self.get_images_async(acquisition=acquisition)
    images = tuple(images.values())
    return await list_image_tables_async(
        images=images,
        filter_types=filter_types,
        mode=mode,
    )

concatenate_image_tables

concatenate_image_tables(
    name: str,
    acquisition: int | None = None,
    strict: bool = True,
    index_key: str | None = None,
    mode: Literal["eager", "lazy"] = "eager",
) -> Table

Concatenate tables from all images in the plate.

Parameters:

  • name (str) –

    The name of the table to concatenate.

  • index_key (str | None, default: None ) –

    The key to use for the index of the concatenated table.

  • acquisition (int | None, default: None ) –

    The acquisition id to filter the images.

  • strict (bool, default: True ) –

    If True, raise an error if the table is not found in the image.

  • index_key (str | None, default: None ) –

    If a string is provided, a new index column will be created new_index_pattern = {row}{column}{path_in_well}_{label}

  • mode (Literal['eager', 'lazy'], default: 'eager' ) –

    The mode to use for concatenation. Can be 'eager' or 'lazy'. if 'eager', the table will be loaded into memory. if 'lazy', the table will be loaded as a lazy frame.

Source code in src/ngio/hcs/_plate.py
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
def concatenate_image_tables(
    self,
    name: str,
    acquisition: int | None = None,
    strict: bool = True,
    index_key: str | None = None,
    mode: Literal["eager", "lazy"] = "eager",
) -> Table:
    """Concatenate tables from all images in the plate.

    Args:
        name: The name of the table to concatenate.
        index_key: The key to use for the index of the concatenated table.
        acquisition: The acquisition id to filter the images.
        strict: If True, raise an error if the table is not found in the image.
        index_key: If a string is provided, a new index column will be created
            new_index_pattern = {row}_{column}_{path_in_well}_{label}
        mode: The mode to use for concatenation. Can be 'eager' or 'lazy'.
            if 'eager', the table will be loaded into memory.
            if 'lazy', the table will be loaded as a lazy frame.
    """
    images = self.get_images(acquisition=acquisition)
    extras = _build_extras(tuple(images.keys()))
    return concatenate_image_tables(
        images=tuple(images.values()),
        extras=extras,
        name=name,
        index_key=index_key,
        strict=strict,
        mode=mode,
    )

concatenate_image_tables_as

concatenate_image_tables_as(
    name: str,
    table_cls: type[TableType],
    acquisition: int | None = None,
    index_key: str | None = None,
    strict: bool = True,
    mode: Literal["eager", "lazy"] = "eager",
) -> TableType

Concatenate tables from all images in the plate as a specific type.

Parameters:

  • name (str) –

    The name of the table to concatenate.

  • table_cls (type[TableType]) –

    The type of the table to concatenate.

  • index_key (str | None, default: None ) –

    The key to use for the index of the concatenated table.

  • acquisition (int | None, default: None ) –

    The acquisition id to filter the images.

  • index_key (str | None, default: None ) –

    If a string is provided, a new index column will be created new_index_pattern = {row}{column}{path_in_well}_{label}

  • strict (bool, default: True ) –

    If True, raise an error if the table is not found in the image.

  • mode (Literal['eager', 'lazy'], default: 'eager' ) –

    The mode to use for concatenation. Can be 'eager' or 'lazy'. if 'eager', the table will be loaded into memory. if 'lazy', the table will be loaded as a lazy frame.

Source code in src/ngio/hcs/_plate.py
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
def concatenate_image_tables_as(
    self,
    name: str,
    table_cls: type[TableType],
    acquisition: int | None = None,
    index_key: str | None = None,
    strict: bool = True,
    mode: Literal["eager", "lazy"] = "eager",
) -> TableType:
    """Concatenate tables from all images in the plate as a specific type.

    Args:
        name: The name of the table to concatenate.
        table_cls: The type of the table to concatenate.
        index_key: The key to use for the index of the concatenated table.
        acquisition: The acquisition id to filter the images.
        index_key: If a string is provided, a new index column will be created
            new_index_pattern = {row}_{column}_{path_in_well}_{label}
        strict: If True, raise an error if the table is not found in the image.
        mode: The mode to use for concatenation. Can be 'eager' or 'lazy'.
            if 'eager', the table will be loaded into memory.
            if 'lazy', the table will be loaded as a lazy frame.
    """
    images = self.get_images(acquisition=acquisition)
    extras = _build_extras(tuple(images.keys()))
    return concatenate_image_tables_as(
        images=tuple(images.values()),
        extras=extras,
        name=name,
        table_cls=table_cls,
        index_key=index_key,
        strict=strict,
        mode=mode,
    )

concatenate_image_tables_async async

concatenate_image_tables_async(
    name: str,
    acquisition: int | None = None,
    index_key: str | None = None,
    strict: bool = True,
    mode: Literal["eager", "lazy"] = "eager",
) -> Table

Concatenate tables from all images in the plate asynchronously.

Parameters:

  • name (str) –

    The name of the table to concatenate.

  • index_key (str | None, default: None ) –

    The key to use for the index of the concatenated table.

  • acquisition (int | None, default: None ) –

    The acquisition id to filter the images.

  • index_key (str | None, default: None ) –

    If a string is provided, a new index column will be created new_index_pattern = {row}{column}{path_in_well}_{label}

  • strict (bool, default: True ) –

    If True, raise an error if the table is not found in the image.

  • mode (Literal['eager', 'lazy'], default: 'eager' ) –

    The mode to use for concatenation. Can be 'eager' or 'lazy'. if 'eager', the table will be loaded into memory. if 'lazy', the table will be loaded as a lazy frame.

Source code in src/ngio/hcs/_plate.py
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
async def concatenate_image_tables_async(
    self,
    name: str,
    acquisition: int | None = None,
    index_key: str | None = None,
    strict: bool = True,
    mode: Literal["eager", "lazy"] = "eager",
) -> Table:
    """Concatenate tables from all images in the plate asynchronously.

    Args:
        name: The name of the table to concatenate.
        index_key: The key to use for the index of the concatenated table.
        acquisition: The acquisition id to filter the images.
        index_key: If a string is provided, a new index column will be created
            new_index_pattern = {row}_{column}_{path_in_well}_{label}
        strict: If True, raise an error if the table is not found in the image.
        mode: The mode to use for concatenation. Can be 'eager' or 'lazy'.
            if 'eager', the table will be loaded into memory.
            if 'lazy', the table will be loaded as a lazy frame.
    """
    images = await self.get_images_async(acquisition=acquisition)
    extras = _build_extras(tuple(images.keys()))
    return await concatenate_image_tables_async(
        images=tuple(images.values()),
        extras=extras,
        name=name,
        index_key=index_key,
        strict=strict,
        mode=mode,
    )

concatenate_image_tables_as_async async

concatenate_image_tables_as_async(
    name: str,
    table_cls: type[TableType],
    acquisition: int | None = None,
    index_key: str | None = None,
    strict: bool = True,
    mode: Literal["eager", "lazy"] = "eager",
) -> TableType

Concatenate tables from all images in the plate as a specific type.

Parameters:

  • name (str) –

    The name of the table to concatenate.

  • table_cls (type[TableType]) –

    The type of the table to concatenate.

  • index_key (str | None, default: None ) –

    The key to use for the index of the concatenated table.

  • acquisition (int | None, default: None ) –

    The acquisition id to filter the images.

  • index_key (str | None, default: None ) –

    If a string is provided, a new index column will be created new_index_pattern = {row}{column}{path_in_well}_{label}

  • strict (bool, default: True ) –

    If True, raise an error if the table is not found in the image.

  • mode (Literal['eager', 'lazy'], default: 'eager' ) –

    The mode to use for concatenation. Can be 'eager' or 'lazy'. if 'eager', the table will be loaded into memory. if 'lazy', the table will be loaded as a lazy frame.

Source code in src/ngio/hcs/_plate.py
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
async def concatenate_image_tables_as_async(
    self,
    name: str,
    table_cls: type[TableType],
    acquisition: int | None = None,
    index_key: str | None = None,
    strict: bool = True,
    mode: Literal["eager", "lazy"] = "eager",
) -> TableType:
    """Concatenate tables from all images in the plate as a specific type.

    Args:
        name: The name of the table to concatenate.
        table_cls: The type of the table to concatenate.
        index_key: The key to use for the index of the concatenated table.
        acquisition: The acquisition id to filter the images.
        index_key: If a string is provided, a new index column will be created
            new_index_pattern = {row}_{column}_{path_in_well}_{label}
        strict: If True, raise an error if the table is not found in the image.
        mode: The mode to use for concatenation. Can be 'eager' or 'lazy'.
            if 'eager', the table will be loaded into memory.
            if 'lazy', the table will be loaded as a lazy frame.
    """
    images = await self.get_images_async(acquisition=acquisition)
    extras = _build_extras(tuple(images.keys()))
    return await concatenate_image_tables_as_async(
        images=tuple(images.values()),
        extras=extras,
        name=name,
        table_cls=table_cls,
        index_key=index_key,
        strict=strict,
        mode=mode,
    )

Open a Well

ngio.open_ome_zarr_well

open_ome_zarr_well(
    store: StoreOrGroup,
    cache: bool = False,
    mode: AccessModeLiteral = "r+",
) -> OmeZarrWell

Open an OME-Zarr well.

Parameters:

  • store (StoreOrGroup) –

    The Zarr store or group that stores the plate.

  • cache (bool, default: False ) –

    Whether to use a cache for the zarr group metadata.

  • mode (AccessModeLiteral, default: 'r+' ) –

    The access mode for the image. Defaults to "r+".

Source code in src/ngio/hcs/_plate.py
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
def open_ome_zarr_well(
    store: StoreOrGroup,
    cache: bool = False,
    mode: AccessModeLiteral = "r+",
) -> OmeZarrWell:
    """Open an OME-Zarr well.

    Args:
        store (StoreOrGroup): The Zarr store or group that stores the plate.
        cache (bool): Whether to use a cache for the zarr group metadata.
        mode (AccessModeLiteral): The access mode for the image. Defaults to "r+".
    """
    group_handler = ZarrGroupHandler(
        store=store,
        cache=cache,
        mode=mode,
    )
    return OmeZarrWell(group_handler)

ngio.OmeZarrWell Class Reference

ngio.OmeZarrWell

OmeZarrWell(group_handler: ZarrGroupHandler)

A class to handle the Well Sequence in an OME-Zarr file.

Initialize the LabelGroupHandler.

Parameters:

  • group_handler (ZarrGroupHandler) –

    The Zarr group handler that contains the Well.

Source code in src/ngio/hcs/_plate.py
83
84
85
86
87
88
89
90
def __init__(self, group_handler: ZarrGroupHandler) -> None:
    """Initialize the LabelGroupHandler.

    Args:
        group_handler: The Zarr group handler that contains the Well.
    """
    self._group_handler = group_handler
    self._meta_handler = WellMetaHandler(group_handler)

meta_handler property

meta_handler

Return the metadata handler.

meta property

meta

Return the metadata.

acquisition_ids property

acquisition_ids: list[int]

Return the acquisitions ids in the well.

paths

paths(acquisition: int | None = None) -> list[str]

Return the images paths in the well.

If acquisition is None, return all images paths in the well. Else, return the images paths in the well for the given acquisition.

Parameters:

  • acquisition (int | None, default: None ) –

    The acquisition id to filter the images.

Source code in src/ngio/hcs/_plate.py
111
112
113
114
115
116
117
118
119
120
def paths(self, acquisition: int | None = None) -> list[str]:
    """Return the images paths in the well.

    If acquisition is None, return all images paths in the well.
    Else, return the images paths in the well for the given acquisition.

    Args:
        acquisition (int | None): The acquisition id to filter the images.
    """
    return self.meta.paths(acquisition)

get_image_store

get_image_store(image_path: str) -> StoreOrGroup

Get the image store from the well.

Parameters:

  • image_path (str) –

    The path of the image.

Source code in src/ngio/hcs/_plate.py
122
123
124
125
126
127
128
def get_image_store(self, image_path: str) -> StoreOrGroup:
    """Get the image store from the well.

    Args:
        image_path (str): The path of the image.
    """
    return self._group_handler.get_group(image_path, create_mode=True)

get_image_acquisition_id

get_image_acquisition_id(image_path: str) -> int | None

Get the acquisition id of an image in the well.

Parameters:

  • image_path (str) –

    The path of the image.

Returns:

  • int | None

    int | None: The acquisition id of the image.

Source code in src/ngio/hcs/_plate.py
130
131
132
133
134
135
136
137
138
139
def get_image_acquisition_id(self, image_path: str) -> int | None:
    """Get the acquisition id of an image in the well.

    Args:
        image_path (str): The path of the image.

    Returns:
        int | None: The acquisition id of the image.
    """
    return self.meta.get_image_acquisition_id(image_path=image_path)

get_image

get_image(image_path: str) -> OmeZarrContainer

Get an image from the well.

Parameters:

  • image_path (str) –

    The path of the image.

Returns:

Source code in src/ngio/hcs/_plate.py
141
142
143
144
145
146
147
148
149
150
151
def get_image(self, image_path: str) -> OmeZarrContainer:
    """Get an image from the well.

    Args:
        image_path (str): The path of the image.

    Returns:
        OmeZarrContainer: The image.
    """
    handler = self._group_handler.get_handler(image_path)
    return OmeZarrContainer(handler)

atomic_add_image

atomic_add_image(
    image_path: str,
    acquisition_id: int | None = None,
    strict: bool = True,
) -> StoreOrGroup

Parallel safe version of add_image.

Source code in src/ngio/hcs/_plate.py
177
178
179
180
181
182
183
184
185
186
187
188
189
def atomic_add_image(
    self,
    image_path: str,
    acquisition_id: int | None = None,
    strict: bool = True,
) -> StoreOrGroup:
    """Parallel safe version of add_image."""
    return self._add_image(
        image_path=image_path,
        acquisition_id=acquisition_id,
        atomic=True,
        strict=strict,
    )

add_image

add_image(
    image_path: str,
    acquisition_id: int | None = None,
    strict: bool = True,
) -> StoreOrGroup

Add an image to an ome-zarr well.

Parameters:

  • image_path (str) –

    The path of the image.

  • acquisition_id (int | None, default: None ) –

    The acquisition id to filter the images.

  • strict (bool, default: True ) –

    Whether to check if the acquisition id is already exists in the well. Defaults to True. If False this might lead to acquisition in a well that does not exist at the plate level.

Source code in src/ngio/hcs/_plate.py
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
def add_image(
    self,
    image_path: str,
    acquisition_id: int | None = None,
    strict: bool = True,
) -> StoreOrGroup:
    """Add an image to an ome-zarr well.

    Args:
        image_path (str): The path of the image.
        acquisition_id (int | None): The acquisition id to filter the images.
        strict (bool): Whether to check if the acquisition id is already exists
            in the well. Defaults to True. If False this might lead to
            acquisition in a well that does not exist at the plate level.
    """
    return self._add_image(
        image_path=image_path,
        acquisition_id=acquisition_id,
        atomic=False,
        strict=strict,
    )