ngio 0.3.4__py3-none-any.whl → 0.4.0__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 +7 -2
- ngio/common/__init__.py +5 -52
- ngio/common/_dimensions.py +270 -55
- ngio/common/_masking_roi.py +38 -10
- ngio/common/_pyramid.py +51 -30
- ngio/common/_roi.py +269 -82
- ngio/common/_synt_images_utils.py +101 -0
- ngio/common/_zoom.py +49 -19
- ngio/experimental/__init__.py +5 -0
- ngio/experimental/iterators/__init__.py +15 -0
- ngio/experimental/iterators/_abstract_iterator.py +390 -0
- ngio/experimental/iterators/_feature.py +189 -0
- ngio/experimental/iterators/_image_processing.py +130 -0
- ngio/experimental/iterators/_mappers.py +48 -0
- ngio/experimental/iterators/_rois_utils.py +127 -0
- ngio/experimental/iterators/_segmentation.py +235 -0
- ngio/hcs/_plate.py +41 -36
- ngio/images/__init__.py +22 -1
- ngio/images/_abstract_image.py +403 -176
- ngio/images/_create.py +31 -15
- ngio/images/_create_synt_container.py +138 -0
- ngio/images/_image.py +452 -63
- ngio/images/_label.py +56 -30
- ngio/images/_masked_image.py +387 -129
- ngio/images/_ome_zarr_container.py +237 -67
- ngio/{common → images}/_table_ops.py +41 -41
- ngio/io_pipes/__init__.py +75 -0
- ngio/io_pipes/_io_pipes.py +361 -0
- ngio/io_pipes/_io_pipes_masked.py +488 -0
- ngio/io_pipes/_io_pipes_roi.py +152 -0
- ngio/io_pipes/_io_pipes_types.py +56 -0
- ngio/io_pipes/_match_shape.py +376 -0
- ngio/io_pipes/_ops_axes.py +344 -0
- ngio/io_pipes/_ops_slices.py +446 -0
- ngio/io_pipes/_ops_slices_utils.py +196 -0
- ngio/io_pipes/_ops_transforms.py +104 -0
- ngio/io_pipes/_zoom_transform.py +175 -0
- ngio/ome_zarr_meta/__init__.py +4 -2
- ngio/ome_zarr_meta/ngio_specs/__init__.py +4 -10
- ngio/ome_zarr_meta/ngio_specs/_axes.py +186 -175
- ngio/ome_zarr_meta/ngio_specs/_channels.py +55 -18
- ngio/ome_zarr_meta/ngio_specs/_dataset.py +48 -122
- ngio/ome_zarr_meta/ngio_specs/_ngio_hcs.py +6 -15
- ngio/ome_zarr_meta/ngio_specs/_ngio_image.py +38 -87
- ngio/ome_zarr_meta/ngio_specs/_pixel_size.py +17 -1
- ngio/ome_zarr_meta/v04/_v04_spec_utils.py +34 -31
- ngio/resources/20200812-CardiomyocyteDifferentiation14-Cycle1_B03/mask.png +0 -0
- ngio/resources/20200812-CardiomyocyteDifferentiation14-Cycle1_B03/nuclei.png +0 -0
- ngio/resources/20200812-CardiomyocyteDifferentiation14-Cycle1_B03/raw.jpg +0 -0
- ngio/resources/__init__.py +55 -0
- ngio/resources/resource_model.py +36 -0
- ngio/tables/backends/_abstract_backend.py +5 -6
- ngio/tables/backends/_anndata.py +1 -2
- ngio/tables/backends/_anndata_utils.py +3 -3
- ngio/tables/backends/_non_zarr_backends.py +1 -1
- ngio/tables/backends/_table_backends.py +0 -1
- ngio/tables/backends/_utils.py +3 -3
- ngio/tables/v1/_roi_table.py +165 -70
- ngio/transforms/__init__.py +5 -0
- ngio/transforms/_zoom.py +19 -0
- ngio/utils/__init__.py +2 -3
- ngio/utils/_datasets.py +5 -0
- ngio/utils/_logger.py +19 -0
- ngio/utils/_zarr_utils.py +6 -6
- {ngio-0.3.4.dist-info → ngio-0.4.0.dist-info}/METADATA +24 -22
- ngio-0.4.0.dist-info/RECORD +85 -0
- ngio/common/_array_pipe.py +0 -288
- ngio/common/_axes_transforms.py +0 -64
- ngio/common/_common_types.py +0 -5
- ngio/common/_slicer.py +0 -96
- ngio-0.3.4.dist-info/RECORD +0 -61
- {ngio-0.3.4.dist-info → ngio-0.4.0.dist-info}/WHEEL +0 -0
- {ngio-0.3.4.dist-info → ngio-0.4.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
"""Abstract class for handling OME-NGFF images."""
|
|
2
2
|
|
|
3
3
|
import warnings
|
|
4
|
-
from collections.abc import
|
|
4
|
+
from collections.abc import Sequence
|
|
5
5
|
|
|
6
6
|
import numpy as np
|
|
7
|
+
from zarr.types import DIMENSION_SEPARATOR
|
|
7
8
|
|
|
8
9
|
from ngio.images._create import create_empty_image_container
|
|
9
10
|
from ngio.images._image import Image, ImagesContainer
|
|
10
11
|
from ngio.images._label import Label, LabelsContainer
|
|
11
12
|
from ngio.images._masked_image import MaskedImage, MaskedLabel
|
|
12
|
-
from ngio.ome_zarr_meta import
|
|
13
|
-
NgioImageMeta,
|
|
14
|
-
PixelSize,
|
|
15
|
-
)
|
|
13
|
+
from ngio.ome_zarr_meta import NgioImageMeta, PixelSize, find_label_meta_handler
|
|
16
14
|
from ngio.ome_zarr_meta.ngio_specs import (
|
|
17
15
|
DefaultNgffVersion,
|
|
18
16
|
DefaultSpaceUnit,
|
|
@@ -58,7 +56,21 @@ def _default_label_container(handler: ZarrGroupHandler) -> LabelsContainer | Non
|
|
|
58
56
|
|
|
59
57
|
|
|
60
58
|
class OmeZarrContainer:
|
|
61
|
-
"""This class
|
|
59
|
+
"""This class is an object representation of an OME-Zarr image.
|
|
60
|
+
|
|
61
|
+
It provides methods to access:
|
|
62
|
+
- The multiscale image metadata
|
|
63
|
+
- To open images at different levels of resolution
|
|
64
|
+
- To access labels and tables associated with the image.
|
|
65
|
+
- To derive new images, labels, and add tables to the image.
|
|
66
|
+
- To modify the image metadata, such as axes units and channel metadata.
|
|
67
|
+
|
|
68
|
+
Attributes:
|
|
69
|
+
images_container (ImagesContainer): The container for the images.
|
|
70
|
+
labels_container (LabelsContainer): The container for the labels.
|
|
71
|
+
tables_container (TablesContainer): The container for the tables.
|
|
72
|
+
|
|
73
|
+
"""
|
|
62
74
|
|
|
63
75
|
_images_container: ImagesContainer
|
|
64
76
|
_labels_container: LabelsContainer | None
|
|
@@ -71,7 +83,14 @@ class OmeZarrContainer:
|
|
|
71
83
|
label_container: LabelsContainer | None = None,
|
|
72
84
|
validate_paths: bool = False,
|
|
73
85
|
) -> None:
|
|
74
|
-
"""Initialize the OmeZarrContainer.
|
|
86
|
+
"""Initialize the OmeZarrContainer.
|
|
87
|
+
|
|
88
|
+
Args:
|
|
89
|
+
group_handler (ZarrGroupHandler): The Zarr group handler.
|
|
90
|
+
table_container (TablesContainer | None): The tables container.
|
|
91
|
+
label_container (LabelsContainer | None): The labels container.
|
|
92
|
+
validate_paths (bool): Whether to validate the paths of the image multiscale
|
|
93
|
+
"""
|
|
75
94
|
self._group_handler = group_handler
|
|
76
95
|
self._images_container = ImagesContainer(self._group_handler)
|
|
77
96
|
|
|
@@ -101,7 +120,11 @@ class OmeZarrContainer:
|
|
|
101
120
|
|
|
102
121
|
@property
|
|
103
122
|
def images_container(self) -> ImagesContainer:
|
|
104
|
-
"""Return the
|
|
123
|
+
"""Return the images container.
|
|
124
|
+
|
|
125
|
+
Returns:
|
|
126
|
+
ImagesContainer: The images container.
|
|
127
|
+
"""
|
|
105
128
|
return self._images_container
|
|
106
129
|
|
|
107
130
|
def _get_labels_container(self) -> LabelsContainer | None:
|
|
@@ -193,19 +216,47 @@ class OmeZarrContainer:
|
|
|
193
216
|
"""Return the time unit of the image."""
|
|
194
217
|
return self.image_meta.time_unit
|
|
195
218
|
|
|
219
|
+
@property
|
|
220
|
+
def channel_labels(self) -> list[str]:
|
|
221
|
+
"""Return the channels of the image."""
|
|
222
|
+
image = self.get_image()
|
|
223
|
+
return image.channel_labels
|
|
224
|
+
|
|
225
|
+
@property
|
|
226
|
+
def wavelength_ids(self) -> list[str | None]:
|
|
227
|
+
"""Return the list of wavelength of the image."""
|
|
228
|
+
image = self.get_image()
|
|
229
|
+
return image.wavelength_ids
|
|
230
|
+
|
|
231
|
+
@property
|
|
232
|
+
def num_channels(self) -> int:
|
|
233
|
+
"""Return the number of channels."""
|
|
234
|
+
return len(self.channel_labels)
|
|
235
|
+
|
|
236
|
+
def get_channel_idx(
|
|
237
|
+
self, channel_label: str | None = None, wavelength_id: str | None = None
|
|
238
|
+
) -> int:
|
|
239
|
+
"""Get the index of a channel by its label or wavelength ID."""
|
|
240
|
+
image = self.get_image()
|
|
241
|
+
return image.channels_meta.get_channel_idx(
|
|
242
|
+
channel_label=channel_label, wavelength_id=wavelength_id
|
|
243
|
+
)
|
|
244
|
+
|
|
196
245
|
def set_channel_meta(
|
|
197
246
|
self,
|
|
198
|
-
labels:
|
|
199
|
-
wavelength_id:
|
|
247
|
+
labels: Sequence[str] | int | None = None,
|
|
248
|
+
wavelength_id: Sequence[str] | None = None,
|
|
200
249
|
percentiles: tuple[float, float] | None = None,
|
|
201
|
-
colors:
|
|
202
|
-
active:
|
|
250
|
+
colors: Sequence[str] | None = None,
|
|
251
|
+
active: Sequence[bool] | None = None,
|
|
203
252
|
**omero_kwargs: dict,
|
|
204
253
|
) -> None:
|
|
205
254
|
"""Create a ChannelsMeta object with the default unit."""
|
|
206
255
|
self._images_container.set_channel_meta(
|
|
207
256
|
labels=labels,
|
|
208
257
|
wavelength_id=wavelength_id,
|
|
258
|
+
start=None,
|
|
259
|
+
end=None,
|
|
209
260
|
percentiles=percentiles,
|
|
210
261
|
colors=colors,
|
|
211
262
|
active=active,
|
|
@@ -262,9 +313,57 @@ class OmeZarrContainer:
|
|
|
262
313
|
path=path, pixel_size=pixel_size, strict=strict
|
|
263
314
|
)
|
|
264
315
|
|
|
316
|
+
def _find_matching_masking_label(
|
|
317
|
+
self,
|
|
318
|
+
masking_label_name: str | None = None,
|
|
319
|
+
masking_table_name: str | None = None,
|
|
320
|
+
pixel_size: PixelSize | None = None,
|
|
321
|
+
) -> tuple[Label, MaskingRoiTable]:
|
|
322
|
+
if masking_label_name is not None and masking_table_name is not None:
|
|
323
|
+
# Both provided
|
|
324
|
+
masking_label = self.get_label(
|
|
325
|
+
name=masking_label_name, pixel_size=pixel_size, strict=False
|
|
326
|
+
)
|
|
327
|
+
masking_table = self.get_masking_roi_table(name=masking_table_name)
|
|
328
|
+
|
|
329
|
+
elif masking_label_name is not None and masking_table_name is None:
|
|
330
|
+
# Only the label provided
|
|
331
|
+
masking_label = self.get_label(
|
|
332
|
+
name=masking_label_name, pixel_size=pixel_size, strict=False
|
|
333
|
+
)
|
|
334
|
+
|
|
335
|
+
for table_name in self.list_roi_tables():
|
|
336
|
+
table = self.get_generic_roi_table(name=table_name)
|
|
337
|
+
if isinstance(table, MaskingRoiTable):
|
|
338
|
+
if table.reference_label == masking_label_name:
|
|
339
|
+
masking_table = table
|
|
340
|
+
break
|
|
341
|
+
else:
|
|
342
|
+
masking_table = masking_label.build_masking_roi_table()
|
|
343
|
+
|
|
344
|
+
elif masking_table_name is not None and masking_label_name is None:
|
|
345
|
+
# Only the table provided
|
|
346
|
+
masking_table = self.get_masking_roi_table(name=masking_table_name)
|
|
347
|
+
|
|
348
|
+
if masking_table.reference_label is None:
|
|
349
|
+
raise NgioValueError(
|
|
350
|
+
f"Masking table {masking_table_name} does not have a reference "
|
|
351
|
+
"label. Please provide the masking_label_name explicitly."
|
|
352
|
+
)
|
|
353
|
+
masking_label = self.get_label(
|
|
354
|
+
name=masking_table.reference_label,
|
|
355
|
+
pixel_size=pixel_size,
|
|
356
|
+
strict=False,
|
|
357
|
+
)
|
|
358
|
+
else:
|
|
359
|
+
raise NgioValueError(
|
|
360
|
+
"Neither masking_label_name nor masking_table_name were provided."
|
|
361
|
+
)
|
|
362
|
+
return masking_label, masking_table
|
|
363
|
+
|
|
265
364
|
def get_masked_image(
|
|
266
365
|
self,
|
|
267
|
-
masking_label_name: str,
|
|
366
|
+
masking_label_name: str | None = None,
|
|
268
367
|
masking_table_name: str | None = None,
|
|
269
368
|
path: str | None = None,
|
|
270
369
|
pixel_size: PixelSize | None = None,
|
|
@@ -273,26 +372,27 @@ class OmeZarrContainer:
|
|
|
273
372
|
"""Get a masked image at a specific level.
|
|
274
373
|
|
|
275
374
|
Args:
|
|
276
|
-
masking_label_name (str): The name of the label.
|
|
277
|
-
|
|
375
|
+
masking_label_name (str | None): The name of the masking label to use.
|
|
376
|
+
If None, the masking table must be provided.
|
|
377
|
+
masking_table_name (str | None): The name of the masking table to use.
|
|
378
|
+
If None, the masking label must be provided.
|
|
278
379
|
path (str | None): The path to the image in the ome_zarr file.
|
|
380
|
+
If None, the first level will be used.
|
|
279
381
|
pixel_size (PixelSize | None): The pixel size of the image.
|
|
382
|
+
This is only used if path is None.
|
|
280
383
|
strict (bool): Only used if the pixel size is provided. If True, the
|
|
281
384
|
pixel size must match the image pixel size exactly. If False, the
|
|
282
385
|
closest pixel size level will be returned.
|
|
283
386
|
"""
|
|
284
387
|
image = self.get_image(path=path, pixel_size=pixel_size, strict=strict)
|
|
285
|
-
masking_label = self.
|
|
286
|
-
|
|
388
|
+
masking_label, masking_table = self._find_matching_masking_label(
|
|
389
|
+
masking_label_name=masking_label_name,
|
|
390
|
+
masking_table_name=masking_table_name,
|
|
391
|
+
pixel_size=pixel_size,
|
|
287
392
|
)
|
|
288
|
-
if masking_table_name is None:
|
|
289
|
-
masking_table = masking_label.build_masking_roi_table()
|
|
290
|
-
else:
|
|
291
|
-
masking_table = self.get_masking_roi_table(name=masking_table_name)
|
|
292
|
-
|
|
293
393
|
return MaskedImage(
|
|
294
394
|
group_handler=image._group_handler,
|
|
295
|
-
path=
|
|
395
|
+
path=image.path,
|
|
296
396
|
meta_handler=image.meta_handler,
|
|
297
397
|
label=masking_label,
|
|
298
398
|
masking_roi_table=masking_table,
|
|
@@ -302,13 +402,15 @@ class OmeZarrContainer:
|
|
|
302
402
|
self,
|
|
303
403
|
store: StoreOrGroup,
|
|
304
404
|
ref_path: str | None = None,
|
|
305
|
-
shape:
|
|
306
|
-
labels:
|
|
405
|
+
shape: Sequence[int] | None = None,
|
|
406
|
+
labels: Sequence[str] | None = None,
|
|
307
407
|
pixel_size: PixelSize | None = None,
|
|
308
|
-
axes_names:
|
|
408
|
+
axes_names: Sequence[str] | None = None,
|
|
309
409
|
name: str | None = None,
|
|
310
|
-
chunks:
|
|
410
|
+
chunks: Sequence[int] | None = None,
|
|
311
411
|
dtype: str | None = None,
|
|
412
|
+
dimension_separator: DIMENSION_SEPARATOR | None = None,
|
|
413
|
+
compressor=None,
|
|
312
414
|
copy_labels: bool = False,
|
|
313
415
|
copy_tables: bool = False,
|
|
314
416
|
overwrite: bool = False,
|
|
@@ -319,13 +421,18 @@ class OmeZarrContainer:
|
|
|
319
421
|
store (StoreOrGroup): The Zarr store or group to create the image in.
|
|
320
422
|
ref_path (str | None): The path to the reference image in
|
|
321
423
|
the image container.
|
|
322
|
-
shape (
|
|
323
|
-
labels (
|
|
424
|
+
shape (Sequence[int] | None): The shape of the new image.
|
|
425
|
+
labels (Sequence[str] | None): The labels of the new image.
|
|
324
426
|
pixel_size (PixelSize | None): The pixel size of the new image.
|
|
325
|
-
axes_names (
|
|
326
|
-
chunks (
|
|
427
|
+
axes_names (Sequence[str] | None): The axes names of the new image.
|
|
428
|
+
chunks (Sequence[int] | None): The chunk shape of the new image.
|
|
327
429
|
dtype (str | None): The data type of the new image.
|
|
328
430
|
name (str | None): The name of the new image.
|
|
431
|
+
dimension_separator (DIMENSION_SEPARATOR | None): The dimension
|
|
432
|
+
separator to use. If None, the dimension separator of the
|
|
433
|
+
reference image will be used.
|
|
434
|
+
compressor: The compressor to use. If None, the compressor of the
|
|
435
|
+
reference image will be used.
|
|
329
436
|
copy_labels (bool): Whether to copy the labels from the reference image.
|
|
330
437
|
copy_tables (bool): Whether to copy the tables from the reference image.
|
|
331
438
|
overwrite (bool): Whether to overwrite an existing image.
|
|
@@ -344,6 +451,8 @@ class OmeZarrContainer:
|
|
|
344
451
|
name=name,
|
|
345
452
|
chunks=chunks,
|
|
346
453
|
dtype=dtype,
|
|
454
|
+
dimension_separator=dimension_separator,
|
|
455
|
+
compressor=compressor,
|
|
347
456
|
overwrite=overwrite,
|
|
348
457
|
)
|
|
349
458
|
|
|
@@ -490,7 +599,7 @@ class OmeZarrContainer:
|
|
|
490
599
|
backend=backend,
|
|
491
600
|
)
|
|
492
601
|
|
|
493
|
-
def build_image_roi_table(self, name: str = "image") -> RoiTable:
|
|
602
|
+
def build_image_roi_table(self, name: str | None = "image") -> RoiTable:
|
|
494
603
|
"""Compute the ROI table for an image."""
|
|
495
604
|
return self.get_image().build_image_roi_table(name=name)
|
|
496
605
|
|
|
@@ -541,7 +650,7 @@ class OmeZarrContainer:
|
|
|
541
650
|
def get_masked_label(
|
|
542
651
|
self,
|
|
543
652
|
label_name: str,
|
|
544
|
-
masking_label_name: str,
|
|
653
|
+
masking_label_name: str | None = None,
|
|
545
654
|
masking_table_name: str | None = None,
|
|
546
655
|
path: str | None = None,
|
|
547
656
|
pixel_size: PixelSize | None = None,
|
|
@@ -551,7 +660,7 @@ class OmeZarrContainer:
|
|
|
551
660
|
|
|
552
661
|
Args:
|
|
553
662
|
label_name (str): The name of the label.
|
|
554
|
-
masking_label_name (str): The name of the masking label.
|
|
663
|
+
masking_label_name (str | None): The name of the masking label.
|
|
555
664
|
masking_table_name (str | None): The name of the masking table.
|
|
556
665
|
path (str | None): The path to the image in the ome_zarr file.
|
|
557
666
|
pixel_size (PixelSize | None): The pixel size of the image.
|
|
@@ -562,14 +671,11 @@ class OmeZarrContainer:
|
|
|
562
671
|
label = self.get_label(
|
|
563
672
|
name=label_name, path=path, pixel_size=pixel_size, strict=strict
|
|
564
673
|
)
|
|
565
|
-
masking_label = self.
|
|
566
|
-
|
|
674
|
+
masking_label, masking_table = self._find_matching_masking_label(
|
|
675
|
+
masking_label_name=masking_label_name,
|
|
676
|
+
masking_table_name=masking_table_name,
|
|
677
|
+
pixel_size=pixel_size,
|
|
567
678
|
)
|
|
568
|
-
if masking_table_name is None:
|
|
569
|
-
masking_table = masking_label.build_masking_roi_table()
|
|
570
|
-
else:
|
|
571
|
-
masking_table = self.get_masking_roi_table(name=masking_table_name)
|
|
572
|
-
|
|
573
679
|
return MaskedLabel(
|
|
574
680
|
group_handler=label._group_handler,
|
|
575
681
|
path=label.path,
|
|
@@ -582,11 +688,13 @@ class OmeZarrContainer:
|
|
|
582
688
|
self,
|
|
583
689
|
name: str,
|
|
584
690
|
ref_image: Image | Label | None = None,
|
|
585
|
-
shape:
|
|
691
|
+
shape: Sequence[int] | None = None,
|
|
586
692
|
pixel_size: PixelSize | None = None,
|
|
587
|
-
axes_names:
|
|
588
|
-
chunks:
|
|
589
|
-
dtype: str
|
|
693
|
+
axes_names: Sequence[str] | None = None,
|
|
694
|
+
chunks: Sequence[int] | None = None,
|
|
695
|
+
dtype: str = "uint32",
|
|
696
|
+
dimension_separator: DIMENSION_SEPARATOR | None = None,
|
|
697
|
+
compressor=None,
|
|
590
698
|
overwrite: bool = False,
|
|
591
699
|
) -> "Label":
|
|
592
700
|
"""Create an empty OME-Zarr label from a reference image.
|
|
@@ -597,12 +705,17 @@ class OmeZarrContainer:
|
|
|
597
705
|
name (str): The name of the new image.
|
|
598
706
|
ref_image (Image | Label | None): A reference image that will be used
|
|
599
707
|
to create the new image.
|
|
600
|
-
shape (
|
|
708
|
+
shape (Sequence[int] | None): The shape of the new image.
|
|
601
709
|
pixel_size (PixelSize | None): The pixel size of the new image.
|
|
602
|
-
axes_names (
|
|
710
|
+
axes_names (Sequence[str] | None): The axes names of the new image.
|
|
603
711
|
For labels, the channel axis is not allowed.
|
|
604
|
-
chunks (
|
|
605
|
-
dtype (str
|
|
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
|
+
compressor: The compressor to use. If None, the compressor of the
|
|
718
|
+
reference image will be used.
|
|
606
719
|
overwrite (bool): Whether to overwrite an existing image.
|
|
607
720
|
|
|
608
721
|
Returns:
|
|
@@ -619,6 +732,8 @@ class OmeZarrContainer:
|
|
|
619
732
|
axes_names=axes_names,
|
|
620
733
|
chunks=chunks,
|
|
621
734
|
dtype=dtype,
|
|
735
|
+
dimension_separator=dimension_separator,
|
|
736
|
+
compressor=compressor,
|
|
622
737
|
overwrite=overwrite,
|
|
623
738
|
)
|
|
624
739
|
|
|
@@ -667,9 +782,50 @@ def open_image(
|
|
|
667
782
|
)
|
|
668
783
|
|
|
669
784
|
|
|
785
|
+
def open_label(
|
|
786
|
+
store: StoreOrGroup,
|
|
787
|
+
name: str | None = None,
|
|
788
|
+
path: str | None = None,
|
|
789
|
+
pixel_size: PixelSize | None = None,
|
|
790
|
+
strict: bool = True,
|
|
791
|
+
cache: bool = False,
|
|
792
|
+
mode: AccessModeLiteral = "r+",
|
|
793
|
+
) -> Label:
|
|
794
|
+
"""Open a single level label from an OME-Zarr Label group.
|
|
795
|
+
|
|
796
|
+
Args:
|
|
797
|
+
store (StoreOrGroup): The Zarr store or group to create the image in.
|
|
798
|
+
name (str | None): The name of the label. If None,
|
|
799
|
+
we will try to open the store as a multiscale label.
|
|
800
|
+
path (str | None): The path to the image in the ome_zarr file.
|
|
801
|
+
pixel_size (PixelSize | None): The pixel size of the image.
|
|
802
|
+
strict (bool): Only used if the pixel size is provided. If True, the
|
|
803
|
+
pixel size must match the image pixel size exactly. If False, the
|
|
804
|
+
closest pixel size level will be returned.
|
|
805
|
+
cache (bool): Whether to use a cache for the zarr group metadata.
|
|
806
|
+
mode (AccessModeLiteral): The access mode for the image. Defaults to "r+".
|
|
807
|
+
|
|
808
|
+
"""
|
|
809
|
+
group_handler = ZarrGroupHandler(store, cache, mode)
|
|
810
|
+
if name is None:
|
|
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
|
|
815
|
+
return Label(group_handler, path, label_meta_handler)
|
|
816
|
+
|
|
817
|
+
labels_container = LabelsContainer(group_handler)
|
|
818
|
+
return labels_container.get(
|
|
819
|
+
name=name,
|
|
820
|
+
path=path,
|
|
821
|
+
pixel_size=pixel_size,
|
|
822
|
+
strict=strict,
|
|
823
|
+
)
|
|
824
|
+
|
|
825
|
+
|
|
670
826
|
def create_empty_ome_zarr(
|
|
671
827
|
store: StoreOrGroup,
|
|
672
|
-
shape:
|
|
828
|
+
shape: Sequence[int],
|
|
673
829
|
xy_pixelsize: float,
|
|
674
830
|
z_spacing: float = 1.0,
|
|
675
831
|
time_spacing: float = 1.0,
|
|
@@ -678,14 +834,16 @@ def create_empty_ome_zarr(
|
|
|
678
834
|
z_scaling_factor: float = 1.0,
|
|
679
835
|
space_unit: SpaceUnits = DefaultSpaceUnit,
|
|
680
836
|
time_unit: TimeUnits = DefaultTimeUnit,
|
|
681
|
-
axes_names:
|
|
837
|
+
axes_names: Sequence[str] | None = None,
|
|
682
838
|
name: str | None = None,
|
|
683
|
-
chunks:
|
|
839
|
+
chunks: Sequence[int] | None = None,
|
|
684
840
|
dtype: str = "uint16",
|
|
841
|
+
dimension_separator: DIMENSION_SEPARATOR = "/",
|
|
842
|
+
compressor="default",
|
|
685
843
|
channel_labels: list[str] | None = None,
|
|
686
844
|
channel_wavelengths: list[str] | None = None,
|
|
687
|
-
channel_colors:
|
|
688
|
-
channel_active:
|
|
845
|
+
channel_colors: Sequence[str] | None = None,
|
|
846
|
+
channel_active: Sequence[bool] | None = None,
|
|
689
847
|
overwrite: bool = False,
|
|
690
848
|
version: NgffVersions = DefaultNgffVersion,
|
|
691
849
|
) -> OmeZarrContainer:
|
|
@@ -693,7 +851,7 @@ def create_empty_ome_zarr(
|
|
|
693
851
|
|
|
694
852
|
Args:
|
|
695
853
|
store (StoreOrGroup): The Zarr store or group to create the image in.
|
|
696
|
-
shape (
|
|
854
|
+
shape (Sequence[int]): The shape of the image.
|
|
697
855
|
xy_pixelsize (float): The pixel size in x and y dimensions.
|
|
698
856
|
z_spacing (float, optional): The spacing between z slices. Defaults to 1.0.
|
|
699
857
|
time_spacing (float, optional): The spacing between time points.
|
|
@@ -708,19 +866,22 @@ def create_empty_ome_zarr(
|
|
|
708
866
|
DefaultSpaceUnit.
|
|
709
867
|
time_unit (TimeUnits, optional): The unit of time. Defaults to
|
|
710
868
|
DefaultTimeUnit.
|
|
711
|
-
axes_names (
|
|
869
|
+
axes_names (Sequence[str] | None, optional): The names of the axes.
|
|
712
870
|
If None the canonical names are used. Defaults to None.
|
|
713
871
|
name (str | None, optional): The name of the image. Defaults to None.
|
|
714
|
-
chunks (
|
|
872
|
+
chunks (Sequence[int] | None, optional): The chunk shape. If None the shape
|
|
715
873
|
is used. Defaults to None.
|
|
716
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
|
+
compressor: The compressor to use. Defaults to "default".
|
|
717
878
|
channel_labels (list[str] | None, optional): The labels of the channels.
|
|
718
879
|
Defaults to None.
|
|
719
880
|
channel_wavelengths (list[str] | None, optional): The wavelengths of the
|
|
720
881
|
channels. Defaults to None.
|
|
721
|
-
channel_colors (
|
|
882
|
+
channel_colors (Sequence[str] | None, optional): The colors of the channels.
|
|
722
883
|
Defaults to None.
|
|
723
|
-
channel_active (
|
|
884
|
+
channel_active (Sequence[bool] | None, optional): Whether the channels are
|
|
724
885
|
active. Defaults to None.
|
|
725
886
|
overwrite (bool, optional): Whether to overwrite an existing image.
|
|
726
887
|
Defaults to True.
|
|
@@ -742,6 +903,8 @@ def create_empty_ome_zarr(
|
|
|
742
903
|
name=name,
|
|
743
904
|
chunks=chunks,
|
|
744
905
|
dtype=dtype,
|
|
906
|
+
dimension_separator=dimension_separator,
|
|
907
|
+
compressor=compressor,
|
|
745
908
|
overwrite=overwrite,
|
|
746
909
|
version=version,
|
|
747
910
|
)
|
|
@@ -768,14 +931,16 @@ def create_ome_zarr_from_array(
|
|
|
768
931
|
z_scaling_factor: float = 1.0,
|
|
769
932
|
space_unit: SpaceUnits = DefaultSpaceUnit,
|
|
770
933
|
time_unit: TimeUnits = DefaultTimeUnit,
|
|
771
|
-
axes_names:
|
|
934
|
+
axes_names: Sequence[str] | None = None,
|
|
772
935
|
channel_labels: list[str] | None = None,
|
|
773
936
|
channel_wavelengths: list[str] | None = None,
|
|
774
937
|
percentiles: tuple[float, float] | None = (0.1, 99.9),
|
|
775
|
-
channel_colors:
|
|
776
|
-
channel_active:
|
|
938
|
+
channel_colors: Sequence[str] | None = None,
|
|
939
|
+
channel_active: Sequence[bool] | None = None,
|
|
777
940
|
name: str | None = None,
|
|
778
|
-
chunks:
|
|
941
|
+
chunks: Sequence[int] | None = None,
|
|
942
|
+
dimension_separator: DIMENSION_SEPARATOR = "/",
|
|
943
|
+
compressor: str = "default",
|
|
779
944
|
overwrite: bool = False,
|
|
780
945
|
version: NgffVersions = DefaultNgffVersion,
|
|
781
946
|
) -> OmeZarrContainer:
|
|
@@ -798,10 +963,10 @@ def create_ome_zarr_from_array(
|
|
|
798
963
|
DefaultSpaceUnit.
|
|
799
964
|
time_unit (TimeUnits, optional): The unit of time. Defaults to
|
|
800
965
|
DefaultTimeUnit.
|
|
801
|
-
axes_names (
|
|
966
|
+
axes_names (Sequence[str] | None, optional): The names of the axes.
|
|
802
967
|
If None the canonical names are used. Defaults to None.
|
|
803
968
|
name (str | None, optional): The name of the image. Defaults to None.
|
|
804
|
-
chunks (
|
|
969
|
+
chunks (Sequence[int] | None, optional): The chunk shape. If None the shape
|
|
805
970
|
is used. Defaults to None.
|
|
806
971
|
channel_labels (list[str] | None, optional): The labels of the channels.
|
|
807
972
|
Defaults to None.
|
|
@@ -809,10 +974,13 @@ def create_ome_zarr_from_array(
|
|
|
809
974
|
channels. Defaults to None.
|
|
810
975
|
percentiles (tuple[float, float] | None, optional): The percentiles of the
|
|
811
976
|
channels. Defaults to None.
|
|
812
|
-
channel_colors (
|
|
977
|
+
channel_colors (Sequence[str] | None, optional): The colors of the channels.
|
|
813
978
|
Defaults to None.
|
|
814
|
-
channel_active (
|
|
979
|
+
channel_active (Sequence[bool] | None, optional): Whether the channels are
|
|
815
980
|
active. Defaults to None.
|
|
981
|
+
dimension_separator (DIMENSION_SEPARATOR): The separator to use for
|
|
982
|
+
dimensions. Defaults to "/".
|
|
983
|
+
compressor: The compressor to use. Defaults to "default".
|
|
816
984
|
overwrite (bool, optional): Whether to overwrite an existing image.
|
|
817
985
|
Defaults to True.
|
|
818
986
|
version (str, optional): The version of the OME-Zarr specification.
|
|
@@ -834,6 +1002,8 @@ def create_ome_zarr_from_array(
|
|
|
834
1002
|
chunks=chunks,
|
|
835
1003
|
dtype=str(array.dtype),
|
|
836
1004
|
overwrite=overwrite,
|
|
1005
|
+
dimension_separator=dimension_separator,
|
|
1006
|
+
compressor=compressor,
|
|
837
1007
|
version=version,
|
|
838
1008
|
)
|
|
839
1009
|
|