ngio 0.5.0__py3-none-any.whl → 0.5.0a1__py3-none-any.whl
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.
- ngio/__init__.py +2 -5
- ngio/common/__init__.py +6 -11
- ngio/common/_masking_roi.py +54 -34
- ngio/common/_pyramid.py +87 -321
- ngio/common/_roi.py +330 -258
- ngio/experimental/iterators/_feature.py +3 -3
- ngio/experimental/iterators/_rois_utils.py +11 -10
- ngio/hcs/_plate.py +136 -192
- ngio/images/_abstract_image.py +35 -539
- ngio/images/_create.py +283 -0
- ngio/images/_create_synt_container.py +43 -40
- ngio/images/_image.py +251 -517
- ngio/images/_label.py +172 -249
- ngio/images/_masked_image.py +2 -2
- ngio/images/_ome_zarr_container.py +241 -644
- ngio/io_pipes/_io_pipes.py +9 -9
- ngio/io_pipes/_io_pipes_masked.py +7 -7
- ngio/io_pipes/_io_pipes_roi.py +6 -6
- ngio/io_pipes/_io_pipes_types.py +3 -3
- ngio/io_pipes/_match_shape.py +8 -6
- ngio/io_pipes/_ops_slices_utils.py +5 -8
- ngio/ome_zarr_meta/__init__.py +18 -29
- ngio/ome_zarr_meta/_meta_handlers.py +708 -392
- ngio/ome_zarr_meta/ngio_specs/__init__.py +0 -4
- ngio/ome_zarr_meta/ngio_specs/_axes.py +51 -152
- ngio/ome_zarr_meta/ngio_specs/_dataset.py +22 -13
- ngio/ome_zarr_meta/ngio_specs/_ngio_hcs.py +91 -129
- ngio/ome_zarr_meta/ngio_specs/_ngio_image.py +68 -57
- ngio/ome_zarr_meta/v04/__init__.py +1 -5
- ngio/ome_zarr_meta/v04/{_v04_spec.py → _v04_spec_utils.py} +85 -54
- ngio/ome_zarr_meta/v05/__init__.py +1 -5
- ngio/ome_zarr_meta/v05/{_v05_spec.py → _v05_spec_utils.py} +87 -64
- ngio/resources/__init__.py +1 -1
- ngio/resources/resource_model.py +1 -1
- ngio/tables/_tables_container.py +27 -85
- ngio/tables/backends/_anndata.py +8 -58
- ngio/tables/backends/_anndata_utils.py +6 -1
- ngio/tables/backends/_csv.py +19 -3
- ngio/tables/backends/_json.py +13 -10
- ngio/tables/backends/_non_zarr_backends.py +196 -0
- ngio/tables/backends/_parquet.py +31 -3
- ngio/tables/v1/_roi_table.py +27 -44
- ngio/utils/__init__.py +12 -8
- ngio/utils/_datasets.py +0 -6
- ngio/utils/_logger.py +50 -0
- ngio/utils/_zarr_utils.py +250 -292
- {ngio-0.5.0.dist-info → ngio-0.5.0a1.dist-info}/METADATA +6 -13
- ngio-0.5.0a1.dist-info/RECORD +88 -0
- {ngio-0.5.0.dist-info → ngio-0.5.0a1.dist-info}/WHEEL +1 -1
- ngio/images/_create_utils.py +0 -406
- ngio/tables/backends/_py_arrow_backends.py +0 -222
- ngio/utils/_cache.py +0 -48
- ngio-0.5.0.dist-info/RECORD +0 -88
- {ngio-0.5.0.dist-info → ngio-0.5.0a1.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,24 +1,18 @@
|
|
|
1
1
|
"""Abstract class for handling OME-NGFF images."""
|
|
2
2
|
|
|
3
3
|
import warnings
|
|
4
|
-
from collections.abc import
|
|
5
|
-
from typing import
|
|
4
|
+
from collections.abc import Sequence
|
|
5
|
+
from typing import Literal
|
|
6
6
|
|
|
7
7
|
import numpy as np
|
|
8
8
|
from zarr.core.array import CompressorLike
|
|
9
9
|
|
|
10
|
-
from ngio.
|
|
11
|
-
from ngio.images._create_utils import init_image_like
|
|
10
|
+
from ngio.images._create import create_empty_image_container
|
|
12
11
|
from ngio.images._image import Image, ImagesContainer
|
|
13
12
|
from ngio.images._label import Label, LabelsContainer
|
|
14
13
|
from ngio.images._masked_image import MaskedImage, MaskedLabel
|
|
15
|
-
from ngio.ome_zarr_meta import
|
|
16
|
-
LabelMetaHandler,
|
|
17
|
-
NgioImageMeta,
|
|
18
|
-
PixelSize,
|
|
19
|
-
)
|
|
14
|
+
from ngio.ome_zarr_meta import NgioImageMeta, PixelSize, find_label_meta_handler
|
|
20
15
|
from ngio.ome_zarr_meta.ngio_specs import (
|
|
21
|
-
Channel,
|
|
22
16
|
DefaultNgffVersion,
|
|
23
17
|
DefaultSpaceUnit,
|
|
24
18
|
DefaultTimeUnit,
|
|
@@ -26,8 +20,6 @@ from ngio.ome_zarr_meta.ngio_specs import (
|
|
|
26
20
|
SpaceUnits,
|
|
27
21
|
TimeUnits,
|
|
28
22
|
)
|
|
29
|
-
from ngio.ome_zarr_meta.ngio_specs._axes import AxesSetup
|
|
30
|
-
from ngio.ome_zarr_meta.ngio_specs._channels import ChannelsMeta
|
|
31
23
|
from ngio.tables import (
|
|
32
24
|
ConditionTable,
|
|
33
25
|
DefaultTableBackend,
|
|
@@ -43,7 +35,6 @@ from ngio.tables import (
|
|
|
43
35
|
)
|
|
44
36
|
from ngio.utils import (
|
|
45
37
|
AccessModeLiteral,
|
|
46
|
-
NgioError,
|
|
47
38
|
NgioValidationError,
|
|
48
39
|
NgioValueError,
|
|
49
40
|
StoreOrGroup,
|
|
@@ -51,33 +42,18 @@ from ngio.utils import (
|
|
|
51
42
|
)
|
|
52
43
|
|
|
53
44
|
|
|
54
|
-
def
|
|
55
|
-
handler: ZarrGroupHandler, create_mode: bool = True
|
|
56
|
-
) -> TablesContainer | None:
|
|
45
|
+
def _default_table_container(handler: ZarrGroupHandler) -> TablesContainer | None:
|
|
57
46
|
"""Return a default table container."""
|
|
58
|
-
|
|
59
|
-
|
|
47
|
+
success, table_handler = handler.safe_derive_handler("tables")
|
|
48
|
+
if success and isinstance(table_handler, ZarrGroupHandler):
|
|
60
49
|
return TablesContainer(table_handler)
|
|
61
|
-
except NgioError:
|
|
62
|
-
return None
|
|
63
50
|
|
|
64
51
|
|
|
65
|
-
def
|
|
66
|
-
handler: ZarrGroupHandler,
|
|
67
|
-
ngff_version: NgffVersions,
|
|
68
|
-
axes_setup: AxesSetup | None = None,
|
|
69
|
-
create_mode: bool = True,
|
|
70
|
-
) -> LabelsContainer | None:
|
|
52
|
+
def _default_label_container(handler: ZarrGroupHandler) -> LabelsContainer | None:
|
|
71
53
|
"""Return a default label container."""
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return LabelsContainer(
|
|
75
|
-
group_handler=label_handler,
|
|
76
|
-
axes_setup=axes_setup,
|
|
77
|
-
ngff_version=ngff_version,
|
|
78
|
-
)
|
|
79
|
-
except FileNotFoundError:
|
|
80
|
-
return None
|
|
54
|
+
success, label_handler = handler.safe_derive_handler("labels")
|
|
55
|
+
if success and isinstance(label_handler, ZarrGroupHandler):
|
|
56
|
+
return LabelsContainer(label_handler)
|
|
81
57
|
|
|
82
58
|
|
|
83
59
|
class OmeZarrContainer:
|
|
@@ -106,7 +82,6 @@ class OmeZarrContainer:
|
|
|
106
82
|
group_handler: ZarrGroupHandler,
|
|
107
83
|
table_container: TablesContainer | None = None,
|
|
108
84
|
label_container: LabelsContainer | None = None,
|
|
109
|
-
axes_setup: AxesSetup | None = None,
|
|
110
85
|
validate_paths: bool = False,
|
|
111
86
|
) -> None:
|
|
112
87
|
"""Initialize the OmeZarrContainer.
|
|
@@ -115,19 +90,16 @@ class OmeZarrContainer:
|
|
|
115
90
|
group_handler (ZarrGroupHandler): The Zarr group handler.
|
|
116
91
|
table_container (TablesContainer | None): The tables container.
|
|
117
92
|
label_container (LabelsContainer | None): The labels container.
|
|
118
|
-
axes_setup (AxesSetup | None): Axes setup to load ome-zarr with
|
|
119
|
-
non-standard axes configurations.
|
|
120
93
|
validate_paths (bool): Whether to validate the paths of the image multiscale
|
|
121
94
|
"""
|
|
122
95
|
self._group_handler = group_handler
|
|
123
|
-
self._images_container = ImagesContainer(
|
|
124
|
-
|
|
125
|
-
)
|
|
96
|
+
self._images_container = ImagesContainer(self._group_handler)
|
|
97
|
+
|
|
126
98
|
self._labels_container = label_container
|
|
127
99
|
self._tables_container = table_container
|
|
128
100
|
|
|
129
101
|
if validate_paths:
|
|
130
|
-
for level_path in self._images_container.
|
|
102
|
+
for level_path in self._images_container.levels_paths:
|
|
131
103
|
self.get_image(path=level_path)
|
|
132
104
|
|
|
133
105
|
def __repr__(self) -> str:
|
|
@@ -156,18 +128,13 @@ class OmeZarrContainer:
|
|
|
156
128
|
"""
|
|
157
129
|
return self._images_container
|
|
158
130
|
|
|
159
|
-
def _get_labels_container(self
|
|
131
|
+
def _get_labels_container(self) -> LabelsContainer | None:
|
|
160
132
|
"""Return the labels container."""
|
|
161
|
-
if self._labels_container is
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
self.
|
|
166
|
-
create_mode=create_mode,
|
|
167
|
-
ngff_version=self.meta.version,
|
|
168
|
-
axes_setup=self._images_container.axes_setup,
|
|
169
|
-
)
|
|
170
|
-
self._labels_container = _labels_container
|
|
133
|
+
if self._labels_container is None:
|
|
134
|
+
_labels_container = _default_label_container(self._group_handler)
|
|
135
|
+
if _labels_container is None:
|
|
136
|
+
return None
|
|
137
|
+
self._labels_container = _labels_container
|
|
171
138
|
return self._labels_container
|
|
172
139
|
|
|
173
140
|
@property
|
|
@@ -178,15 +145,13 @@ class OmeZarrContainer:
|
|
|
178
145
|
raise NgioValidationError("No labels found in the image.")
|
|
179
146
|
return _labels_container
|
|
180
147
|
|
|
181
|
-
def _get_tables_container(self
|
|
148
|
+
def _get_tables_container(self) -> TablesContainer | None:
|
|
182
149
|
"""Return the tables container."""
|
|
183
|
-
if self._tables_container is
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
self.
|
|
188
|
-
)
|
|
189
|
-
self._tables_container = _tables_container
|
|
150
|
+
if self._tables_container is None:
|
|
151
|
+
_tables_container = _default_table_container(self._group_handler)
|
|
152
|
+
if _tables_container is None:
|
|
153
|
+
return None
|
|
154
|
+
self._tables_container = _tables_container
|
|
190
155
|
return self._tables_container
|
|
191
156
|
|
|
192
157
|
@property
|
|
@@ -197,238 +162,116 @@ class OmeZarrContainer:
|
|
|
197
162
|
raise NgioValidationError("No tables found in the image.")
|
|
198
163
|
return _tables_container
|
|
199
164
|
|
|
200
|
-
@property
|
|
201
|
-
def meta(self) -> NgioImageMeta:
|
|
202
|
-
"""Return the image metadata."""
|
|
203
|
-
return self.images_container.meta
|
|
204
|
-
|
|
205
165
|
@property
|
|
206
166
|
def image_meta(self) -> NgioImageMeta:
|
|
207
167
|
"""Return the image metadata."""
|
|
208
|
-
|
|
209
|
-
"'image_meta' is deprecated and will be removed in ngio=0.6. "
|
|
210
|
-
"Please use 'meta' instead.",
|
|
211
|
-
DeprecationWarning,
|
|
212
|
-
stacklevel=2,
|
|
213
|
-
)
|
|
214
|
-
return self.images_container.meta
|
|
215
|
-
|
|
216
|
-
@property
|
|
217
|
-
def axes_setup(self) -> AxesSetup:
|
|
218
|
-
"""Return the axes setup."""
|
|
219
|
-
return self.images_container.axes_setup
|
|
168
|
+
return self._images_container.meta
|
|
220
169
|
|
|
221
170
|
@property
|
|
222
171
|
def levels(self) -> int:
|
|
223
172
|
"""Return the number of levels in the image."""
|
|
224
|
-
return self.
|
|
225
|
-
|
|
226
|
-
@property
|
|
227
|
-
def level_paths(self) -> list[str]:
|
|
228
|
-
"""Return the paths of the levels in the image."""
|
|
229
|
-
return self.images_container.level_paths
|
|
173
|
+
return self._images_container.levels
|
|
230
174
|
|
|
231
175
|
@property
|
|
232
176
|
def levels_paths(self) -> list[str]:
|
|
233
|
-
"""
|
|
234
|
-
|
|
235
|
-
"'levels_paths' is deprecated and will be removed in ngio=0.6. "
|
|
236
|
-
"Please use 'level_paths' instead.",
|
|
237
|
-
DeprecationWarning,
|
|
238
|
-
stacklevel=2,
|
|
239
|
-
)
|
|
240
|
-
return self.images_container.level_paths
|
|
177
|
+
"""Return the paths of the levels in the image."""
|
|
178
|
+
return self._images_container.levels_paths
|
|
241
179
|
|
|
242
180
|
@property
|
|
243
181
|
def is_3d(self) -> bool:
|
|
244
182
|
"""Return True if the image is 3D."""
|
|
245
|
-
return self.
|
|
183
|
+
return self.get_image().is_3d
|
|
246
184
|
|
|
247
185
|
@property
|
|
248
186
|
def is_2d(self) -> bool:
|
|
249
187
|
"""Return True if the image is 2D."""
|
|
250
|
-
return self.
|
|
188
|
+
return self.get_image().is_2d
|
|
251
189
|
|
|
252
190
|
@property
|
|
253
191
|
def is_time_series(self) -> bool:
|
|
254
192
|
"""Return True if the image is a time series."""
|
|
255
|
-
return self.
|
|
193
|
+
return self.get_image().is_time_series
|
|
256
194
|
|
|
257
195
|
@property
|
|
258
196
|
def is_2d_time_series(self) -> bool:
|
|
259
197
|
"""Return True if the image is a 2D time series."""
|
|
260
|
-
return self.
|
|
198
|
+
return self.get_image().is_2d_time_series
|
|
261
199
|
|
|
262
200
|
@property
|
|
263
201
|
def is_3d_time_series(self) -> bool:
|
|
264
202
|
"""Return True if the image is a 3D time series."""
|
|
265
|
-
return self.
|
|
203
|
+
return self.get_image().is_3d_time_series
|
|
266
204
|
|
|
267
205
|
@property
|
|
268
206
|
def is_multi_channels(self) -> bool:
|
|
269
207
|
"""Return True if the image is multichannel."""
|
|
270
|
-
return self.
|
|
208
|
+
return self.get_image().is_multi_channels
|
|
271
209
|
|
|
272
210
|
@property
|
|
273
211
|
def space_unit(self) -> str | None:
|
|
274
212
|
"""Return the space unit of the image."""
|
|
275
|
-
return self.
|
|
213
|
+
return self.image_meta.space_unit
|
|
276
214
|
|
|
277
215
|
@property
|
|
278
216
|
def time_unit(self) -> str | None:
|
|
279
217
|
"""Return the time unit of the image."""
|
|
280
|
-
return self.
|
|
218
|
+
return self.image_meta.time_unit
|
|
281
219
|
|
|
282
220
|
@property
|
|
283
221
|
def channel_labels(self) -> list[str]:
|
|
284
222
|
"""Return the channels of the image."""
|
|
285
|
-
|
|
223
|
+
image = self.get_image()
|
|
224
|
+
return image.channel_labels
|
|
286
225
|
|
|
287
226
|
@property
|
|
288
227
|
def wavelength_ids(self) -> list[str | None]:
|
|
289
228
|
"""Return the list of wavelength of the image."""
|
|
290
|
-
|
|
229
|
+
image = self.get_image()
|
|
230
|
+
return image.wavelength_ids
|
|
291
231
|
|
|
292
232
|
@property
|
|
293
233
|
def num_channels(self) -> int:
|
|
294
234
|
"""Return the number of channels."""
|
|
295
|
-
return self.
|
|
235
|
+
return len(self.channel_labels)
|
|
296
236
|
|
|
297
237
|
def get_channel_idx(
|
|
298
238
|
self, channel_label: str | None = None, wavelength_id: str | None = None
|
|
299
239
|
) -> int:
|
|
300
240
|
"""Get the index of a channel by its label or wavelength ID."""
|
|
301
|
-
|
|
241
|
+
image = self.get_image()
|
|
242
|
+
return image.channels_meta.get_channel_idx(
|
|
302
243
|
channel_label=channel_label, wavelength_id=wavelength_id
|
|
303
244
|
)
|
|
304
245
|
|
|
305
246
|
def set_channel_meta(
|
|
306
247
|
self,
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
wavelength_id: Sequence[str | None] | None = None,
|
|
310
|
-
start: Sequence[float | None] | None = None,
|
|
311
|
-
end: Sequence[float | None] | None = None,
|
|
248
|
+
labels: Sequence[str] | int | None = None,
|
|
249
|
+
wavelength_id: Sequence[str] | None = None,
|
|
312
250
|
percentiles: tuple[float, float] | None = None,
|
|
313
|
-
colors: Sequence[str
|
|
314
|
-
active: Sequence[bool
|
|
251
|
+
colors: Sequence[str] | None = None,
|
|
252
|
+
active: Sequence[bool] | None = None,
|
|
315
253
|
**omero_kwargs: dict,
|
|
316
254
|
) -> None:
|
|
317
|
-
"""Create a ChannelsMeta object with the default unit.
|
|
318
|
-
|
|
319
|
-
Args:
|
|
320
|
-
channel_meta (ChannelsMeta | None): The channels metadata to set.
|
|
321
|
-
If none, it will fall back to the deprecated parameters.
|
|
322
|
-
labels(Sequence[str | None] | int): Deprecated. The list of channels names
|
|
323
|
-
in the image. If an integer is provided, the channels will
|
|
324
|
-
be named "channel_i".
|
|
325
|
-
wavelength_id(Sequence[str | None]): Deprecated. The wavelength ID of the
|
|
326
|
-
channel. If None, the wavelength ID will be the same as
|
|
327
|
-
the channel name.
|
|
328
|
-
start(Sequence[float | None]): Deprecated. The start value for each channel.
|
|
329
|
-
If None, the start value will be computed from the image.
|
|
330
|
-
end(Sequence[float | None]): Deprecated. The end value for each channel.
|
|
331
|
-
If None, the end value will be computed from the image.
|
|
332
|
-
percentiles(tuple[float, float] | None): Deprecated. The start and end
|
|
333
|
-
percentiles for each channel. If None, the percentiles will
|
|
334
|
-
not be computed.
|
|
335
|
-
colors(Sequence[str | None]): Deprecated. The list of colors for the
|
|
336
|
-
channels. If None, the colors will be random.
|
|
337
|
-
active (Sequence[bool | None]): Deprecated. Whether the channel should
|
|
338
|
-
be shown by default.
|
|
339
|
-
omero_kwargs(dict): Deprecated. Extra fields to store in the omero
|
|
340
|
-
attributes.
|
|
341
|
-
"""
|
|
255
|
+
"""Create a ChannelsMeta object with the default unit."""
|
|
342
256
|
self._images_container.set_channel_meta(
|
|
343
|
-
channel_meta=channel_meta,
|
|
344
257
|
labels=labels,
|
|
345
258
|
wavelength_id=wavelength_id,
|
|
346
|
-
start=
|
|
347
|
-
end=
|
|
259
|
+
start=None,
|
|
260
|
+
end=None,
|
|
348
261
|
percentiles=percentiles,
|
|
349
262
|
colors=colors,
|
|
350
263
|
active=active,
|
|
351
264
|
**omero_kwargs,
|
|
352
265
|
)
|
|
353
266
|
|
|
354
|
-
def set_channel_labels(
|
|
355
|
-
self,
|
|
356
|
-
labels: Sequence[str],
|
|
357
|
-
) -> None:
|
|
358
|
-
"""Update the labels of the channels.
|
|
359
|
-
|
|
360
|
-
Args:
|
|
361
|
-
labels (Sequence[str]): The new labels for the channels.
|
|
362
|
-
"""
|
|
363
|
-
self._images_container.set_channel_labels(labels=labels)
|
|
364
|
-
|
|
365
|
-
def set_channel_colors(
|
|
366
|
-
self,
|
|
367
|
-
colors: Sequence[str],
|
|
368
|
-
) -> None:
|
|
369
|
-
"""Update the colors of the channels.
|
|
370
|
-
|
|
371
|
-
Args:
|
|
372
|
-
colors (Sequence[str]): The new colors for the channels.
|
|
373
|
-
"""
|
|
374
|
-
self._images_container.set_channel_colors(colors=colors)
|
|
375
|
-
|
|
376
267
|
def set_channel_percentiles(
|
|
377
268
|
self,
|
|
378
269
|
start_percentile: float = 0.1,
|
|
379
270
|
end_percentile: float = 99.9,
|
|
380
271
|
) -> None:
|
|
381
|
-
"""
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
start_percentile (float): The start percentile.
|
|
385
|
-
end_percentile (float): The end percentile.
|
|
386
|
-
"""
|
|
387
|
-
warnings.warn(
|
|
388
|
-
"The 'set_channel_percentiles' method is deprecated and will be removed in "
|
|
389
|
-
"ngio=0.6. Please use 'set_channel_windows_with_percentiles' instead.",
|
|
390
|
-
DeprecationWarning,
|
|
391
|
-
stacklevel=2,
|
|
392
|
-
)
|
|
393
|
-
self._images_container.set_channel_windows_with_percentiles(
|
|
394
|
-
percentiles=(start_percentile, end_percentile)
|
|
395
|
-
)
|
|
396
|
-
|
|
397
|
-
def set_channel_windows(
|
|
398
|
-
self,
|
|
399
|
-
starts_ends: Sequence[tuple[float, float]],
|
|
400
|
-
min_max: Sequence[tuple[float, float]] | None = None,
|
|
401
|
-
) -> None:
|
|
402
|
-
"""Update the channel windows.
|
|
403
|
-
|
|
404
|
-
These values are used by viewers to set the display
|
|
405
|
-
range of each channel.
|
|
406
|
-
|
|
407
|
-
Args:
|
|
408
|
-
starts_ends (Sequence[tuple[float, float]]): The start and end values
|
|
409
|
-
for each channel.
|
|
410
|
-
min_max (Sequence[tuple[float, float]] | None): The min and max values
|
|
411
|
-
for each channel. If None, the min and max values will not be updated.
|
|
412
|
-
"""
|
|
413
|
-
self._images_container.set_channel_windows(
|
|
414
|
-
starts_ends=starts_ends,
|
|
415
|
-
min_max=min_max,
|
|
416
|
-
)
|
|
417
|
-
|
|
418
|
-
def set_channel_windows_with_percentiles(
|
|
419
|
-
self,
|
|
420
|
-
percentiles: tuple[float, float] | list[tuple[float, float]] = (0.1, 99.9),
|
|
421
|
-
) -> None:
|
|
422
|
-
"""Update the channel windows using percentiles.
|
|
423
|
-
|
|
424
|
-
Args:
|
|
425
|
-
percentiles (tuple[float, float] | list[tuple[float, float]]):
|
|
426
|
-
The start and end percentiles for each channel.
|
|
427
|
-
If a single tuple is provided,
|
|
428
|
-
the same percentiles will be used for all channels.
|
|
429
|
-
"""
|
|
430
|
-
self._images_container.set_channel_windows_with_percentiles(
|
|
431
|
-
percentiles=percentiles
|
|
272
|
+
"""Update the percentiles of the image."""
|
|
273
|
+
self._images_container.set_channel_percentiles(
|
|
274
|
+
start_percentile=start_percentile, end_percentile=end_percentile
|
|
432
275
|
)
|
|
433
276
|
|
|
434
277
|
def set_axes_units(
|
|
@@ -444,35 +287,12 @@ class OmeZarrContainer:
|
|
|
444
287
|
time_unit (TimeUnits): The unit of time.
|
|
445
288
|
set_labels (bool): Whether to set the units for the labels as well.
|
|
446
289
|
"""
|
|
447
|
-
if set_labels:
|
|
448
|
-
for label_name in self.list_labels():
|
|
449
|
-
label = self.get_label(label_name)
|
|
450
|
-
label.set_axes_unit(space_unit=space_unit, time_unit=time_unit)
|
|
451
290
|
self._images_container.set_axes_unit(space_unit=space_unit, time_unit=time_unit)
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
self
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
"""Set the axes names of the image.
|
|
458
|
-
|
|
459
|
-
Args:
|
|
460
|
-
axes_names (Sequence[str]): The axes names of the image.
|
|
461
|
-
"""
|
|
462
|
-
self._images_container.set_axes_names(axes_names=axes_names)
|
|
463
|
-
|
|
464
|
-
def set_name(
|
|
465
|
-
self,
|
|
466
|
-
name: str,
|
|
467
|
-
) -> None:
|
|
468
|
-
"""Set the name of the image in the metadata.
|
|
469
|
-
|
|
470
|
-
This does not change the group name or any paths.
|
|
471
|
-
|
|
472
|
-
Args:
|
|
473
|
-
name (str): The name of the image.
|
|
474
|
-
"""
|
|
475
|
-
self._images_container.set_name(name=name)
|
|
291
|
+
if not set_labels:
|
|
292
|
+
return
|
|
293
|
+
for label_name in self.list_labels():
|
|
294
|
+
label = self.get_label(label_name)
|
|
295
|
+
label.set_axes_unit(space_unit=space_unit, time_unit=time_unit)
|
|
476
296
|
|
|
477
297
|
def get_image(
|
|
478
298
|
self,
|
|
@@ -583,122 +403,82 @@ class OmeZarrContainer:
|
|
|
583
403
|
self,
|
|
584
404
|
store: StoreOrGroup,
|
|
585
405
|
ref_path: str | None = None,
|
|
586
|
-
# Metadata parameters
|
|
587
406
|
shape: Sequence[int] | None = None,
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
407
|
+
labels: Sequence[str] | None = None,
|
|
408
|
+
pixel_size: PixelSize | None = None,
|
|
409
|
+
axes_names: Sequence[str] | None = None,
|
|
591
410
|
name: str | None = None,
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
# Zarr Array parameters
|
|
597
|
-
chunks: ChunksLike | None = None,
|
|
598
|
-
shards: ShardsLike | None = None,
|
|
599
|
-
dtype: str = "uint16",
|
|
600
|
-
dimension_separator: Literal[".", "/"] = "/",
|
|
601
|
-
compressors: CompressorLike = "auto",
|
|
602
|
-
extra_array_kwargs: Mapping[str, Any] | None = None,
|
|
603
|
-
overwrite: bool = False,
|
|
604
|
-
# Copy from current image
|
|
411
|
+
chunks: Sequence[int] | None = None,
|
|
412
|
+
dtype: str | None = None,
|
|
413
|
+
dimension_separator: Literal[".", "/"] | None = None,
|
|
414
|
+
compressors: CompressorLike | None = None,
|
|
605
415
|
copy_labels: bool = False,
|
|
606
416
|
copy_tables: bool = False,
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
pixel_size: PixelSize | None = None,
|
|
417
|
+
ngff_version: NgffVersions | None = None,
|
|
418
|
+
overwrite: bool = False,
|
|
610
419
|
) -> "OmeZarrContainer":
|
|
611
|
-
"""
|
|
612
|
-
|
|
613
|
-
If a kwarg is not provided, the value from the reference image will be used.
|
|
420
|
+
"""Create an empty OME-Zarr container from an existing image.
|
|
614
421
|
|
|
615
422
|
Args:
|
|
616
423
|
store (StoreOrGroup): The Zarr store or group to create the image in.
|
|
617
|
-
ref_path (str | None): The path to the reference image in
|
|
618
|
-
container.
|
|
424
|
+
ref_path (str | None): The path to the reference image in
|
|
425
|
+
the image container.
|
|
619
426
|
shape (Sequence[int] | None): The shape of the new image.
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
427
|
+
labels (Sequence[str] | None): The labels of the new image.
|
|
428
|
+
pixel_size (PixelSize | None): The pixel size of the new image.
|
|
429
|
+
axes_names (Sequence[str] | None): The axes names of the new image.
|
|
430
|
+
chunks (Sequence[int] | None): The chunk shape of the new image.
|
|
431
|
+
dtype (str | None): The data type of the new image.
|
|
624
432
|
name (str | None): The name of the new image.
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
channels_meta (Sequence[str | Channel] | None): The channels metadata
|
|
635
|
-
of the new image.
|
|
636
|
-
ngff_version (NgffVersions | None): The NGFF version to use.
|
|
637
|
-
chunks (ChunksLike | None): The chunk shape of the new image.
|
|
638
|
-
shards (ShardsLike | None): The shard shape of the new image.
|
|
639
|
-
dtype (str): The data type of the new image. Defaults to "uint16".
|
|
640
|
-
dimension_separator (Literal[".", "/"]): The separator to use for
|
|
641
|
-
dimensions. Defaults to "/".
|
|
642
|
-
compressors (CompressorLike): The compressors to use. Defaults to "auto".
|
|
643
|
-
extra_array_kwargs (Mapping[str, Any] | None): Extra arguments to pass to
|
|
644
|
-
the zarr array creation.
|
|
645
|
-
overwrite (bool): Whether to overwrite an existing image. Defaults to False.
|
|
646
|
-
copy_labels (bool): Whether to copy the labels from the current image.
|
|
647
|
-
Defaults to False.
|
|
648
|
-
copy_tables (bool): Whether to copy the tables from the current image.
|
|
649
|
-
Defaults to False.
|
|
650
|
-
labels (Sequence[str] | None): Deprecated. This argument is deprecated,
|
|
651
|
-
please use channels_meta instead.
|
|
652
|
-
pixel_size (PixelSize | None): Deprecated. The pixel size of the new image.
|
|
653
|
-
This argument is deprecated, please use pixelsize, z_spacing,
|
|
654
|
-
and time_spacing instead.
|
|
433
|
+
dimension_separator (DIMENSION_SEPARATOR | None): The dimension
|
|
434
|
+
separator to use. If None, the dimension separator of the
|
|
435
|
+
reference image will be used.
|
|
436
|
+
compressors (CompressorLike | None): The compressors to use. If None,
|
|
437
|
+
the compressors of the reference image will be used.
|
|
438
|
+
copy_labels (bool): Whether to copy the labels from the reference image.
|
|
439
|
+
copy_tables (bool): Whether to copy the tables from the reference image.
|
|
440
|
+
ngff_version (NgffVersions): The NGFF version to use.
|
|
441
|
+
overwrite (bool): Whether to overwrite an existing image.
|
|
655
442
|
|
|
656
443
|
Returns:
|
|
657
|
-
OmeZarrContainer: The new
|
|
444
|
+
OmeZarrContainer: The new image container.
|
|
658
445
|
|
|
659
446
|
"""
|
|
660
447
|
new_container = self._images_container.derive(
|
|
661
448
|
store=store,
|
|
662
449
|
ref_path=ref_path,
|
|
663
450
|
shape=shape,
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
451
|
+
labels=labels,
|
|
452
|
+
pixel_size=pixel_size,
|
|
453
|
+
axes_names=axes_names,
|
|
667
454
|
name=name,
|
|
668
|
-
translation=translation,
|
|
669
|
-
channels_meta=channels_meta,
|
|
670
|
-
channels_policy=channels_policy,
|
|
671
|
-
ngff_version=ngff_version,
|
|
672
455
|
chunks=chunks,
|
|
673
|
-
shards=shards,
|
|
674
456
|
dtype=dtype,
|
|
675
457
|
dimension_separator=dimension_separator,
|
|
676
458
|
compressors=compressors,
|
|
677
|
-
|
|
459
|
+
ngff_version=ngff_version,
|
|
678
460
|
overwrite=overwrite,
|
|
679
|
-
labels=labels,
|
|
680
|
-
pixel_size=pixel_size,
|
|
681
461
|
)
|
|
462
|
+
|
|
682
463
|
new_ome_zarr = OmeZarrContainer(
|
|
683
464
|
group_handler=new_container._group_handler,
|
|
684
465
|
validate_paths=False,
|
|
685
|
-
axes_setup=new_container.meta.axes_handler.axes_setup,
|
|
686
466
|
)
|
|
687
467
|
|
|
688
468
|
if copy_labels:
|
|
689
|
-
self.labels_container._group_handler.
|
|
690
|
-
new_ome_zarr.labels_container._group_handler
|
|
469
|
+
self.labels_container._group_handler.copy_handler(
|
|
470
|
+
new_ome_zarr.labels_container._group_handler
|
|
691
471
|
)
|
|
692
472
|
|
|
693
473
|
if copy_tables:
|
|
694
|
-
self.tables_container._group_handler.
|
|
695
|
-
new_ome_zarr.tables_container._group_handler
|
|
474
|
+
self.tables_container._group_handler.copy_handler(
|
|
475
|
+
new_ome_zarr.tables_container._group_handler
|
|
696
476
|
)
|
|
697
477
|
return new_ome_zarr
|
|
698
478
|
|
|
699
479
|
def list_tables(self, filter_types: TypedTable | str | None = None) -> list[str]:
|
|
700
480
|
"""List all tables in the image."""
|
|
701
|
-
table_container = self._get_tables_container(
|
|
481
|
+
table_container = self._get_tables_container()
|
|
702
482
|
if table_container is None:
|
|
703
483
|
return []
|
|
704
484
|
|
|
@@ -791,8 +571,8 @@ class OmeZarrContainer:
|
|
|
791
571
|
"""
|
|
792
572
|
if check_type is not None:
|
|
793
573
|
warnings.warn(
|
|
794
|
-
"The 'check_type' argument is deprecated and will be removed in "
|
|
795
|
-
"ngio=0.
|
|
574
|
+
"The 'check_type' argument is deprecated, and will be removed in "
|
|
575
|
+
"ngio=0.3. Use 'get_table_as' instead or one of the "
|
|
796
576
|
"type specific get_*table() methods.",
|
|
797
577
|
DeprecationWarning,
|
|
798
578
|
stacklevel=2,
|
|
@@ -839,28 +619,9 @@ class OmeZarrContainer:
|
|
|
839
619
|
name=name, table=table, backend=backend, overwrite=overwrite
|
|
840
620
|
)
|
|
841
621
|
|
|
842
|
-
def delete_table(self, name: str, missing_ok: bool = False) -> None:
|
|
843
|
-
"""Delete a table from the group.
|
|
844
|
-
|
|
845
|
-
Args:
|
|
846
|
-
name (str): The name of the table to delete.
|
|
847
|
-
missing_ok (bool): If True, do not raise an error if the table does not
|
|
848
|
-
exist.
|
|
849
|
-
|
|
850
|
-
"""
|
|
851
|
-
table_container = self._get_tables_container(create_mode=False)
|
|
852
|
-
if table_container is None and missing_ok:
|
|
853
|
-
return
|
|
854
|
-
if table_container is None:
|
|
855
|
-
raise NgioValueError(
|
|
856
|
-
f"No tables found in the image, cannot delete {name}. "
|
|
857
|
-
"Set missing_ok=True to ignore this error."
|
|
858
|
-
)
|
|
859
|
-
table_container.delete(name=name, missing_ok=missing_ok)
|
|
860
|
-
|
|
861
622
|
def list_labels(self) -> list[str]:
|
|
862
623
|
"""List all labels in the image."""
|
|
863
|
-
label_container = self._get_labels_container(
|
|
624
|
+
label_container = self._get_labels_container()
|
|
864
625
|
if label_container is None:
|
|
865
626
|
return []
|
|
866
627
|
return label_container.list()
|
|
@@ -923,90 +684,42 @@ class OmeZarrContainer:
|
|
|
923
684
|
masking_roi_table=masking_table,
|
|
924
685
|
)
|
|
925
686
|
|
|
926
|
-
def delete_label(self, name: str, missing_ok: bool = False) -> None:
|
|
927
|
-
"""Delete a label from the group.
|
|
928
|
-
|
|
929
|
-
Args:
|
|
930
|
-
name (str): The name of the label to delete.
|
|
931
|
-
missing_ok (bool): If True, do not raise an error if the label does not
|
|
932
|
-
exist.
|
|
933
|
-
|
|
934
|
-
"""
|
|
935
|
-
label_container = self._get_labels_container(create_mode=False)
|
|
936
|
-
if label_container is None and missing_ok:
|
|
937
|
-
return
|
|
938
|
-
if label_container is None:
|
|
939
|
-
raise NgioValueError(
|
|
940
|
-
f"No labels found in the image, cannot delete {name}. "
|
|
941
|
-
"Set missing_ok=True to ignore this error."
|
|
942
|
-
)
|
|
943
|
-
label_container.delete(name=name, missing_ok=missing_ok)
|
|
944
|
-
|
|
945
687
|
def derive_label(
|
|
946
688
|
self,
|
|
947
689
|
name: str,
|
|
948
690
|
ref_image: Image | Label | None = None,
|
|
949
|
-
# Metadata parameters
|
|
950
691
|
shape: Sequence[int] | None = None,
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
channels_policy: Literal["same", "squeeze", "singleton"] | int = "squeeze",
|
|
956
|
-
ngff_version: NgffVersions | None = None,
|
|
957
|
-
# Zarr Array parameters
|
|
958
|
-
chunks: ChunksLike | None = None,
|
|
959
|
-
shards: ShardsLike | None = None,
|
|
960
|
-
dtype: str | None = None,
|
|
692
|
+
pixel_size: PixelSize | None = None,
|
|
693
|
+
axes_names: Sequence[str] | None = None,
|
|
694
|
+
chunks: Sequence[int] | None = None,
|
|
695
|
+
dtype: str = "uint32",
|
|
961
696
|
dimension_separator: Literal[".", "/"] | None = None,
|
|
962
697
|
compressors: CompressorLike | None = None,
|
|
963
|
-
extra_array_kwargs: Mapping[str, Any] | None = None,
|
|
964
698
|
overwrite: bool = False,
|
|
965
|
-
# Deprecated arguments
|
|
966
|
-
labels: Sequence[str] | None = None,
|
|
967
|
-
pixel_size: PixelSize | None = None,
|
|
968
699
|
) -> "Label":
|
|
969
|
-
"""
|
|
700
|
+
"""Create an empty OME-Zarr label from a reference image.
|
|
970
701
|
|
|
971
|
-
|
|
702
|
+
And add the label to the /labels group.
|
|
972
703
|
|
|
973
704
|
Args:
|
|
974
|
-
name (str): The name of the new
|
|
975
|
-
ref_image (Image | Label | None):
|
|
976
|
-
|
|
977
|
-
shape (Sequence[int] | None): The shape of the new
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
- If an integer is provided, the channels axis will be changed to have
|
|
990
|
-
that size.
|
|
991
|
-
Defaults to "squeeze".
|
|
992
|
-
ngff_version (NgffVersions | None): The NGFF version to use.
|
|
993
|
-
chunks (ChunksLike | None): The chunk shape of the new label.
|
|
994
|
-
shards (ShardsLike | None): The shard shape of the new label.
|
|
995
|
-
dtype (str | None): The data type of the new label.
|
|
996
|
-
dimension_separator (Literal[".", "/"] | None): The separator to use for
|
|
997
|
-
dimensions.
|
|
998
|
-
compressors (CompressorLike | None): The compressors to use.
|
|
999
|
-
extra_array_kwargs (Mapping[str, Any] | None): Extra arguments to pass to
|
|
1000
|
-
the zarr array creation.
|
|
1001
|
-
overwrite (bool): Whether to overwrite an existing label. Defaults to False.
|
|
1002
|
-
labels (Sequence[str] | None): Deprecated. This argument is deprecated,
|
|
1003
|
-
please use channels_meta instead.
|
|
1004
|
-
pixel_size (PixelSize | None): Deprecated. The pixel size of the new label.
|
|
1005
|
-
This argument is deprecated, please use pixelsize, z_spacing,
|
|
1006
|
-
and time_spacing instead.
|
|
705
|
+
name (str): The name of the new image.
|
|
706
|
+
ref_image (Image | Label | None): A reference image that will be used
|
|
707
|
+
to create the new image.
|
|
708
|
+
shape (Sequence[int] | None): The shape of the new image.
|
|
709
|
+
pixel_size (PixelSize | None): The pixel size of the new image.
|
|
710
|
+
axes_names (Sequence[str] | None): The axes names of the new image.
|
|
711
|
+
For labels, the channel axis is not allowed.
|
|
712
|
+
chunks (Sequence[int] | None): The chunk shape of the new image.
|
|
713
|
+
dtype (str): The data type of the new label.
|
|
714
|
+
dimension_separator (DIMENSION_SEPARATOR | None): The dimension
|
|
715
|
+
separator to use. If None, the dimension separator of the
|
|
716
|
+
reference image will be used.
|
|
717
|
+
compressors (CompressorLike | None): The compressors to use. If None,
|
|
718
|
+
the compressors of the reference image will be used.
|
|
719
|
+
overwrite (bool): Whether to overwrite an existing image.
|
|
1007
720
|
|
|
1008
721
|
Returns:
|
|
1009
|
-
Label: The new
|
|
722
|
+
Label: The new label.
|
|
1010
723
|
|
|
1011
724
|
"""
|
|
1012
725
|
if ref_image is None:
|
|
@@ -1015,21 +728,13 @@ class OmeZarrContainer:
|
|
|
1015
728
|
name=name,
|
|
1016
729
|
ref_image=ref_image,
|
|
1017
730
|
shape=shape,
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
time_spacing=time_spacing,
|
|
1021
|
-
translation=translation,
|
|
1022
|
-
channels_policy=channels_policy,
|
|
1023
|
-
ngff_version=ngff_version,
|
|
731
|
+
pixel_size=pixel_size,
|
|
732
|
+
axes_names=axes_names,
|
|
1024
733
|
chunks=chunks,
|
|
1025
|
-
shards=shards,
|
|
1026
734
|
dtype=dtype,
|
|
1027
735
|
dimension_separator=dimension_separator,
|
|
1028
736
|
compressors=compressors,
|
|
1029
|
-
extra_array_kwargs=extra_array_kwargs,
|
|
1030
737
|
overwrite=overwrite,
|
|
1031
|
-
labels=labels,
|
|
1032
|
-
pixel_size=pixel_size,
|
|
1033
738
|
)
|
|
1034
739
|
|
|
1035
740
|
|
|
@@ -1037,7 +742,6 @@ def open_ome_zarr_container(
|
|
|
1037
742
|
store: StoreOrGroup,
|
|
1038
743
|
cache: bool = False,
|
|
1039
744
|
mode: AccessModeLiteral = "r+",
|
|
1040
|
-
axes_setup: AxesSetup | None = None,
|
|
1041
745
|
validate_arrays: bool = True,
|
|
1042
746
|
) -> OmeZarrContainer:
|
|
1043
747
|
"""Open an OME-Zarr image."""
|
|
@@ -1045,7 +749,6 @@ def open_ome_zarr_container(
|
|
|
1045
749
|
return OmeZarrContainer(
|
|
1046
750
|
group_handler=handler,
|
|
1047
751
|
validate_paths=validate_arrays,
|
|
1048
|
-
axes_setup=axes_setup,
|
|
1049
752
|
)
|
|
1050
753
|
|
|
1051
754
|
|
|
@@ -1054,7 +757,6 @@ def open_image(
|
|
|
1054
757
|
path: str | None = None,
|
|
1055
758
|
pixel_size: PixelSize | None = None,
|
|
1056
759
|
strict: bool = True,
|
|
1057
|
-
axes_setup: AxesSetup | None = None,
|
|
1058
760
|
cache: bool = False,
|
|
1059
761
|
mode: AccessModeLiteral = "r+",
|
|
1060
762
|
) -> Image:
|
|
@@ -1067,14 +769,12 @@ def open_image(
|
|
|
1067
769
|
strict (bool): Only used if the pixel size is provided. If True, the
|
|
1068
770
|
pixel size must match the image pixel size exactly. If False, the
|
|
1069
771
|
closest pixel size level will be returned.
|
|
1070
|
-
axes_setup (AxesSetup | None): Axes setup to load ome-zarr with
|
|
1071
|
-
non-standard axes configurations.
|
|
1072
772
|
cache (bool): Whether to use a cache for the zarr group metadata.
|
|
1073
773
|
mode (AccessModeLiteral): The
|
|
1074
774
|
access mode for the image. Defaults to "r+".
|
|
1075
775
|
"""
|
|
1076
776
|
group_handler = ZarrGroupHandler(store=store, cache=cache, mode=mode)
|
|
1077
|
-
images_container = ImagesContainer(group_handler
|
|
777
|
+
images_container = ImagesContainer(group_handler)
|
|
1078
778
|
return images_container.get(
|
|
1079
779
|
path=path,
|
|
1080
780
|
pixel_size=pixel_size,
|
|
@@ -1088,7 +788,6 @@ def open_label(
|
|
|
1088
788
|
path: str | None = None,
|
|
1089
789
|
pixel_size: PixelSize | None = None,
|
|
1090
790
|
strict: bool = True,
|
|
1091
|
-
axes_setup: AxesSetup | None = None,
|
|
1092
791
|
cache: bool = False,
|
|
1093
792
|
mode: AccessModeLiteral = "r+",
|
|
1094
793
|
) -> Label:
|
|
@@ -1103,23 +802,19 @@ def open_label(
|
|
|
1103
802
|
strict (bool): Only used if the pixel size is provided. If True, the
|
|
1104
803
|
pixel size must match the image pixel size exactly. If False, the
|
|
1105
804
|
closest pixel size level will be returned.
|
|
1106
|
-
axes_setup (AxesSetup | None): Axes setup to load ome-zarr with
|
|
1107
|
-
non-standard axes configurations.
|
|
1108
805
|
cache (bool): Whether to use a cache for the zarr group metadata.
|
|
1109
806
|
mode (AccessModeLiteral): The access mode for the image. Defaults to "r+".
|
|
1110
807
|
|
|
1111
808
|
"""
|
|
1112
809
|
group_handler = ZarrGroupHandler(store=store, cache=cache, mode=mode)
|
|
1113
810
|
if name is None:
|
|
1114
|
-
label_meta_handler =
|
|
1115
|
-
path = (
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
.path
|
|
1119
|
-
)
|
|
811
|
+
label_meta_handler = find_label_meta_handler(group_handler)
|
|
812
|
+
path = label_meta_handler.meta.get_dataset(
|
|
813
|
+
path=path, pixel_size=pixel_size, strict=strict
|
|
814
|
+
).path
|
|
1120
815
|
return Label(group_handler, path, label_meta_handler)
|
|
1121
816
|
|
|
1122
|
-
labels_container = LabelsContainer(group_handler
|
|
817
|
+
labels_container = LabelsContainer(group_handler)
|
|
1123
818
|
return labels_container.get(
|
|
1124
819
|
name=name,
|
|
1125
820
|
path=path,
|
|
@@ -1131,294 +826,196 @@ def open_label(
|
|
|
1131
826
|
def create_empty_ome_zarr(
|
|
1132
827
|
store: StoreOrGroup,
|
|
1133
828
|
shape: Sequence[int],
|
|
1134
|
-
|
|
829
|
+
xy_pixelsize: float,
|
|
1135
830
|
z_spacing: float = 1.0,
|
|
1136
831
|
time_spacing: float = 1.0,
|
|
1137
|
-
scaling_factors: Sequence[float] | Literal["auto"] = "auto",
|
|
1138
832
|
levels: int | list[str] = 5,
|
|
1139
|
-
|
|
833
|
+
xy_scaling_factor: float = 2,
|
|
834
|
+
z_scaling_factor: float = 1.0,
|
|
1140
835
|
space_unit: SpaceUnits = DefaultSpaceUnit,
|
|
1141
836
|
time_unit: TimeUnits = DefaultTimeUnit,
|
|
1142
837
|
axes_names: Sequence[str] | None = None,
|
|
1143
|
-
channels_meta: Sequence[str | Channel] | None = None,
|
|
1144
838
|
name: str | None = None,
|
|
1145
|
-
|
|
1146
|
-
ngff_version: NgffVersions = DefaultNgffVersion,
|
|
1147
|
-
chunks: ChunksLike = "auto",
|
|
1148
|
-
shards: ShardsLike | None = None,
|
|
839
|
+
chunks: Sequence[int] | Literal["auto"] = "auto",
|
|
1149
840
|
dtype: str = "uint16",
|
|
1150
841
|
dimension_separator: Literal[".", "/"] = "/",
|
|
1151
842
|
compressors: CompressorLike = "auto",
|
|
1152
|
-
extra_array_kwargs: Mapping[str, Any] | None = None,
|
|
1153
|
-
overwrite: bool = False,
|
|
1154
|
-
# Deprecated arguments
|
|
1155
|
-
xy_pixelsize: float | None = None,
|
|
1156
|
-
xy_scaling_factor: float | None = None,
|
|
1157
|
-
z_scaling_factor: float | None = None,
|
|
1158
843
|
channel_labels: list[str] | None = None,
|
|
1159
844
|
channel_wavelengths: list[str] | None = None,
|
|
1160
845
|
channel_colors: Sequence[str] | None = None,
|
|
1161
846
|
channel_active: Sequence[bool] | None = None,
|
|
847
|
+
overwrite: bool = False,
|
|
848
|
+
version: NgffVersions = DefaultNgffVersion,
|
|
1162
849
|
) -> OmeZarrContainer:
|
|
1163
850
|
"""Create an empty OME-Zarr image with the given shape and metadata.
|
|
1164
851
|
|
|
1165
852
|
Args:
|
|
1166
853
|
store (StoreOrGroup): The Zarr store or group to create the image in.
|
|
1167
854
|
shape (Sequence[int]): The shape of the image.
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
space_unit (SpaceUnits): The unit of space. Defaults to
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
855
|
+
xy_pixelsize (float): The pixel size in x and y dimensions.
|
|
856
|
+
z_spacing (float, optional): The spacing between z slices. Defaults to 1.0.
|
|
857
|
+
time_spacing (float, optional): The spacing between time points.
|
|
858
|
+
Defaults to 1.0.
|
|
859
|
+
levels (int | list[str], optional): The number of levels in the pyramid or a
|
|
860
|
+
list of level names. Defaults to 5.
|
|
861
|
+
xy_scaling_factor (float, optional): The down-scaling factor in x and y
|
|
862
|
+
dimensions. Defaults to 2.0.
|
|
863
|
+
z_scaling_factor (float, optional): The down-scaling factor in z dimension.
|
|
864
|
+
Defaults to 1.0.
|
|
865
|
+
space_unit (SpaceUnits, optional): The unit of space. Defaults to
|
|
866
|
+
DefaultSpaceUnit.
|
|
867
|
+
time_unit (TimeUnits, optional): The unit of time. Defaults to
|
|
868
|
+
DefaultTimeUnit.
|
|
869
|
+
axes_names (Sequence[str] | None, optional): The names of the axes.
|
|
870
|
+
If None the canonical names are used. Defaults to None.
|
|
871
|
+
name (str | None, optional): The name of the image. Defaults to None.
|
|
872
|
+
chunks (Sequence[int] | None, optional): The chunk shape. If None the shape
|
|
873
|
+
is used. Defaults to None.
|
|
874
|
+
dtype (str, optional): The data type of the image. Defaults to "uint16".
|
|
875
|
+
dimension_separator (DIMENSION_SEPARATOR): The dimension
|
|
876
|
+
separator to use. Defaults to "/".
|
|
877
|
+
compressors (CompressorLike): The compressor to use. Defaults to "auto".
|
|
878
|
+
channel_labels (list[str] | None, optional): The labels of the channels.
|
|
1183
879
|
Defaults to None.
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
880
|
+
channel_wavelengths (list[str] | None, optional): The wavelengths of the
|
|
881
|
+
channels. Defaults to None.
|
|
882
|
+
channel_colors (Sequence[str] | None, optional): The colors of the channels.
|
|
883
|
+
Defaults to None.
|
|
884
|
+
channel_active (Sequence[bool] | None, optional): Whether the channels are
|
|
885
|
+
active. Defaults to None.
|
|
886
|
+
overwrite (bool, optional): Whether to overwrite an existing image.
|
|
887
|
+
Defaults to True.
|
|
888
|
+
version (NgffVersion, optional): The version of the OME-Zarr specification.
|
|
1188
889
|
Defaults to DefaultNgffVersion.
|
|
1189
|
-
chunks (ChunksLike): The chunk shape. Defaults to "auto".
|
|
1190
|
-
shards (ShardsLike | None): The shard shape. Defaults to None.
|
|
1191
|
-
dtype (str): The data type of the image. Defaults to "uint16".
|
|
1192
|
-
dimension_separator (Literal[".", "/"]): The dimension separator to use.
|
|
1193
|
-
Defaults to "/".
|
|
1194
|
-
compressors (CompressorLike): The compressor to use. Defaults to "auto".
|
|
1195
|
-
extra_array_kwargs (Mapping[str, Any] | None): Extra arguments to pass to
|
|
1196
|
-
the zarr array creation. Defaults to None.
|
|
1197
|
-
overwrite (bool): Whether to overwrite an existing image. Defaults to False.
|
|
1198
|
-
xy_pixelsize (float | None): Deprecated. Use pixelsize instead.
|
|
1199
|
-
xy_scaling_factor (float | None): Deprecated. Use scaling_factors instead.
|
|
1200
|
-
z_scaling_factor (float | None): Deprecated. Use scaling_factors instead.
|
|
1201
|
-
channel_labels (list[str] | None): Deprecated. Use channels_meta instead.
|
|
1202
|
-
channel_wavelengths (list[str] | None): Deprecated. Use channels_meta instead.
|
|
1203
|
-
channel_colors (Sequence[str] | None): Deprecated. Use channels_meta instead.
|
|
1204
|
-
channel_active (Sequence[bool] | None): Deprecated. Use channels_meta instead.
|
|
1205
890
|
"""
|
|
1206
|
-
|
|
1207
|
-
warnings.warn(
|
|
1208
|
-
"'xy_pixelsize' is deprecated and will be removed in ngio=0.6. "
|
|
1209
|
-
"Please use 'pixelsize' instead.",
|
|
1210
|
-
DeprecationWarning,
|
|
1211
|
-
stacklevel=2,
|
|
1212
|
-
)
|
|
1213
|
-
pixelsize = xy_pixelsize
|
|
1214
|
-
if xy_scaling_factor is not None or z_scaling_factor is not None:
|
|
1215
|
-
warnings.warn(
|
|
1216
|
-
"'xy_scaling_factor' and 'z_scaling_factor' are deprecated and will be "
|
|
1217
|
-
"removed in ngio=0.6. Please use 'scaling_factors' instead.",
|
|
1218
|
-
DeprecationWarning,
|
|
1219
|
-
stacklevel=2,
|
|
1220
|
-
)
|
|
1221
|
-
xy_scaling_factor_ = xy_scaling_factor or 2.0
|
|
1222
|
-
z_scaling_factor_ = z_scaling_factor or 1.0
|
|
1223
|
-
if len(shape) == 2:
|
|
1224
|
-
scaling_factors = (xy_scaling_factor_, xy_scaling_factor_)
|
|
1225
|
-
else:
|
|
1226
|
-
zyx_factors = (z_scaling_factor_, xy_scaling_factor_, xy_scaling_factor_)
|
|
1227
|
-
scaling_factors = (1.0,) * (len(shape) - 3) + zyx_factors
|
|
1228
|
-
|
|
1229
|
-
if channel_labels is not None:
|
|
1230
|
-
warnings.warn(
|
|
1231
|
-
"'channel_labels' is deprecated and will be removed in ngio=0.6. "
|
|
1232
|
-
"Please use 'channels_meta' instead.",
|
|
1233
|
-
DeprecationWarning,
|
|
1234
|
-
stacklevel=2,
|
|
1235
|
-
)
|
|
1236
|
-
channels_meta = channel_labels
|
|
1237
|
-
|
|
1238
|
-
if channel_wavelengths is not None:
|
|
1239
|
-
warnings.warn(
|
|
1240
|
-
"'channel_wavelengths' is deprecated and will be removed in ngio=0.6. "
|
|
1241
|
-
"Please use 'channels_meta' instead.",
|
|
1242
|
-
DeprecationWarning,
|
|
1243
|
-
stacklevel=2,
|
|
1244
|
-
)
|
|
1245
|
-
if channel_colors is not None:
|
|
1246
|
-
warnings.warn(
|
|
1247
|
-
"'channel_colors' is deprecated and will be removed in ngio=0.6. "
|
|
1248
|
-
"Please use 'channels_meta' instead.",
|
|
1249
|
-
DeprecationWarning,
|
|
1250
|
-
stacklevel=2,
|
|
1251
|
-
)
|
|
1252
|
-
if channel_active is not None:
|
|
1253
|
-
warnings.warn(
|
|
1254
|
-
"'channel_active' is deprecated and will be removed in ngio=0.6. "
|
|
1255
|
-
"Please use 'channels_meta' instead.",
|
|
1256
|
-
DeprecationWarning,
|
|
1257
|
-
stacklevel=2,
|
|
1258
|
-
)
|
|
1259
|
-
|
|
1260
|
-
if pixelsize is None:
|
|
1261
|
-
raise NgioValueError("pixelsize must be provided.")
|
|
1262
|
-
|
|
1263
|
-
handler, axes_setup = init_image_like(
|
|
891
|
+
handler = create_empty_image_container(
|
|
1264
892
|
store=store,
|
|
1265
|
-
meta_type=NgioImageMeta,
|
|
1266
893
|
shape=shape,
|
|
1267
|
-
pixelsize=
|
|
894
|
+
pixelsize=xy_pixelsize,
|
|
1268
895
|
z_spacing=z_spacing,
|
|
1269
896
|
time_spacing=time_spacing,
|
|
1270
|
-
scaling_factors=scaling_factors,
|
|
1271
897
|
levels=levels,
|
|
1272
|
-
|
|
898
|
+
yx_scaling_factor=xy_scaling_factor,
|
|
899
|
+
z_scaling_factor=z_scaling_factor,
|
|
1273
900
|
space_unit=space_unit,
|
|
1274
901
|
time_unit=time_unit,
|
|
1275
902
|
axes_names=axes_names,
|
|
1276
|
-
channels_meta=channels_meta,
|
|
1277
903
|
name=name,
|
|
1278
|
-
axes_setup=axes_setup,
|
|
1279
|
-
ngff_version=ngff_version,
|
|
1280
904
|
chunks=chunks,
|
|
1281
|
-
shards=shards,
|
|
1282
905
|
dtype=dtype,
|
|
1283
906
|
dimension_separator=dimension_separator,
|
|
1284
907
|
compressors=compressors,
|
|
1285
|
-
extra_array_kwargs=extra_array_kwargs,
|
|
1286
908
|
overwrite=overwrite,
|
|
909
|
+
version=version,
|
|
1287
910
|
)
|
|
1288
911
|
|
|
1289
|
-
ome_zarr = OmeZarrContainer(group_handler=handler
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
labels=channel_names,
|
|
1298
|
-
wavelength_id=channel_wavelengths,
|
|
1299
|
-
percentiles=None,
|
|
1300
|
-
colors=channel_colors,
|
|
1301
|
-
active=channel_active,
|
|
1302
|
-
)
|
|
1303
|
-
else:
|
|
1304
|
-
ome_zarr.set_channel_meta(
|
|
1305
|
-
labels=ome_zarr.channel_labels,
|
|
1306
|
-
percentiles=None,
|
|
1307
|
-
)
|
|
912
|
+
ome_zarr = OmeZarrContainer(group_handler=handler)
|
|
913
|
+
ome_zarr.set_channel_meta(
|
|
914
|
+
labels=channel_labels,
|
|
915
|
+
wavelength_id=channel_wavelengths,
|
|
916
|
+
percentiles=None,
|
|
917
|
+
colors=channel_colors,
|
|
918
|
+
active=channel_active,
|
|
919
|
+
)
|
|
1308
920
|
return ome_zarr
|
|
1309
921
|
|
|
1310
922
|
|
|
1311
923
|
def create_ome_zarr_from_array(
|
|
1312
924
|
store: StoreOrGroup,
|
|
1313
925
|
array: np.ndarray,
|
|
1314
|
-
|
|
926
|
+
xy_pixelsize: float,
|
|
1315
927
|
z_spacing: float = 1.0,
|
|
1316
928
|
time_spacing: float = 1.0,
|
|
1317
|
-
scaling_factors: Sequence[float] | Literal["auto"] = "auto",
|
|
1318
929
|
levels: int | list[str] = 5,
|
|
1319
|
-
|
|
930
|
+
xy_scaling_factor: float = 2.0,
|
|
931
|
+
z_scaling_factor: float = 1.0,
|
|
1320
932
|
space_unit: SpaceUnits = DefaultSpaceUnit,
|
|
1321
933
|
time_unit: TimeUnits = DefaultTimeUnit,
|
|
1322
934
|
axes_names: Sequence[str] | None = None,
|
|
1323
|
-
channels_meta: Sequence[str | Channel] | None = None,
|
|
1324
|
-
percentiles: tuple[float, float] = (0.1, 99.9),
|
|
1325
|
-
name: str | None = None,
|
|
1326
|
-
axes_setup: AxesSetup | None = None,
|
|
1327
|
-
ngff_version: NgffVersions = DefaultNgffVersion,
|
|
1328
|
-
chunks: ChunksLike = "auto",
|
|
1329
|
-
shards: ShardsLike | None = None,
|
|
1330
|
-
dimension_separator: Literal[".", "/"] = "/",
|
|
1331
|
-
compressors: CompressorLike = "auto",
|
|
1332
|
-
extra_array_kwargs: Mapping[str, Any] | None = None,
|
|
1333
|
-
overwrite: bool = False,
|
|
1334
|
-
# Deprecated arguments
|
|
1335
|
-
xy_pixelsize: float | None = None,
|
|
1336
|
-
xy_scaling_factor: float | None = None,
|
|
1337
|
-
z_scaling_factor: float | None = None,
|
|
1338
935
|
channel_labels: list[str] | None = None,
|
|
1339
936
|
channel_wavelengths: list[str] | None = None,
|
|
937
|
+
percentiles: tuple[float, float] | None = (0.1, 99.9),
|
|
1340
938
|
channel_colors: Sequence[str] | None = None,
|
|
1341
939
|
channel_active: Sequence[bool] | None = None,
|
|
940
|
+
name: str | None = None,
|
|
941
|
+
chunks: Sequence[int] | Literal["auto"] = "auto",
|
|
942
|
+
dimension_separator: Literal[".", "/"] = "/",
|
|
943
|
+
compressors: CompressorLike = "auto",
|
|
944
|
+
overwrite: bool = False,
|
|
945
|
+
version: NgffVersions = DefaultNgffVersion,
|
|
1342
946
|
) -> OmeZarrContainer:
|
|
1343
947
|
"""Create an OME-Zarr image from a numpy array.
|
|
1344
948
|
|
|
1345
949
|
Args:
|
|
1346
950
|
store (StoreOrGroup): The Zarr store or group to create the image in.
|
|
1347
951
|
array (np.ndarray): The image data.
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
space_unit (SpaceUnits): The unit of space. Defaults to
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
952
|
+
xy_pixelsize (float): The pixel size in x and y dimensions.
|
|
953
|
+
z_spacing (float, optional): The spacing between z slices. Defaults to 1.0.
|
|
954
|
+
time_spacing (float, optional): The spacing between time points.
|
|
955
|
+
Defaults to 1.0.
|
|
956
|
+
levels (int | list[str], optional): The number of levels in the pyramid or a
|
|
957
|
+
list of level names. Defaults to 5.
|
|
958
|
+
xy_scaling_factor (float, optional): The down-scaling factor in x and y
|
|
959
|
+
dimensions. Defaults to 2.0.
|
|
960
|
+
z_scaling_factor (float, optional): The down-scaling factor in z dimension.
|
|
961
|
+
Defaults to 1.0.
|
|
962
|
+
space_unit (SpaceUnits, optional): The unit of space. Defaults to
|
|
963
|
+
DefaultSpaceUnit.
|
|
964
|
+
time_unit (TimeUnits, optional): The unit of time. Defaults to
|
|
965
|
+
DefaultTimeUnit.
|
|
966
|
+
axes_names (Sequence[str] | None, optional): The names of the axes.
|
|
967
|
+
If None the canonical names are used. Defaults to None.
|
|
968
|
+
name (str | None, optional): The name of the image. Defaults to None.
|
|
969
|
+
chunks (Sequence[int] | None, optional): The chunk shape. If None the shape
|
|
970
|
+
is used. Defaults to None.
|
|
971
|
+
channel_labels (list[str] | None, optional): The labels of the channels.
|
|
1363
972
|
Defaults to None.
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
dimension_separator (Literal[".", "/"]): The separator to use for
|
|
973
|
+
channel_wavelengths (list[str] | None, optional): The wavelengths of the
|
|
974
|
+
channels. Defaults to None.
|
|
975
|
+
percentiles (tuple[float, float] | None, optional): The percentiles of the
|
|
976
|
+
channels. Defaults to None.
|
|
977
|
+
channel_colors (Sequence[str] | None, optional): The colors of the channels.
|
|
978
|
+
Defaults to None.
|
|
979
|
+
channel_active (Sequence[bool] | None, optional): Whether the channels are
|
|
980
|
+
active. Defaults to None.
|
|
981
|
+
dimension_separator (DIMENSION_SEPARATOR): The separator to use for
|
|
1374
982
|
dimensions. Defaults to "/".
|
|
1375
983
|
compressors (CompressorLike): The compressors to use. Defaults to "auto".
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
xy_scaling_factor (float | None): Deprecated. Use scaling_factors instead.
|
|
1381
|
-
z_scaling_factor (float | None): Deprecated. Use scaling_factors instead.
|
|
1382
|
-
channel_labels (list[str] | None): Deprecated. Use channels_meta instead.
|
|
1383
|
-
channel_wavelengths (list[str] | None): Deprecated. Use channels_meta instead.
|
|
1384
|
-
channel_colors (Sequence[str] | None): Deprecated. Use channels_meta instead.
|
|
1385
|
-
channel_active (Sequence[bool] | None): Deprecated. Use channels_meta instead.
|
|
984
|
+
overwrite (bool, optional): Whether to overwrite an existing image.
|
|
985
|
+
Defaults to True.
|
|
986
|
+
version (str, optional): The version of the OME-Zarr specification.
|
|
987
|
+
Defaults to DefaultNgffVersion.
|
|
1386
988
|
"""
|
|
1387
|
-
|
|
989
|
+
handler = create_empty_image_container(
|
|
1388
990
|
store=store,
|
|
1389
991
|
shape=array.shape,
|
|
1390
|
-
pixelsize=
|
|
992
|
+
pixelsize=xy_pixelsize,
|
|
1391
993
|
z_spacing=z_spacing,
|
|
1392
994
|
time_spacing=time_spacing,
|
|
1393
|
-
scaling_factors=scaling_factors,
|
|
1394
995
|
levels=levels,
|
|
1395
|
-
|
|
996
|
+
yx_scaling_factor=xy_scaling_factor,
|
|
997
|
+
z_scaling_factor=z_scaling_factor,
|
|
1396
998
|
space_unit=space_unit,
|
|
1397
999
|
time_unit=time_unit,
|
|
1398
1000
|
axes_names=axes_names,
|
|
1399
|
-
channels_meta=channels_meta,
|
|
1400
1001
|
name=name,
|
|
1401
|
-
ngff_version=ngff_version,
|
|
1402
1002
|
chunks=chunks,
|
|
1403
|
-
|
|
1003
|
+
dtype=str(array.dtype),
|
|
1004
|
+
overwrite=overwrite,
|
|
1404
1005
|
dimension_separator=dimension_separator,
|
|
1405
1006
|
compressors=compressors,
|
|
1406
|
-
|
|
1407
|
-
overwrite=overwrite,
|
|
1408
|
-
xy_pixelsize=xy_pixelsize,
|
|
1409
|
-
xy_scaling_factor=xy_scaling_factor,
|
|
1410
|
-
z_scaling_factor=z_scaling_factor,
|
|
1411
|
-
channel_labels=channel_labels,
|
|
1412
|
-
channel_wavelengths=channel_wavelengths,
|
|
1413
|
-
channel_colors=channel_colors,
|
|
1414
|
-
channel_active=channel_active,
|
|
1007
|
+
version=version,
|
|
1415
1008
|
)
|
|
1009
|
+
|
|
1010
|
+
ome_zarr = OmeZarrContainer(group_handler=handler)
|
|
1416
1011
|
image = ome_zarr.get_image()
|
|
1417
1012
|
image.set_array(array)
|
|
1418
1013
|
image.consolidate()
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1014
|
+
ome_zarr.set_channel_meta(
|
|
1015
|
+
labels=channel_labels,
|
|
1016
|
+
wavelength_id=channel_wavelengths,
|
|
1017
|
+
percentiles=percentiles,
|
|
1018
|
+
colors=channel_colors,
|
|
1019
|
+
active=channel_active,
|
|
1020
|
+
)
|
|
1424
1021
|
return ome_zarr
|