Skip to content

Instantly share code, notes, and snippets.

@dstansby
Created September 4, 2024 14:05
Show Gist options
  • Select an option

  • Save dstansby/00ae92f7d801a99147c8f57422ebd9cf to your computer and use it in GitHub Desktop.

Select an option

Save dstansby/00ae92f7d801a99147c8f57422ebd9cf to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"id": "eca0ba22-85fe-4668-acbb-065c0a618a86",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import zarr"
]
},
{
"cell_type": "code",
"execution_count": 51,
"id": "b5ba2eef-9199-4473-995a-88b2c60f4cfe",
"metadata": {},
"outputs": [],
"source": [
"# Make some data\n",
"chunk_size = 64\n",
"data_shape = [chunk_size * 2, chunk_size * 2, chunk_size * 2]\n",
"data = np.arange(np.prod(data_shape)).reshape(data_shape).astype(np.uint64)\n",
"# Coordinate transform translation (we will use this later)\n",
"translation = [512, 4050, 324]"
]
},
{
"cell_type": "code",
"execution_count": 52,
"id": "530b4be7-9418-478e-8d0b-0ea3ced4afba",
"metadata": {},
"outputs": [],
"source": [
"ome_zarr_root = zarr.open_group(\"test.ome.zarr\", mode='w')\n",
"array_path = \"0\"\n",
"zarr_array = ome_zarr_root.create_dataset(array_path, shape=data_shape, dtype=np.uint64, dimension_separator='/')"
]
},
{
"cell_type": "code",
"execution_count": 53,
"id": "5a9f5f8c-9842-411e-b30b-a0ebbb0ea8da",
"metadata": {},
"outputs": [],
"source": [
"zarr_array[:] = data"
]
},
{
"cell_type": "code",
"execution_count": 54,
"id": "ab42909f-e29a-465a-bd84-46ab68469c86",
"metadata": {},
"outputs": [],
"source": [
"ome_zarr_root.attrs['multiscales'] = [{\n",
" 'version': '0.4',\n",
" 'axes': [\n",
" {\"name\": \"x\", \"type\": \"space\", \"unit\": \"micrometer\"},\n",
" {\"name\": \"y\", \"type\": \"space\", \"unit\": \"micrometer\"},\n",
" {\"name\": \"z\", \"type\": \"space\", \"unit\": \"micrometer\"},\n",
" ],\n",
" 'name': '',\n",
" 'datasets': [\n",
" {\n",
" 'path': array_path,\n",
" 'coordinateTransformations': [{\n",
" 'type': 'translation',\n",
" 'translation': translation,\n",
" }]\n",
" },\n",
" ]\n",
"}]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8493a89e-bd87-4513-9a61-71de502363ad",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.14"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment