Skip to content

Commit e257292

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent eb6970b commit e257292

File tree

3 files changed

+331
-331
lines changed

3 files changed

+331
-331
lines changed
Lines changed: 179 additions & 179 deletions
Original file line numberDiff line numberDiff line change
@@ -1,189 +1,189 @@
11
{
2-
"cells": [
3-
{
4-
"cell_type": "markdown",
5-
"id": "255d97a8",
6-
"metadata": {},
7-
"source": [
8-
"# Write OME-ZARR images\n",
9-
"(basic:write)=\n",
10-
"\n",
11-
"Writing ome-zarr images is primarily exposed through the {py:class}`ome_zarr.image.NgffImage` and {py:class}`ome_zarr.image.NgffMultiscales` classes, which provide a high-level API for creating and manipulating OME-ZARR images and pyramids."
12-
]
13-
},
14-
{
15-
"cell_type": "code",
16-
"execution_count": 1,
17-
"id": "21e12529",
18-
"metadata": {},
19-
"outputs": [],
20-
"source": [
21-
"import numpy as np\n",
22-
"from ome_zarr.image import NgffImage, NgffMultiscales"
23-
]
24-
},
25-
{
26-
"cell_type": "markdown",
27-
"id": "33774809",
28-
"metadata": {},
29-
"source": [
30-
"Let's first create some random data to write:"
31-
]
32-
},
33-
{
34-
"cell_type": "code",
35-
"execution_count": 2,
36-
"id": "4cdd0f46",
37-
"metadata": {},
38-
"outputs": [],
39-
"source": [
40-
"path = \"test_ngff.ome.zarr\"\n",
41-
"\n",
42-
"# create some random data to write\n",
43-
"size_xy = 128\n",
44-
"size_z = 10\n",
45-
"rng = np.random.default_rng(0)\n",
46-
"data = rng.poisson(lam=10, size=(size_z, size_xy, size_xy)).astype(np.uint8)"
47-
]
48-
},
49-
{
50-
"cell_type": "code",
51-
"execution_count": 4,
52-
"id": "ce122c48",
53-
"metadata": {},
54-
"outputs": [
2+
"cells": [
553
{
56-
"data": {
57-
"text/plain": [
58-
"[]"
4+
"cell_type": "markdown",
5+
"id": "255d97a8",
6+
"metadata": {},
7+
"source": [
8+
"# Write OME-ZARR images\n",
9+
"(basic:write)=\n",
10+
"\n",
11+
"Writing ome-zarr images is primarily exposed through the {py:class}`ome_zarr.image.NgffImage` and {py:class}`ome_zarr.image.NgffMultiscales` classes, which provide a high-level API for creating and manipulating OME-ZARR images and pyramids."
5912
]
60-
},
61-
"execution_count": 4,
62-
"metadata": {},
63-
"output_type": "execute_result"
64-
}
65-
],
66-
"source": [
67-
"ngff_image = NgffImage(\n",
68-
" data=data,\n",
69-
" axes=\"zyx\",\n",
70-
" scale={\"z\": 0.5, \"y\": 0.1, \"x\": 0.1},\n",
71-
")\n",
72-
"\n",
73-
"ngff_multiscales = NgffMultiscales(image=ngff_image)\n",
74-
"ngff_multiscales.to_ome_zarr(path)"
75-
]
76-
},
77-
{
78-
"cell_type": "markdown",
79-
"id": "9015365c",
80-
"metadata": {},
81-
"source": [
82-
"## Write OME-ZARR images: Legacy API\n",
83-
"\n",
84-
"\n",
85-
"In previous versions, the principle entry-point for writing OME-ZARR images was {py:func}`ome_zarr.writer.write_image`.\n",
86-
"This takes an n-dimensional `numpy` array or `dask` array and writes it to the specified `zarr group` according to the OME-ZARR specification.\n",
87-
"By default, a pyramid of resolution levels will be created by down-sampling the data by a factor\n",
88-
"of 2 in the X and Y dimensions.\n",
89-
"For more custom control over the pyramid, see the more in-depth example on [scaling functions and scale factors](advanced:pyramid)."
90-
]
91-
},
92-
{
93-
"cell_type": "code",
94-
"execution_count": null,
95-
"id": "f87d36fa",
96-
"metadata": {},
97-
"outputs": [
13+
},
9814
{
99-
"data": {
100-
"text/plain": [
101-
"[]"
15+
"cell_type": "code",
16+
"execution_count": 1,
17+
"id": "21e12529",
18+
"metadata": {},
19+
"outputs": [],
20+
"source": [
21+
"import numpy as np\n",
22+
"from ome_zarr.image import NgffImage, NgffMultiscales"
10223
]
103-
},
104-
"execution_count": 1,
105-
"metadata": {},
106-
"output_type": "execute_result"
107-
}
108-
],
109-
"source": [
110-
"import numpy as np\n",
111-
"\n",
112-
"from ome_zarr.writer import write_image\n",
113-
"\n",
114-
"path = \"test_ngff_image.ome.zarr\"\n",
115-
"write_image(data, path, axes=\"zyx\")"
116-
]
117-
},
118-
{
119-
"cell_type": "markdown",
120-
"id": "03f9f06a",
121-
"metadata": {},
122-
"source": [
123-
"Alternatively, the {py:func}`ome_zarr.writer.write_multiscale` can be used,\n",
124-
"which takes a \"pyramid\" of pre-computed `numpy` arrays.\n",
125-
"\n",
126-
"The default version of OME-NGFF is v0.5, which is based on Zarr v3.\n",
127-
"A zarr v3 group and store is created by `zarr.open_group()` below.\n",
128-
"To write OME-NGFF v0.4 (Zarr v2), add the `zarr_format=2` argument."
129-
]
130-
},
131-
{
132-
"cell_type": "code",
133-
"execution_count": null,
134-
"id": "cfb1d49f",
135-
"metadata": {},
136-
"outputs": [
24+
},
25+
{
26+
"cell_type": "markdown",
27+
"id": "33774809",
28+
"metadata": {},
29+
"source": [
30+
"Let's first create some random data to write:"
31+
]
32+
},
33+
{
34+
"cell_type": "code",
35+
"execution_count": 2,
36+
"id": "4cdd0f46",
37+
"metadata": {},
38+
"outputs": [],
39+
"source": [
40+
"path = \"test_ngff.ome.zarr\"\n",
41+
"\n",
42+
"# create some random data to write\n",
43+
"size_xy = 128\n",
44+
"size_z = 10\n",
45+
"rng = np.random.default_rng(0)\n",
46+
"data = rng.poisson(lam=10, size=(size_z, size_xy, size_xy)).astype(np.uint8)"
47+
]
48+
},
13749
{
138-
"data": {
139-
"text/plain": [
140-
"[]"
50+
"cell_type": "code",
51+
"execution_count": 4,
52+
"id": "ce122c48",
53+
"metadata": {},
54+
"outputs": [
55+
{
56+
"data": {
57+
"text/plain": [
58+
"[]"
59+
]
60+
},
61+
"execution_count": 4,
62+
"metadata": {},
63+
"output_type": "execute_result"
64+
}
65+
],
66+
"source": [
67+
"ngff_image = NgffImage(\n",
68+
" data=data,\n",
69+
" axes=\"zyx\",\n",
70+
" scale={\"z\": 0.5, \"y\": 0.1, \"x\": 0.1},\n",
71+
")\n",
72+
"\n",
73+
"ngff_multiscales = NgffMultiscales(image=ngff_image)\n",
74+
"ngff_multiscales.to_ome_zarr(path)"
14175
]
142-
},
143-
"execution_count": 3,
144-
"metadata": {},
145-
"output_type": "execute_result"
76+
},
77+
{
78+
"cell_type": "markdown",
79+
"id": "9015365c",
80+
"metadata": {},
81+
"source": [
82+
"## Write OME-ZARR images: Legacy API\n",
83+
"\n",
84+
"\n",
85+
"In previous versions, the principle entry-point for writing OME-ZARR images was {py:func}`ome_zarr.writer.write_image`.\n",
86+
"This takes an n-dimensional `numpy` array or `dask` array and writes it to the specified `zarr group` according to the OME-ZARR specification.\n",
87+
"By default, a pyramid of resolution levels will be created by down-sampling the data by a factor\n",
88+
"of 2 in the X and Y dimensions.\n",
89+
"For more custom control over the pyramid, see the more in-depth example on [scaling functions and scale factors](advanced:pyramid)."
90+
]
91+
},
92+
{
93+
"cell_type": "code",
94+
"execution_count": null,
95+
"id": "f87d36fa",
96+
"metadata": {},
97+
"outputs": [
98+
{
99+
"data": {
100+
"text/plain": [
101+
"[]"
102+
]
103+
},
104+
"execution_count": 1,
105+
"metadata": {},
106+
"output_type": "execute_result"
107+
}
108+
],
109+
"source": [
110+
"import numpy as np\n",
111+
"\n",
112+
"from ome_zarr.writer import write_image\n",
113+
"\n",
114+
"path = \"test_ngff_image.ome.zarr\"\n",
115+
"write_image(data, path, axes=\"zyx\")"
116+
]
117+
},
118+
{
119+
"cell_type": "markdown",
120+
"id": "03f9f06a",
121+
"metadata": {},
122+
"source": [
123+
"Alternatively, the {py:func}`ome_zarr.writer.write_multiscale` can be used,\n",
124+
"which takes a \"pyramid\" of pre-computed `numpy` arrays.\n",
125+
"\n",
126+
"The default version of OME-NGFF is v0.5, which is based on Zarr v3.\n",
127+
"A zarr v3 group and store is created by `zarr.open_group()` below.\n",
128+
"To write OME-NGFF v0.4 (Zarr v2), add the `zarr_format=2` argument."
129+
]
130+
},
131+
{
132+
"cell_type": "code",
133+
"execution_count": null,
134+
"id": "cfb1d49f",
135+
"metadata": {},
136+
"outputs": [
137+
{
138+
"data": {
139+
"text/plain": [
140+
"[]"
141+
]
142+
},
143+
"execution_count": 3,
144+
"metadata": {},
145+
"output_type": "execute_result"
146+
}
147+
],
148+
"source": [
149+
"path = \"test_ngff_image_v2.ome.zarr\"\n",
150+
"write_image(data, path, axes=\"zyx\", zarr_format=2)"
151+
]
152+
},
153+
{
154+
"cell_type": "markdown",
155+
"id": "7b9a0138",
156+
"metadata": {},
157+
"source": [
158+
"To view the image, see tutorial on [viewing images](basic:view_images)."
159+
]
160+
},
161+
{
162+
"cell_type": "markdown",
163+
"id": "1f8a602d",
164+
"metadata": {},
165+
"source": []
166+
}
167+
],
168+
"metadata": {
169+
"kernelspec": {
170+
"display_name": "ome-zarr (3.12.12)",
171+
"language": "python",
172+
"name": "python3"
173+
},
174+
"language_info": {
175+
"codemirror_mode": {
176+
"name": "ipython",
177+
"version": 3
178+
},
179+
"file_extension": ".py",
180+
"mimetype": "text/x-python",
181+
"name": "python",
182+
"nbconvert_exporter": "python",
183+
"pygments_lexer": "ipython3",
184+
"version": "3.12.12"
146185
}
147-
],
148-
"source": [
149-
"path = \"test_ngff_image_v2.ome.zarr\"\n",
150-
"write_image(data, path, axes=\"zyx\", zarr_format=2)"
151-
]
152-
},
153-
{
154-
"cell_type": "markdown",
155-
"id": "7b9a0138",
156-
"metadata": {},
157-
"source": [
158-
"To view the image, see tutorial on [viewing images](basic:view_images)."
159-
]
160-
},
161-
{
162-
"cell_type": "markdown",
163-
"id": "1f8a602d",
164-
"metadata": {},
165-
"source": []
166-
}
167-
],
168-
"metadata": {
169-
"kernelspec": {
170-
"display_name": "ome-zarr (3.12.12)",
171-
"language": "python",
172-
"name": "python3"
173186
},
174-
"language_info": {
175-
"codemirror_mode": {
176-
"name": "ipython",
177-
"version": 3
178-
},
179-
"file_extension": ".py",
180-
"mimetype": "text/x-python",
181-
"name": "python",
182-
"nbconvert_exporter": "python",
183-
"pygments_lexer": "ipython3",
184-
"version": "3.12.12"
185-
}
186-
},
187-
"nbformat": 4,
188-
"nbformat_minor": 5
187+
"nbformat": 4,
188+
"nbformat_minor": 5
189189
}

0 commit comments

Comments
 (0)