Skip to content

HCS exploration

Explore a plate and aggregate tables across it.

Open an OME-Zarr plate with ngio, see what it contains, aggregate a table across every image in it, and write the result back to the plate. The last section creates a new empty plate from scratch.

Step 1: show what's in the plate

from pathlib import Path

from ngio import open_ome_zarr_plate
from ngio.utils import download_ome_zarr_dataset

# Download the dataset
download_dir = Path("./data").absolute()

hcs_path = download_ome_zarr_dataset("CardiomyocyteTinyMip", download_dir=download_dir)
hcs_zarr = open_ome_zarr_plate(hcs_path)
print(hcs_zarr)
print(f"Rows: {hcs_zarr.rows}, Columns: {hcs_zarr.columns}")

# Get all the images in the plate
print(hcs_zarr.get_images())
Plate([rows x columns] (1 x 1)) Rows: ['B'], Columns: ['03'] {'B/03/0': OmeZarrContainer(levels=5, labels=['nuclei'], #tables=4)}

Step 2: aggregate tables across all images

# Aggregate all table across all images
table = hcs_zarr.concatenate_image_tables(name="nuclei")
print(table_html(table.dataframe.head()))
label area bbox_area equivalent_diameter max_intensity mean_intensity min_intensity standard_deviation_intensity row column path_in_well
1 1360.00 1664.00 13.75 268.00 184.58 125.00 24.50 B 03 0
2 2464.00 2992.00 16.76 461.00 273.25 132.00 51.79 B 03 0
3 1968.00 2688.00 15.55 429.00 277.29 143.00 41.82 B 03 0
4 5120.00 6400.00 21.38 413.00 279.04 118.00 44.38 B 03 0
5 288.00 352.00 8.19 341.00 243.32 147.00 41.86 B 03 0

Step 3: save the table in the plate

# Save the table in the HCS plate
hcs_zarr.add_table(name="nuclei", table=table, overwrite=True)

# Read the table back for sanity check
print(table_html(hcs_zarr.get_table("nuclei").dataframe.head()))
label area bbox_area equivalent_diameter max_intensity mean_intensity min_intensity standard_deviation_intensity row column path_in_well
1 1360.00 1664.00 13.75 268.00 184.58 125.00 24.50 B 03 0
2 2464.00 2992.00 16.76 461.00 273.25 132.00 51.79 B 03 0
3 1968.00 2688.00 15.55 429.00 277.29 143.00 41.82 B 03 0
4 5120.00 6400.00 21.38 413.00 279.04 118.00 44.38 B 03 0
5 288.00 352.00 8.19 341.00 243.32 147.00 41.86 B 03 0

Step 4: create a new empty plate

from ngio import ImageInWellPath, create_empty_plate

test_plate = create_empty_plate(
    store="./data/empty_plate.zarr",
    name="Test Plate",
    images=[
        ImageInWellPath(row="A", column="01", path="0"),
        ImageInWellPath(row="A", column="02", path="0"),
        ImageInWellPath(row="A", column="02", path="1", acquisition_id=1),
    ],
    overwrite=True,
)

print(test_plate)
print(f"Rows: {test_plate.rows}, Columns: {test_plate.columns}")
Plate([rows x columns] (1 x 2)) Rows: ['A'], Columns: ['01', '02']

Next steps