.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/run_coordinate_transform.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_coordinate_transform.py: Coordinate Transform ==================== This script writes two positions using the high content screening (HCS) OME-Zarr dataset with two FOV in a single well with different coordinate transformations (i.e translation and scaling) .. GENERATED FROM PYTHON SOURCE LINES 11-18 .. code-block:: Python import os from tempfile import TemporaryDirectory import numpy as np from iohub.ngff import TransformationMeta, open_ome_zarr .. GENERATED FROM PYTHON SOURCE LINES 19-20 Set storage path .. GENERATED FROM PYTHON SOURCE LINES 20-25 .. code-block:: Python tmp_dir = TemporaryDirectory() store_path = os.path.join(tmp_dir.name, "transformed.zarr") print("Zarr store path", store_path) .. rst-class:: sphx-glr-script-out .. code-block:: none Zarr store path /tmp/tmpkcacpph0/transformed.zarr .. GENERATED FROM PYTHON SOURCE LINES 26-27 Create two random sample images .. GENERATED FROM PYTHON SOURCE LINES 27-34 .. code-block:: Python tczyx_1 = np.random.randint( 0, np.iinfo(np.uint16).max, size=(1, 3, 3, 32, 32), dtype=np.uint16 ) tczyx_2 = np.random.randint( 0, np.iinfo(np.uint16).max, size=(1, 3, 3, 32, 32), dtype=np.uint16 ) .. GENERATED FROM PYTHON SOURCE LINES 35-37 Coordinate Transformations (T,C,Z,Y,X) By default the translation is the identity matrix .. GENERATED FROM PYTHON SOURCE LINES 37-40 .. code-block:: Python coords_shift = [[1.0, 1.0, 1.0, 10.0, 10.0], [1.0, 1.0, 0.0, -10.0, -10.0]] img_scaling = [[1.0, 1.0, 1.0, 0.5, 0.5]] .. GENERATED FROM PYTHON SOURCE LINES 41-42 Generate Transformation Metadata .. GENERATED FROM PYTHON SOURCE LINES 42-51 .. code-block:: Python translation = [] for shift in coords_shift: translation.append( TransformationMeta(type="translation", translation=shift) ) scaling = [] for scale in img_scaling: scaling.append(TransformationMeta(type="scale", scale=scale)) .. GENERATED FROM PYTHON SOURCE LINES 52-53 Write 5D data to a new Zarr store .. GENERATED FROM PYTHON SOURCE LINES 53-68 .. code-block:: Python 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 position = dataset.create_position(0, 0, 0) position.create_image("0", tczyx_1, transform=[translation[0]]) position = dataset.create_position(0, 0, 1) position.create_image("0", tczyx_2, transform=[translation[1], scaling[0]]) # Print dataset summary dataset.print_tree() .. rst-class:: sphx-glr-script-out .. code-block:: none / └── 0 └── 0 ├── 0 │ └── 0 (1, 3, 3, 32, 32) uint16 └── 1 └── 0 (1, 3, 3, 32, 32) uint16 .. GENERATED FROM PYTHON SOURCE LINES 69-72 .. note:: To see the coordinate transforms, open the positions individually using napari-ome-zarr. This will duplicate the layers (channels). .. GENERATED FROM PYTHON SOURCE LINES 74-75 Clean up .. GENERATED FROM PYTHON SOURCE LINES 75-75 .. code-block:: Python tmp_dir.cleanup() .. _sphx_glr_download_auto_examples_run_coordinate_transform.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: run_coordinate_transform.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: run_coordinate_transform.py `