Skip to content

Commit

Permalink
Merge pull request #317 from elyall/master
Browse files Browse the repository at this point in the history
update docs to include write example for HCS dataset
  • Loading branch information
will-moore authored Oct 17, 2023
2 parents 042038c + 3140c66 commit f18df24
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
49 changes: 49 additions & 0 deletions docs/source/python.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,55 @@ This image can be viewed in `napari` using the
$ napari test_ngff_image.zarr


Writing HCS datasets to OME-NGFF
================================

This sample code shows how to write a high-content screening dataset (i.e. culture plate with multiple wells) to a OME-NGFF file::

import numpy as np
import zarr

from ome_zarr.io import parse_url
from ome_zarr.writer import write_image, write_plate_metadata, write_well_metadata

path = "test_ngff_plate.zarr"
row_names = ["A", "B"]
col_names = ["1", "2", "3"]
well_paths = ["A/2", "B/3"]
field_paths = ["0", "1", "2"]

# generate data
mean_val=10
num_wells = len(well_paths)
num_fields = len(field_paths)
size_xy = 128
size_z = 10
rng = np.random.default_rng(0)
data = rng.poisson(mean_val, size=(num_wells, num_fields, size_z, size_xy, size_xy)).astype(np.uint8)

# write the plate of images and corresponding metadata
store = parse_url(path, mode="w").store
root = zarr.group(store=store)
write_plate_metadata(root, row_names, col_names, well_paths)
for wi, wp in enumerate(well_paths):
row, col = wp.split("/")
row_group = root.require_group(row)
well_group = row_group.require_group(col)
write_well_metadata(well_group, field_paths)
for fi, field in enumerate(field_paths):
image_group = well_group.require_group(str(field))
write_image(image=data[wi, fi], group=image_group, axes="zyx", storage_options=dict(chunks=(1, size_xy, size_xy)))


This image can be viewed in `napari` using the
`napari-ome-zarr <https://github.com/ome/napari-ome-zarr>`_ plugin::

import napari

viewer = napari.Viewer()
viewer.open(path, plugin="napari-ome-zarr")


Reading OME-NGFF images
-----------------------

Expand Down
2 changes: 1 addition & 1 deletion ome_zarr/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def _get_valid_axes(
f"axes length ({len(axes)}) must match number of dimensions ({ndim})"
)

# valiates on init
# validates on init
axes_obj = Axes(axes, fmt)

return axes_obj.to_list(fmt)
Expand Down

0 comments on commit f18df24

Please sign in to comment.