.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/run_multi_fov_hcs_ome_zarr.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_run_multi_fov_hcs_ome_zarr.py: Multi-FOV HCS OME-Zarr ====================== This script writes a high content screening (HCS) OME-Zarr dataset with a single FOV and a single scaling level per well, and adds an extra well-position to an existing dataset. .. GENERATED FROM PYTHON SOURCE LINES 11-19 .. code-block:: Python import os from tempfile import TemporaryDirectory import numpy as np from iohub.ngff import open_ome_zarr .. GENERATED FROM PYTHON SOURCE LINES 20-21 Set storage path .. GENERATED FROM PYTHON SOURCE LINES 21-26 .. code-block:: Python tmp_dir = TemporaryDirectory() store_path = os.path.join(tmp_dir.name, "hcs.zarr") print("Zarr store path", store_path) .. rst-class:: sphx-glr-script-out .. code-block:: none Zarr store path /tmp/tmp5iaut2q0/hcs.zarr .. GENERATED FROM PYTHON SOURCE LINES 27-32 Write 5D data to multiple wells. Integer path names will be automatically converted to strings. While the NGFF specification (and iohub) allows for arbitrary names, the ome-zarr-py library and the napari-ome-zarr viewer can only load positions and arrays with name '0' for the whole plate. .. GENERATED FROM PYTHON SOURCE LINES 32-56 .. code-block:: Python position_list = ( ("A", "1", "0"), ("H", 1, "0"), ("H", "12", "CannotVisualize"), ("Control", "Blank", 0), ) with open_ome_zarr( store_path, layout="hcs", mode="w-", channel_names=["DAPI", "GFP", "Brightfield"], ) as dataset: # Create and write to positions # This affects the tile arrangement in visualization for row, col, fov in position_list: position = dataset.create_position(row, col, fov) position["0"] = np.random.randint( 0, np.iinfo(np.uint16).max, size=(5, 3, 2, 32, 32), dtype=np.uint16 ) # Print dataset summary dataset.print_tree() .. rst-class:: sphx-glr-script-out .. code-block:: none / ├── A │ └── 1 │ └── 0 │ └── 0 (5, 3, 2, 32, 32) uint16 ├── Control │ └── Blank │ └── 0 │ └── 0 (5, 3, 2, 32, 32) uint16 └── H ├── 1 │ └── 0 │ └── 0 (5, 3, 2, 32, 32) uint16 └── 12 └── CannotVisualize └── 0 (5, 3, 2, 32, 32) uint16 .. GENERATED FROM PYTHON SOURCE LINES 57-58 Append a channel to all the positions .. GENERATED FROM PYTHON SOURCE LINES 58-68 .. code-block:: Python with open_ome_zarr(store_path, mode="r+") as dataset: for name, position in dataset.positions(): print(f"Appending a channel to position: {name}") position.append_channel("Segmentation", resize_arrays=True) position["0"][:, 3] = np.random.randint( 0, np.iinfo(np.uint16).max, size=(5, 2, 32, 32), dtype=np.uint16 ) dataset.print_tree() .. rst-class:: sphx-glr-script-out .. code-block:: none Appending a channel to position: A/1/0 Appending a channel to position: Control/Blank/0 Appending a channel to position: H/1/0 Appending a channel to position: H/12/CannotVisualize / ├── A │ └── 1 │ └── 0 │ └── 0 (5, 4, 2, 32, 32) uint16 ├── Control │ └── Blank │ └── 0 │ └── 0 (5, 4, 2, 32, 32) uint16 └── H ├── 1 │ └── 0 │ └── 0 (5, 4, 2, 32, 32) uint16 └── 12 └── CannotVisualize └── 0 (5, 4, 2, 32, 32) uint16 .. GENERATED FROM PYTHON SOURCE LINES 69-70 Try viewing the images with napari-ome-zarr .. GENERATED FROM PYTHON SOURCE LINES 72-73 Clean up .. GENERATED FROM PYTHON SOURCE LINES 73-74 .. code-block:: Python tmp_dir.cleanup() .. _sphx_glr_download_auto_examples_run_multi_fov_hcs_ome_zarr.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: run_multi_fov_hcs_ome_zarr.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: run_multi_fov_hcs_ome_zarr.py `