diff --git a/examples/hcs_zarr.py b/examples/hcs_zarr.py index f8ebd92c..f28b1dfb 100644 --- a/examples/hcs_zarr.py +++ b/examples/hcs_zarr.py @@ -37,8 +37,11 @@ # create and write to positions for i, (row, col, fov) in enumerate(position_list): position = dataset.create_position(row, col, fov) - position["0"] = i*np.ones((2, 3, 5, 32, 32)).astype(np.uint16) + position["0"] = i * np.ones((2, 3, 5, 32, 32)).astype(np.uint16) # 2 timepoints, 3 channels, 5 z-slices, 32x32 image + + #position.img or position.data is a more intuitive way to write and read data. + # Can we implement this? # print dataset summary dataset.print_tree() # Try viewing the hcs.zarr dataset in napari. diff --git a/examples/singleFOV_zarr.py b/examples/singleFOV_zarr.py index d907b4c7..78a3dca5 100644 --- a/examples/singleFOV_zarr.py +++ b/examples/singleFOV_zarr.py @@ -23,6 +23,8 @@ store_path, layout="fov", mode="a", channel_names=["DAPI", "GFP"] ) as dataset: dataset["img"] = tczyx + #dataset.img or dataset.data is a more intuitive way to write and read data. + # Can we implement this? # %% # Opening in read-only mode prevents writing diff --git a/examples/tiles_zarr.py b/examples/tiles_zarr.py new file mode 100644 index 00000000..33db1795 --- /dev/null +++ b/examples/tiles_zarr.py @@ -0,0 +1,41 @@ +# %% +# This script writes a tiled (multi-FOV) zarr dataset. +# It is not spcified by the NGFF specification, but is a common use case. +# We repurpose the HCS layout from the NGFF specification to make multi-position data to view with napari-ome-zarr. + + +import os + +import numpy as np + +from iohub.ngff import open_ome_zarr + +# %% +# Set storage path + +store_path = f'{os.path.expanduser("~/")}tiles.zarr' + +# %% +# Write 5D data to multiple positions. +# While the NGFF specification allows for arbitrary names, +# the ome-zarr-py library (thus the napari-ome-zarr plugin) +# only load arrays with name '0'. + +position_list = ((row, col) for row in ("row_0", "row_1") for col in range(10)) + +with open_ome_zarr( + store_path, + layout="tiles", + mode="w", + channel_names=["DAPI", "GFP", "Brightfield"], +) as dataset: + # create and write to positions + for i, (row, col) in enumerate(position_list): + position = dataset.create_position(row, col) + # Following usage (set the data property) is more intuitive. Can we implement this? + # position.data = i*np.ones((2, 3, 5, 32, 32)).astype(np.uint16) + position["0"] = i*np.ones((2, 3, 5, 32, 32)).astype(np.uint16) + # 2 timepoints, 3 channels, 5 z-slices, 32x32 image at each position + # print dataset summary + dataset.print_tree() +# Try viewing the tiles.zarr dataset in napari or each position individually. \ No newline at end of file