@biongff/vizarr 1.1.1 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/LICENSE +1 -0
  2. package/dist/biongff-vizarr.cjs.js +1 -0
  3. package/dist/biongff-vizarr.es.js +9 -0
  4. package/dist/blosc-CeItQ6qj.cjs +17 -0
  5. package/dist/blosc-DaK8KnI4.js +719 -0
  6. package/dist/chunk-INHXZS53-DiyuLb3Z.js +14 -0
  7. package/dist/chunk-INHXZS53-z3BpFH8p.cjs +1 -0
  8. package/dist/deflate-DzrO3E-1.cjs +1 -0
  9. package/dist/deflate-Q4iCMMBa.js +10 -0
  10. package/dist/index-3CiumG5V.js +53876 -0
  11. package/dist/index-Ckhcz4QQ.cjs +3815 -0
  12. package/dist/index.d.ts +119 -0
  13. package/dist/jpeg-BdEIe3QG.js +533 -0
  14. package/dist/jpeg-DFzBPcur.cjs +1 -0
  15. package/dist/jpeg2k-1tnzEScI.js +24 -0
  16. package/dist/jpeg2k-CcF6vCxI.cjs +1 -0
  17. package/dist/lerc-35FtXNGP.cjs +1 -0
  18. package/dist/lerc-B6qlOBE2.js +1039 -0
  19. package/dist/lz4-CssV0LoA.js +643 -0
  20. package/dist/lz4-PFaIsPAh.cjs +15 -0
  21. package/dist/lzw-CeXp5T9s.js +84 -0
  22. package/dist/lzw-DnHvgKbO.cjs +1 -0
  23. package/dist/packbits-CAZoMCQq.js +24 -0
  24. package/dist/packbits-DwdUAwAt.cjs +1 -0
  25. package/dist/pako.esm-Bx5X36Wo.js +1074 -0
  26. package/dist/pako.esm-DZC2QrbJ.cjs +1 -0
  27. package/dist/raw-BB450wdT.cjs +1 -0
  28. package/dist/raw-oTi55tWo.js +9 -0
  29. package/dist/ref-Bd0nPTvp.js +196 -0
  30. package/dist/ref-CIxavIn6.cjs +1 -0
  31. package/dist/webimage-66a9vFf5.cjs +1 -0
  32. package/dist/webimage-CKRNzqyG.js +19 -0
  33. package/dist/zstd-Cqadn9HA.js +610 -0
  34. package/dist/zstd-_xUhkGOV.cjs +15 -0
  35. package/package.json +35 -21
  36. package/.gitattributes +0 -1
  37. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -32
  38. package/.github/ISSUE_TEMPLATE/documentation_update.md +0 -16
  39. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -19
  40. package/.github/ISSUE_TEMPLATE/maintenance.md +0 -19
  41. package/.github/ISSUE_TEMPLATE/optimisation_request.md +0 -23
  42. package/.github/ISSUE_TEMPLATE/support_request.md +0 -25
  43. package/.github/PULL_REQUEST_TEMPLATE.md +0 -21
  44. package/.github/dependabot.yml +0 -13
  45. package/.github/workflows/deploy.yml +0 -56
  46. package/.github/workflows/npm-publish-dev.yml +0 -49
  47. package/.github/workflows/npm-publish.yml +0 -42
  48. package/.github/workflows/release.yml +0 -37
  49. package/.github/workflows/test.yml +0 -21
  50. package/.releaserc.json +0 -29
  51. package/CHANGELOG.md +0 -70
  52. package/CITATION.cff +0 -56
  53. package/CONTRIBUTING.md +0 -82
  54. package/README.md +0 -85
  55. package/assets/favicon.ico +0 -0
  56. package/assets/favicon.png +0 -0
  57. package/assets/logo-wide.png +0 -0
  58. package/assets/logo-wide.svg +0 -60
  59. package/assets/logo.png +0 -0
  60. package/assets/logo.svg +0 -36
  61. package/assets/robots.txt +0 -3
  62. package/assets/screenshot.png +0 -0
  63. package/biome.json +0 -34
  64. package/index.html +0 -24
  65. package/main.ts +0 -52
  66. package/patches/@vivjs__loaders@0.17.2.patch +0 -13
  67. package/python/.python-version +0 -1
  68. package/python/README.md +0 -14
  69. package/python/Untitled.ipynb +0 -40
  70. package/python/deno.json +0 -22
  71. package/python/notebooks/IDR_example.ipynb +0 -86
  72. package/python/notebooks/README.md +0 -35
  73. package/python/notebooks/create_fixture.py +0 -72
  74. package/python/notebooks/getting_started.ipynb +0 -217
  75. package/python/notebooks/mandelbrot.ipynb +0 -211
  76. package/python/notebooks/spatial_transformations.ipynb +0 -139
  77. package/python/pyproject.toml +0 -18
  78. package/python/src/vizarr/__init__.py +0 -10
  79. package/python/src/vizarr/_widget.js +0 -113
  80. package/python/src/vizarr/_widget.py +0 -67
  81. package/python/uv.lock +0 -2495
  82. package/src/ZarrPixelSource.ts +0 -182
  83. package/src/codecs/jpeg2k.ts +0 -22
  84. package/src/codecs/register.ts +0 -2
  85. package/src/components/LayerController/AcquisitionController.tsx +0 -46
  86. package/src/components/LayerController/AddChannelButton.tsx +0 -122
  87. package/src/components/LayerController/AxisOptions.tsx +0 -93
  88. package/src/components/LayerController/AxisSlider.tsx +0 -86
  89. package/src/components/LayerController/AxisSliders.tsx +0 -29
  90. package/src/components/LayerController/ChannelController.tsx +0 -84
  91. package/src/components/LayerController/ChannelOptions.tsx +0 -183
  92. package/src/components/LayerController/ColorPalette.tsx +0 -40
  93. package/src/components/LayerController/Content.tsx +0 -71
  94. package/src/components/LayerController/Header.tsx +0 -48
  95. package/src/components/LayerController/Labels.tsx +0 -73
  96. package/src/components/LayerController/LayerFitToViewportButton.tsx +0 -43
  97. package/src/components/LayerController/LayerVisibilityButton.tsx +0 -32
  98. package/src/components/LayerController/OpacitySlider.tsx +0 -25
  99. package/src/components/LayerController/index.tsx +0 -42
  100. package/src/components/Menu.tsx +0 -54
  101. package/src/components/Viewer.tsx +0 -136
  102. package/src/hooks.ts +0 -29
  103. package/src/index.tsx +0 -138
  104. package/src/io.ts +0 -276
  105. package/src/layers/grid-layer.ts +0 -214
  106. package/src/layers/label-layer.ts +0 -446
  107. package/src/layers/viv-layers.ts +0 -55
  108. package/src/lru-store.ts +0 -57
  109. package/src/ome.ts +0 -388
  110. package/src/state.ts +0 -202
  111. package/src/theme.ts +0 -80
  112. package/src/types.ts +0 -112
  113. package/src/utils.ts +0 -663
  114. package/tsconfig.json +0 -14
  115. package/vite.config.js +0 -47
@@ -1,72 +0,0 @@
1
- #!/usr/bin/env python
2
- import argparse
3
- import zarr
4
- import numpy as np
5
- import os
6
- import json
7
- from skimage import data
8
- from skimage.transform import pyramid_gaussian
9
-
10
- # Modified from https://github.com/ome/ome-zarr-py/blob/master/tests/create_test_data.py
11
- def create_ome_zarr(zarr_directory, dtype="f4"):
12
-
13
- base = np.tile(data.astronaut(), (4, 4, 1))
14
- gaussian = list(pyramid_gaussian(base, downscale=2, max_layer=3, channel_axis=-1))
15
-
16
- pyramid = []
17
- # convert each level of pyramid into 5D image (t, c, z, y, x)
18
- for pixels in gaussian:
19
- red = pixels[:, :, 0]
20
- green = pixels[:, :, 1]
21
- blue = pixels[:, :, 2]
22
- # wrap to make 5D: (t, c, z, y, x)
23
- pixels = np.array([np.array([red]), np.array([green]), np.array([blue])])
24
- pixels = np.array([pixels]).astype(dtype)
25
- pyramid.append(pixels)
26
-
27
- store = zarr.DirectoryStore(zarr_directory)
28
- grp = zarr.group(store, overwrite=True)
29
- paths = []
30
- for path, dataset in enumerate(pyramid):
31
- grp.create_dataset(str(path), data=pyramid[path])
32
- paths.append({"path": str(path)})
33
-
34
- image_data = {
35
- "id": 1,
36
- "channels": [
37
- {
38
- "color": "FF0000",
39
- "window": {"start": 0, "end": 1},
40
- "label": "Red",
41
- "active": True,
42
- },
43
- {
44
- "color": "00FF00",
45
- "window": {"start": 0, "end": 1},
46
- "label": "Green",
47
- "active": True,
48
- },
49
- {
50
- "color": "0000FF",
51
- "window": {"start": 0, "end": 1},
52
- "label": "Blue",
53
- "active": True,
54
- },
55
- ],
56
- "rdefs": {
57
- "model": "color",
58
- },
59
- }
60
-
61
- multiscales = [
62
- {
63
- "version": "0.1",
64
- "datasets": paths,
65
- }
66
- ]
67
- grp.attrs["multiscales"] = multiscales
68
- grp.attrs["omero"] = image_data
69
-
70
-
71
- if __name__ == "__main__":
72
- create_ome_zarr("astronaut.zarr")
@@ -1,217 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "markdown",
5
- "metadata": {},
6
- "source": [
7
- "# Hello, `vizarr`\n",
8
- "\n",
9
- "This example explains the basic usage of `vizarr` [anywidget](https://github.com/manzt/anywidget)."
10
- ]
11
- },
12
- {
13
- "cell_type": "markdown",
14
- "metadata": {},
15
- "source": [
16
- "### Create a multiscale OME-Zarr\n",
17
- "\n",
18
- "The easiest way to use `vizarr` in a jupyter notebook is to have an OME-Zarr compliant image. OME-Zarr is a developing standard from the OME-Community and currently considered experimental as it is under active development. The specification can be found [here](https://ngff.openmicroscopy.org/specifications/index.html). \n",
19
- " \n",
20
- "Creating an OME-Zarr for your own images can be accomplished by using Bio-Formats, `bioformats2raw` with the `--file_type=zarr --dimension-order=XYZCT` options and adding `omero` metadata to the root attrs of the resulting multiscale group. \n",
21
- "\n",
22
- "For convenience, we have included a simple function to create a multiscale OME-Zarr below."
23
- ]
24
- },
25
- {
26
- "cell_type": "code",
27
- "execution_count": null,
28
- "metadata": {},
29
- "outputs": [],
30
- "source": [
31
- "from create_fixture import create_ome_zarr\n",
32
- "create_ome_zarr(\"astronaut.zarr\") # creates an example OME-Zarr in the current directory"
33
- ]
34
- },
35
- {
36
- "cell_type": "markdown",
37
- "metadata": {},
38
- "source": [
39
- "### Open OME-Zarr in jupyter with `zarr-python`\n",
40
- "\n",
41
- "The root of an OME-Zarr is a group that aheres to the `multiscales` zarr extension (if pyramidal) and also contains `omero` metadata describing _how_ to render the image. Here we open the OME-Zarr as a `zarr.Group` using `zarr-python`. "
42
- ]
43
- },
44
- {
45
- "cell_type": "code",
46
- "execution_count": null,
47
- "metadata": {},
48
- "outputs": [],
49
- "source": [
50
- "import zarr\n",
51
- "multiscale_astronaut = zarr.open(\"astronaut.zarr\", mode=\"r\") # open the zarr created above in jupyter kernel"
52
- ]
53
- },
54
- {
55
- "cell_type": "markdown",
56
- "metadata": {},
57
- "source": [
58
- "### View the image in `vizarr`\n",
59
- "\n",
60
- "The vizarr Python API allows basic viewing of large zarr datasets in computational notebooks. The `vizarr.Viewer` allows adding images to the view with the `.add_image` API. The `source` field must be a `zarr.Array` or `zarr.Group`. If the `zarr.Group` is for an OME-Zarr, `source` is the only required field. If it is an `zarr.Array` or `zarr.Group` that is not OME-Zarr, additional fields are required for rendering (described below)."
61
- ]
62
- },
63
- {
64
- "cell_type": "code",
65
- "execution_count": null,
66
- "metadata": {},
67
- "outputs": [],
68
- "source": [
69
- "import vizarr\n",
70
- "\n",
71
- "viewer = vizarr.Viewer()\n",
72
- "viewer.add_image(source=multiscale_astronaut, name=\"astronaut\")\n",
73
- "viewer"
74
- ]
75
- },
76
- {
77
- "cell_type": "markdown",
78
- "metadata": {},
79
- "source": [
80
- "### Create a generic array layer\n",
81
- "\n",
82
- "`vizarr` also supports custom `zarr.Array` and `zarr.Group`s, but requires additional metadata to render. Viewing a custom `zarr` has the following requirements:\n",
83
- "\n",
84
- "- The last two dimensions of the `zarr.Array` must be `YX`.\n",
85
- "- If an `zarr.Array` has more than 2D dimensions, non-YX axis much have a `chunksize` of `1`.\n",
86
- "- If a `zarr.Group` is provided, it must implement the `multiscales` specification and subresolution arrays must adhere to the same `zarr.Array` requirements outlined above."
87
- ]
88
- },
89
- {
90
- "cell_type": "code",
91
- "execution_count": null,
92
- "metadata": {},
93
- "outputs": [],
94
- "source": [
95
- "import numpy as np\n",
96
- "\n",
97
- "# Create in-memory numpy array\n",
98
- "arr = np.random.randint(0, 255, (1024, 1024), dtype=np.uint8)\n",
99
- "\n",
100
- "viewer.add_image(\n",
101
- " source=zarr.array(arr), # make sure it's a zarr\n",
102
- " opacity=0.5, # optional, default 1\n",
103
- " name=\"noise\", # optional, default image_x\n",
104
- ")\n",
105
- "\n",
106
- "# view canvas above"
107
- ]
108
- },
109
- {
110
- "cell_type": "markdown",
111
- "metadata": {},
112
- "source": [
113
- "### Use `channel_axis` to choose axis to additively blend\n",
114
- "\n",
115
- "Vizarr was designed to support viewing a subset of multiscale OME-Zarr images, but it can support blending 2D slices of generic `zarr.Array`s. For a `zarr.Array` with more than 2 dimensions, a `channel_axis` must be specified to tell vizarr which dimension to split into separate blended channels. \n",
116
- "\n",
117
- "Here we will load one of the sub-resolution `zarr.Array`s from the OME-Zarr we created and view it with Vizarr."
118
- ]
119
- },
120
- {
121
- "cell_type": "code",
122
- "execution_count": null,
123
- "metadata": {},
124
- "outputs": [],
125
- "source": [
126
- "z_arr = zarr.open('astronaut.zarr').get('2')\n",
127
- "z_arr.shape"
128
- ]
129
- },
130
- {
131
- "cell_type": "markdown",
132
- "metadata": {},
133
- "source": [
134
- "The channel axis for an OME-Zarr is always `1`, but loading the image with a different channel axis will load a single plane."
135
- ]
136
- },
137
- {
138
- "cell_type": "code",
139
- "execution_count": null,
140
- "metadata": {},
141
- "outputs": [],
142
- "source": [
143
- "viewer = vizarr.Viewer()\n",
144
- "viewer.add_image(source=z_arr, channel_axis=0)\n",
145
- "viewer"
146
- ]
147
- },
148
- {
149
- "cell_type": "markdown",
150
- "metadata": {},
151
- "source": [
152
- "You can specify other rendering properties to tell vizarr how to render the channels along the specified axis."
153
- ]
154
- },
155
- {
156
- "cell_type": "code",
157
- "execution_count": null,
158
- "metadata": {},
159
- "outputs": [],
160
- "source": [
161
- "viewer = vizarr.Viewer()\n",
162
- "viewer.add_image(\n",
163
- " source=z_arr,\n",
164
- " name=\"CYM astronaut\", # Image name\n",
165
- " channel_axis=1, # size == 3, lists below must be of same length if provided\n",
166
- " colors=[\"#FFFF00\", \"#FF00FF\", \"#00FFFF\"], # optional\n",
167
- " names=[\"yellow\", \"magenta\", \"cyan\"], # optional, default channel_X\n",
168
- " visibilities=[True, False, True], # optional, default True\n",
169
- " contrast_limits=[[0, 1] for _ in range(3)], # optional, but recommended\n",
170
- ")\n",
171
- "viewer"
172
- ]
173
- },
174
- {
175
- "cell_type": "code",
176
- "execution_count": null,
177
- "metadata": {},
178
- "outputs": [],
179
- "source": []
180
- },
181
- {
182
- "cell_type": "code",
183
- "execution_count": null,
184
- "metadata": {},
185
- "outputs": [],
186
- "source": []
187
- },
188
- {
189
- "cell_type": "code",
190
- "execution_count": null,
191
- "metadata": {},
192
- "outputs": [],
193
- "source": []
194
- }
195
- ],
196
- "metadata": {
197
- "kernelspec": {
198
- "display_name": "Python 3 (ipykernel)",
199
- "language": "python",
200
- "name": "python3"
201
- },
202
- "language_info": {
203
- "codemirror_mode": {
204
- "name": "ipython",
205
- "version": 3
206
- },
207
- "file_extension": ".py",
208
- "mimetype": "text/x-python",
209
- "name": "python",
210
- "nbconvert_exporter": "python",
211
- "pygments_lexer": "ipython3",
212
- "version": "3.12.7"
213
- }
214
- },
215
- "nbformat": 4,
216
- "nbformat_minor": 4
217
- }
@@ -1,211 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "markdown",
5
- "metadata": {},
6
- "source": [
7
- "# Setup\n",
8
- "\n",
9
- "Before start, please make sure you have all the dependencies installed."
10
- ]
11
- },
12
- {
13
- "cell_type": "code",
14
- "execution_count": null,
15
- "metadata": {},
16
- "outputs": [],
17
- "source": [
18
- "!pip install --quiet vizarr zarr numba"
19
- ]
20
- },
21
- {
22
- "cell_type": "code",
23
- "execution_count": null,
24
- "metadata": {},
25
- "outputs": [],
26
- "source": [
27
- "import zarr\n",
28
- "import numcodecs\n",
29
- "import numba\n",
30
- "import numpy as np"
31
- ]
32
- },
33
- {
34
- "cell_type": "markdown",
35
- "metadata": {},
36
- "source": [
37
- "## Zoomable Mandelbrot Set\n",
38
- "\n",
39
- "This notebook a contains `vizarr` example visualizing a generic multiscale zarr. The first cell contains code to create the underlying generatvie zarr store. It dynamically creates \"chunks\" at different zoom levels and associated array metadata."
40
- ]
41
- },
42
- {
43
- "cell_type": "code",
44
- "execution_count": null,
45
- "metadata": {},
46
- "outputs": [],
47
- "source": [
48
- "\n",
49
- "def create_meta_store(levels: int, tilesize: int, compressor, dtype: str):\n",
50
- " store = dict()\n",
51
- " zarr.storage.init_group(store)\n",
52
- " \n",
53
- " datasets = [{\"path\": str(i)} for i in range(levels)]\n",
54
- " root_attrs = {\"multiscales\": [{\"datasets\": datasets, \"version\": \"0.1\"}]}\n",
55
- " store[\".zattrs\"] = zarr.util.json_dumps(root_attrs)\n",
56
- " \n",
57
- " base_width = tilesize * 2 ** levels\n",
58
- " for level in range(levels):\n",
59
- " width = int(base_width / 2 ** level)\n",
60
- " zarr.storage.init_array(\n",
61
- " store,\n",
62
- " path=str(level),\n",
63
- " shape=(width, width),\n",
64
- " chunks=(tilesize, tilesize),\n",
65
- " dtype=dtype,\n",
66
- " compressor=compressor,\n",
67
- " )\n",
68
- " return store\n",
69
- "\n",
70
- "\n",
71
- "@numba.njit\n",
72
- "def mandelbrot(out, from_x, from_y, to_x, to_y, grid_size, maxiter):\n",
73
- " step_x = (to_x - from_x) / grid_size\n",
74
- " step_y = (to_y - from_y) / grid_size\n",
75
- " creal = from_x\n",
76
- " cimag = from_y\n",
77
- " for i in range(grid_size):\n",
78
- " cimag = from_y\n",
79
- " for j in range(grid_size):\n",
80
- " nreal = real = imag = n = 0\n",
81
- " for _ in range(maxiter):\n",
82
- " nreal = real * real - imag * imag + creal\n",
83
- " imag = 2 * real * imag + cimag\n",
84
- " real = nreal\n",
85
- " if real * real + imag * imag > 4.0:\n",
86
- " break\n",
87
- " n += 1\n",
88
- " out[j * grid_size + i] = n\n",
89
- " cimag += step_y\n",
90
- " creal += step_x\n",
91
- " return out\n",
92
- "\n",
93
- "\n",
94
- "@numba.njit\n",
95
- "def tile_bounds(level, x, y, max_level, min_coord=-2.5, max_coord=2.5):\n",
96
- " max_width = max_coord - min_coord\n",
97
- " tile_width = max_width / 2 ** (max_level - level)\n",
98
- " from_x = min_coord + x * tile_width\n",
99
- " to_x = min_coord + (x + 1) * tile_width\n",
100
- "\n",
101
- " from_y = min_coord + y * tile_width\n",
102
- " to_y = min_coord + (y + 1) * tile_width\n",
103
- "\n",
104
- " return from_x, from_y, to_x, to_y\n",
105
- "\n",
106
- "\n",
107
- "class MandlebrotStore(zarr.storage.BaseStore):\n",
108
- " \n",
109
- " def __init__(self, levels, tilesize, maxiter=255, compressor=None):\n",
110
- " self.levels = levels\n",
111
- " self.tilesize = tilesize\n",
112
- " self.compressor = compressor\n",
113
- " self.dtype = np.dtype(np.uint8 if maxiter < 256 else np.uint16)\n",
114
- " self.maxiter = maxiter\n",
115
- " self._store = create_meta_store(levels, tilesize, compressor, self.dtype)\n",
116
- "\n",
117
- " def __getitem__(self, key):\n",
118
- " if key in self._store:\n",
119
- " return self._store[key]\n",
120
- "\n",
121
- " try:\n",
122
- " # Try parsing pyramidal coords\n",
123
- " level, chunk_key = key.split(\"/\")\n",
124
- " level = int(level)\n",
125
- " y, x = map(int, chunk_key.split(\".\"))\n",
126
- " except:\n",
127
- " raise KeyError\n",
128
- "\n",
129
- " from_x, from_y, to_x, to_y = tile_bounds(level, x, y, self.levels)\n",
130
- " out = np.zeros(self.tilesize * self.tilesize, dtype=self.dtype)\n",
131
- " tile = mandelbrot(out, from_x, from_y, to_x, to_y, self.tilesize, self.maxiter)\n",
132
- " tile = tile.reshape(self.tilesize, self.tilesize)\n",
133
- "\n",
134
- " if self.compressor:\n",
135
- " return self.compressor.encode(tile)\n",
136
- "\n",
137
- " return tile.tobytes()\n",
138
- "\n",
139
- " def __iter__(self):\n",
140
- " return iter(self._store)\n",
141
- " \n",
142
- " def __len__(self):\n",
143
- " return len(self._store)\n",
144
- "\n",
145
- " def __delitem__(self, key):\n",
146
- " raise NotImplementedError(\"read-only store\")\n",
147
- " \n",
148
- " def __setitem__(self, key):\n",
149
- " raise NotImplementedError(\"read-only store\")"
150
- ]
151
- },
152
- {
153
- "cell_type": "markdown",
154
- "metadata": {},
155
- "source": [
156
- "### Running vizarr\n",
157
- "\n",
158
- "Initalize the store implemented above, and open as a `zarr.Group` for vizarr. "
159
- ]
160
- },
161
- {
162
- "cell_type": "code",
163
- "execution_count": null,
164
- "metadata": {},
165
- "outputs": [],
166
- "source": [
167
- "# Initialize the store\n",
168
- "store = MandlebrotStore(levels=50, tilesize=512, compressor=numcodecs.Blosc())\n",
169
- "# Wrap in a cache so that tiles don't need to be computed as often\n",
170
- "store = zarr.LRUStoreCache(store, max_size=1e9)\n",
171
- "\n",
172
- "# This store implements the 'multiscales' zarr specfiication which is recognized by vizarr\n",
173
- "grp = zarr.open(store, mode=\"r\")"
174
- ]
175
- },
176
- {
177
- "cell_type": "code",
178
- "execution_count": null,
179
- "metadata": {},
180
- "outputs": [],
181
- "source": [
182
- "import vizarr\n",
183
- "\n",
184
- "viewer = vizarr.Viewer()\n",
185
- "viewer.add_image(source=grp, name=\"mandelbrot\")\n",
186
- "viewer"
187
- ]
188
- }
189
- ],
190
- "metadata": {
191
- "kernelspec": {
192
- "display_name": "Python 3 (ipykernel)",
193
- "language": "python",
194
- "name": "python3"
195
- },
196
- "language_info": {
197
- "codemirror_mode": {
198
- "name": "ipython",
199
- "version": 3
200
- },
201
- "file_extension": ".py",
202
- "mimetype": "text/x-python",
203
- "name": "python",
204
- "nbconvert_exporter": "python",
205
- "pygments_lexer": "ipython3",
206
- "version": "3.12.3"
207
- }
208
- },
209
- "nbformat": 4,
210
- "nbformat_minor": 4
211
- }
@@ -1,139 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "code",
5
- "execution_count": null,
6
- "id": "e9ac663e-a7ed-41c9-9050-2c69b89e7e74",
7
- "metadata": {},
8
- "outputs": [],
9
- "source": [
10
- "!pip install --quiet zarr scikit-image"
11
- ]
12
- },
13
- {
14
- "cell_type": "markdown",
15
- "id": "2c447021",
16
- "metadata": {},
17
- "source": [
18
- "## Affine Transformations\n",
19
- "\n",
20
- "Spatial transformations are defined per image layer via a [4x4 transformation matrix](https://www.brainvoyager.com/bv/doc/UsersGuide/CoordsAndTransforms/SpatialTransformationMatrices.html) using the `model_matrix` property.\n",
21
- "\n",
22
- "This features is useful for pre-processing (e.g. flipping, rotating, scaling etc) your data, since these operations \n",
23
- "are executed performantly on the GPU thanks to [Viv](https://github.com/hms-dbmi/viv).\n",
24
- "\n",
25
- "In this notebook we will load a simple OME-NGFF dataset from the `Getting Started` notebook and apply a simple rotation."
26
- ]
27
- },
28
- {
29
- "cell_type": "code",
30
- "execution_count": null,
31
- "id": "31b069e3",
32
- "metadata": {},
33
- "outputs": [],
34
- "source": [
35
- "from create_fixture import create_ome_zarr\n",
36
- "import zarr\n",
37
- "import numpy as np\n",
38
- "\n",
39
- "import vizarr\n",
40
- "\n",
41
- "# creates an example OME-NGFF, see `getting_started.ipynb` for more details\n",
42
- "create_ome_zarr(\"astronaut.zarr\") \n",
43
- "\n",
44
- "# Create a viewer\n",
45
- "viewer = vizarr.Viewer()\n",
46
- "\n",
47
- "astronaut = {\n",
48
- " \"source\": zarr.open(\"astronaut.zarr\", mode=\"r\"),\n",
49
- " \"name\": \"astronaut\",\n",
50
- "}\n",
51
- "\n",
52
- "noise = {\n",
53
- " \"source\": zarr.array(np.random.randint(0, 255, (1024, 1024), dtype=np.uint8)),\n",
54
- " \"opacity\": 0.8,\n",
55
- " \"name\": \"noise\",\n",
56
- "}\n",
57
- "\n",
58
- "viewer.add_image(**astronaut)\n",
59
- "viewer.add_image(**noise)\n",
60
- "viewer"
61
- ]
62
- },
63
- {
64
- "cell_type": "markdown",
65
- "id": "50cc6192",
66
- "metadata": {},
67
- "source": [
68
- "### Apply translation and rotation to `noise` layer"
69
- ]
70
- },
71
- {
72
- "cell_type": "code",
73
- "execution_count": null,
74
- "id": "e967d280",
75
- "metadata": {},
76
- "outputs": [],
77
- "source": [
78
- "M = np.eye(4)\n",
79
- "\n",
80
- "# rotation\n",
81
- "theta = np.pi / 4\n",
82
- "M[:3, :3] = np.array([\n",
83
- " [ np.cos(theta), np.sin(theta), 0],\n",
84
- " [-np.sin(theta), np.cos(theta), 0],\n",
85
- " [ 0, 0, 1],\n",
86
- "])\n",
87
- "\n",
88
- "# translation\n",
89
- "M[:3,3] = np.array([512, 512, 0])\n",
90
- "\n",
91
- "M"
92
- ]
93
- },
94
- {
95
- "cell_type": "code",
96
- "execution_count": null,
97
- "id": "6ffbea5e",
98
- "metadata": {},
99
- "outputs": [],
100
- "source": [
101
- "translated_noise = { **noise, **{\"model_matrix\": M.ravel().tolist() } } # need to ravel into 1D list\n",
102
- "\n",
103
- "v = vizarr.Viewer()\n",
104
- "v.add_image(**astronaut)\n",
105
- "v.add_image(**translated_noise)\n",
106
- "v"
107
- ]
108
- },
109
- {
110
- "cell_type": "code",
111
- "execution_count": null,
112
- "id": "ff64b992",
113
- "metadata": {},
114
- "outputs": [],
115
- "source": []
116
- }
117
- ],
118
- "metadata": {
119
- "kernelspec": {
120
- "display_name": "Python 3 (ipykernel)",
121
- "language": "python",
122
- "name": "python3"
123
- },
124
- "language_info": {
125
- "codemirror_mode": {
126
- "name": "ipython",
127
- "version": 3
128
- },
129
- "file_extension": ".py",
130
- "mimetype": "text/x-python",
131
- "name": "python",
132
- "nbconvert_exporter": "python",
133
- "pygments_lexer": "ipython3",
134
- "version": "3.12.3"
135
- }
136
- },
137
- "nbformat": 4,
138
- "nbformat_minor": 5
139
- }
@@ -1,18 +0,0 @@
1
- [build-system]
2
- requires = ["hatchling"]
3
- build-backend = "hatchling.build"
4
-
5
- [project]
6
- name = "vizarr"
7
- version = "0.1.1"
8
- dependencies = ["anywidget>=0.9.13", "zarr<3"]
9
- requires-python = ">=3.9"
10
-
11
- [dependency-groups]
12
- dev = ["watchfiles", "jupyterlab", "scikit-image"]
13
-
14
- [tool.hatch.build.targets.sdist]
15
- only-include = ["src"]
16
-
17
- [tool.hatch.build.targets.wheel]
18
- packages = ["src/vizarr"]
@@ -1,10 +0,0 @@
1
- import importlib.metadata
2
-
3
- try:
4
- __version__ = importlib.metadata.version("vizarr")
5
- except importlib.metadata.PackageNotFoundError:
6
- __version__ = "unknown"
7
-
8
- del importlib
9
-
10
- from ._widget import Viewer