.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/run_tiled_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_tiled_ome_zarr.py: Tiled OME-Zarr ============== This script shows how to create a tiled single-resolution OME-Zarr dataset, make a tiles grid, and write data. .. GENERATED FROM PYTHON SOURCE LINES 10-17 .. 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 18-19 Set storage path .. GENERATED FROM PYTHON SOURCE LINES 19-23 .. code-block:: Python tmp_dir = TemporaryDirectory() store_path = os.path.join(tmp_dir.name, "tiled.zarr") print("Zarr store path", store_path) .. rst-class:: sphx-glr-script-out .. code-block:: none Zarr store path /tmp/tmpqih40eag/tiled.zarr .. GENERATED FROM PYTHON SOURCE LINES 24-25 Write 5D data to a new Zarr store .. GENERATED FROM PYTHON SOURCE LINES 25-46 .. code-block:: Python # define grid (rows, columns) grid_shape = (2, 3) # define tile shape (5D array) tile_shape = (5, 2, 3, 32, 32) with open_ome_zarr( store_path, layout="tiled", mode="a", channel_names=["DAPI", "GFP"] ) as dataset: dtype = np.uint16 tiles = dataset.make_tiles( "tiled_raw", grid_shape=grid_shape, tile_shape=tile_shape, dtype=dtype ) for row in range(grid_shape[0]): for column in range(grid_shape[1]): # each tile will be filled with different constant values data = np.zeros(shape=tile_shape, dtype=dtype) + row + column tiles.write_tile(data, row, column) .. GENERATED FROM PYTHON SOURCE LINES 47-48 Load the dataset .. GENERATED FROM PYTHON SOURCE LINES 48-59 .. code-block:: Python with open_ome_zarr(store_path, layout="tiled", mode="r") as dataset: # data store structure dataset.print_tree() # get tiled image array tiled = dataset["tiled_raw"] # check grid and tile shapes print(tiled.tiles, tiled.tile_shape) # read a tile tile_1_2 = tiled.get_tile(1, 2) .. rst-class:: sphx-glr-script-out .. code-block:: none / └── tiled_raw (5, 2, 3, 64, 96) uint16 (2, 3) (1, 1, 1, 32, 32) .. GENERATED FROM PYTHON SOURCE LINES 60-61 Try viewing the images with napari-ome-zarr .. GENERATED FROM PYTHON SOURCE LINES 63-64 Clean up .. GENERATED FROM PYTHON SOURCE LINES 64-65 .. code-block:: Python tmp_dir.cleanup() .. _sphx_glr_download_auto_examples_run_tiled_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_tiled_ome_zarr.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: run_tiled_ome_zarr.py `