From 3f02f9974fba7ea73fd7cc44e10ac1a77e8bd39f Mon Sep 17 00:00:00 2001 From: Mark Keller <7525285+keller-mark@users.noreply.github.com> Date: Wed, 28 Jan 2026 12:18:01 -0500 Subject: [PATCH] 3D example --- docs/notebooks/spatialdata_image_3d.ipynb | 211 ++++++++++++++++++++++ 1 file changed, 211 insertions(+) create mode 100644 docs/notebooks/spatialdata_image_3d.ipynb diff --git a/docs/notebooks/spatialdata_image_3d.ipynb b/docs/notebooks/spatialdata_image_3d.ipynb new file mode 100644 index 0000000..01a365b --- /dev/null +++ b/docs/notebooks/spatialdata_image_3d.ipynb @@ -0,0 +1,211 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 12, + "id": "1ca97045-ab06-4700-9870-5eef11f1e4e1", + "metadata": {}, + "outputs": [], + "source": [ + "import easy_vitessce as ev" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "39f4b2fd-d3fd-4d27-83e2-9b804bd40863", + "metadata": {}, + "outputs": [], + "source": [ + "import zarr\n", + "\n", + "zarr_group = zarr.open(\n", + " \"s3://idr/zarr/v0.4/idr0062A/6001240.zarr\",\n", + " storage_options={\n", + " \"anon\": True,\n", + " \"client_kwargs\": {\n", + " \"endpoint_url\": \"https://uk1s3.embassy.ebi.ac.uk\"\n", + " }\n", + " }\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "060f1e78-903f-4943-8d16-56b1e74169b1", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['0', '1', '2', 'labels']" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list(zarr_group.keys())" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "eb38c0d8-f0a1-4a03-8055-378a1895cefb", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'_creator': {'name': 'omero-zarr', 'version': '0.4.0'},\n", + " 'multiscales': [{'axes': [{'name': 'c', 'type': 'channel'},\n", + " {'name': 'z', 'type': 'space', 'unit': 'micrometer'},\n", + " {'name': 'y', 'type': 'space', 'unit': 'micrometer'},\n", + " {'name': 'x', 'type': 'space', 'unit': 'micrometer'}],\n", + " 'datasets': [{'coordinateTransformations': [{'scale': [1.0,\n", + " 0.5002025531914894,\n", + " 0.3603981534640209,\n", + " 0.3603981534640209],\n", + " 'type': 'scale'}],\n", + " 'path': '0'},\n", + " {'coordinateTransformations': [{'scale': [1.0,\n", + " 0.5002025531914894,\n", + " 0.7207963069280418,\n", + " 0.7207963069280418],\n", + " 'type': 'scale'}],\n", + " 'path': '1'},\n", + " {'coordinateTransformations': [{'scale': [1.0,\n", + " 0.5002025531914894,\n", + " 1.4415926138560835,\n", + " 1.4415926138560835],\n", + " 'type': 'scale'}],\n", + " 'path': '2'}],\n", + " 'version': '0.4'}],\n", + " 'omero': {'channels': [{'active': True,\n", + " 'coefficient': 1.0,\n", + " 'color': '0000FF',\n", + " 'family': 'linear',\n", + " 'inverted': False,\n", + " 'label': 'LaminB1',\n", + " 'window': {'end': 1500.0, 'max': 65535.0, 'min': 0.0, 'start': 0.0}},\n", + " {'active': True,\n", + " 'coefficient': 1.0,\n", + " 'color': 'FFFF00',\n", + " 'family': 'linear',\n", + " 'inverted': False,\n", + " 'label': 'Dapi',\n", + " 'window': {'end': 1500.0, 'max': 65535.0, 'min': 0.0, 'start': 0.0}}],\n", + " 'id': 1,\n", + " 'rdefs': {'defaultT': 0, 'defaultZ': 118, 'model': 'color'},\n", + " 'version': '0.4'}}" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dict(zarr_group.attrs)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "12f5ba16-4adc-423b-be4e-629d41c256cd", + "metadata": {}, + "outputs": [], + "source": [ + "img_arr = zarr_group['/1']" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "a51fcb74-94b0-4a43-84af-89ee6fddae15", + "metadata": {}, + "outputs": [], + "source": [ + "from spatialdata import SpatialData\n", + "from spatialdata.models import Image3DModel\n", + "\n", + "image = Image3DModel.parse(img_arr[()], dims=(\"c\",\"z\",\"y\",\"x\"), c_coords=[\"LaminB1\", \"Dapi\"])" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "d2b2fc74-87ba-4c84-a577-b913726cb5a7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "SpatialData object\n", + "└── Images\n", + " └── 'image': DataArray[czyx] (2, 236, 137, 135)\n", + "with coordinate systems:\n", + " ▸ 'global', with elements:\n", + " image (Images)" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sdata = SpatialData(images={\"image\": image})\n", + "sdata" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "abca9477-feb7-4317-b77d-af021d5d30f0", + "metadata": {}, + "outputs": [], + "source": [ + "vw = (\n", + " sdata\n", + " .pl.render_images(\"image\")\n", + " .pl.show()\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6e09f547-e1d3-4191-a5ae-6cce66e40faa", + "metadata": {}, + "outputs": [], + "source": [ + "vw.config.web_app()" + ] + } + ], + "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.12.5" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}