From 8d731b842122342795d2c5b2552cfdd48ca05e31 Mon Sep 17 00:00:00 2001 From: William Moore Date: Tue, 5 Sep 2023 10:07:48 +0100 Subject: [PATCH] Dump sample scripts - maybe add to docs --- docs/source/python.rst | 160 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) diff --git a/docs/source/python.rst b/docs/source/python.rst index f6bbdc26..668ae65e 100644 --- a/docs/source/python.rst +++ b/docs/source/python.rst @@ -109,3 +109,163 @@ the data is available as `dask` arrays:: viewer = napari.view_image(dask_data, channel_axis=0) if __name__ == '__main__': napari.run() + + +More writing examples +--------------------- + +Writing big image from tiles: + + # Created for https://forum.image.sc/t/writing-tile-wise-ome-zarr-with-pyramid-size/85063 + + import zarr + from ome_zarr.io import parse_url + from ome_zarr.reader import Reader + from ome_zarr.writer import write_multiscales_metadata + from omero_zarr.raw_pixels import downsample_pyramid_on_disk + import numpy as np + from math import ceil + + url = "https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.3/9836842.zarr" + reader = Reader(parse_url(url)) + nodes = list(reader()) + # first level of the pyramid + dask_data = nodes[0].data[0] + tile_size = 512 + + def get_tile(ch, row, col): + # read the tile data from somewhere - we use the dask array + y1 = row * tile_size + y2 = y1 + tile_size + x1 = col * tile_size + x2 = x1 + tile_size + return dask_data[ch, y1:y2, x1:x2] + + # (4,1920,1920) + shape = dask_data.shape + chunks = (1, tile_size, tile_size) + d_type = np.dtype('