ngio 0.5.0a2__py3-none-any.whl → 0.5.0a3__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 -2
- ngio/common/__init__.py +11 -6
- ngio/common/_masking_roi.py +12 -41
- ngio/common/_pyramid.py +206 -76
- ngio/common/_roi.py +257 -329
- ngio/experimental/iterators/_feature.py +3 -3
- ngio/experimental/iterators/_rois_utils.py +10 -11
- ngio/hcs/_plate.py +50 -43
- ngio/images/_abstract_image.py +417 -35
- ngio/images/_create_synt_container.py +35 -42
- ngio/images/_create_utils.py +423 -0
- ngio/images/_image.py +154 -176
- ngio/images/_label.py +144 -119
- ngio/images/_ome_zarr_container.py +361 -196
- 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 +5 -4
- ngio/io_pipes/_ops_slices_utils.py +8 -5
- ngio/ome_zarr_meta/__init__.py +15 -18
- ngio/ome_zarr_meta/_meta_handlers.py +334 -713
- ngio/ome_zarr_meta/ngio_specs/_axes.py +1 -0
- ngio/ome_zarr_meta/ngio_specs/_dataset.py +13 -22
- ngio/ome_zarr_meta/ngio_specs/_ngio_hcs.py +54 -61
- ngio/ome_zarr_meta/ngio_specs/_ngio_image.py +14 -68
- ngio/ome_zarr_meta/v04/__init__.py +1 -1
- ngio/ome_zarr_meta/v04/{_v04_spec_utils.py → _v04_spec.py} +16 -61
- ngio/ome_zarr_meta/v05/__init__.py +1 -1
- ngio/ome_zarr_meta/v05/{_v05_spec_utils.py → _v05_spec.py} +18 -61
- ngio/tables/_tables_container.py +2 -4
- ngio/tables/backends/_anndata.py +57 -8
- ngio/tables/backends/_anndata_utils.py +1 -6
- ngio/tables/backends/_csv.py +3 -19
- ngio/tables/backends/_json.py +10 -13
- ngio/tables/backends/_parquet.py +3 -31
- ngio/tables/backends/_py_arrow_backends.py +222 -0
- ngio/tables/v1/_roi_table.py +41 -24
- ngio/utils/__init__.py +4 -12
- ngio/utils/_zarr_utils.py +160 -53
- {ngio-0.5.0a2.dist-info → ngio-0.5.0a3.dist-info}/METADATA +6 -2
- {ngio-0.5.0a2.dist-info → ngio-0.5.0a3.dist-info}/RECORD +44 -45
- {ngio-0.5.0a2.dist-info → ngio-0.5.0a3.dist-info}/WHEEL +1 -1
- ngio/images/_create.py +0 -287
- ngio/tables/backends/_non_zarr_backends.py +0 -196
- ngio/utils/_logger.py +0 -50
- {ngio-0.5.0a2.dist-info → ngio-0.5.0a3.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
"""Abstract class for handling OME-NGFF images."""
|
|
2
2
|
|
|
3
3
|
import warnings
|
|
4
|
-
from collections.abc import Sequence
|
|
5
|
-
from typing import Literal
|
|
4
|
+
from collections.abc import Mapping, Sequence
|
|
5
|
+
from typing import Any, Literal
|
|
6
6
|
|
|
7
7
|
import numpy as np
|
|
8
8
|
from zarr.core.array import CompressorLike
|
|
9
9
|
|
|
10
|
-
from ngio.
|
|
10
|
+
from ngio.common._pyramid import ChunksLike, ShardsLike
|
|
11
|
+
from ngio.images._create_utils import init_image_like
|
|
11
12
|
from ngio.images._image import Image, ImagesContainer
|
|
12
13
|
from ngio.images._label import Label, LabelsContainer
|
|
13
14
|
from ngio.images._masked_image import MaskedImage, MaskedLabel
|
|
14
|
-
from ngio.ome_zarr_meta import
|
|
15
|
+
from ngio.ome_zarr_meta import (
|
|
16
|
+
LabelMetaHandler,
|
|
17
|
+
NgioImageMeta,
|
|
18
|
+
PixelSize,
|
|
19
|
+
)
|
|
15
20
|
from ngio.ome_zarr_meta.ngio_specs import (
|
|
21
|
+
Channel,
|
|
16
22
|
DefaultNgffVersion,
|
|
17
23
|
DefaultSpaceUnit,
|
|
18
24
|
DefaultTimeUnit,
|
|
@@ -35,6 +41,7 @@ from ngio.tables import (
|
|
|
35
41
|
)
|
|
36
42
|
from ngio.utils import (
|
|
37
43
|
AccessModeLiteral,
|
|
44
|
+
NgioError,
|
|
38
45
|
NgioValidationError,
|
|
39
46
|
NgioValueError,
|
|
40
47
|
StoreOrGroup,
|
|
@@ -42,18 +49,26 @@ from ngio.utils import (
|
|
|
42
49
|
)
|
|
43
50
|
|
|
44
51
|
|
|
45
|
-
def
|
|
52
|
+
def _try_get_table_container(
|
|
53
|
+
handler: ZarrGroupHandler, create_mode: bool = True
|
|
54
|
+
) -> TablesContainer | None:
|
|
46
55
|
"""Return a default table container."""
|
|
47
|
-
|
|
48
|
-
|
|
56
|
+
try:
|
|
57
|
+
table_handler = handler.get_handler("tables", create_mode=create_mode)
|
|
49
58
|
return TablesContainer(table_handler)
|
|
59
|
+
except NgioError:
|
|
60
|
+
return None
|
|
50
61
|
|
|
51
62
|
|
|
52
|
-
def
|
|
63
|
+
def _try_get_label_container(
|
|
64
|
+
handler: ZarrGroupHandler, create_mode: bool = True
|
|
65
|
+
) -> LabelsContainer | None:
|
|
53
66
|
"""Return a default label container."""
|
|
54
|
-
|
|
55
|
-
|
|
67
|
+
try:
|
|
68
|
+
label_handler = handler.get_handler("labels", create_mode=create_mode)
|
|
56
69
|
return LabelsContainer(label_handler)
|
|
70
|
+
except NgioError:
|
|
71
|
+
return None
|
|
57
72
|
|
|
58
73
|
|
|
59
74
|
class OmeZarrContainer:
|
|
@@ -128,13 +143,15 @@ class OmeZarrContainer:
|
|
|
128
143
|
"""
|
|
129
144
|
return self._images_container
|
|
130
145
|
|
|
131
|
-
def _get_labels_container(self) -> LabelsContainer | None:
|
|
146
|
+
def _get_labels_container(self, create_mode: bool = True) -> LabelsContainer | None:
|
|
132
147
|
"""Return the labels container."""
|
|
133
|
-
if self._labels_container is None:
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
self.
|
|
148
|
+
if self._labels_container is not None:
|
|
149
|
+
return self._labels_container
|
|
150
|
+
|
|
151
|
+
_labels_container = _try_get_label_container(
|
|
152
|
+
self._group_handler, create_mode=create_mode
|
|
153
|
+
)
|
|
154
|
+
self._labels_container = _labels_container
|
|
138
155
|
return self._labels_container
|
|
139
156
|
|
|
140
157
|
@property
|
|
@@ -145,13 +162,15 @@ class OmeZarrContainer:
|
|
|
145
162
|
raise NgioValidationError("No labels found in the image.")
|
|
146
163
|
return _labels_container
|
|
147
164
|
|
|
148
|
-
def _get_tables_container(self) -> TablesContainer | None:
|
|
165
|
+
def _get_tables_container(self, create_mode: bool = True) -> TablesContainer | None:
|
|
149
166
|
"""Return the tables container."""
|
|
150
|
-
if self._tables_container is None:
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
self.
|
|
167
|
+
if self._tables_container is not None:
|
|
168
|
+
return self._tables_container
|
|
169
|
+
|
|
170
|
+
_tables_container = _try_get_table_container(
|
|
171
|
+
self._group_handler, create_mode=create_mode
|
|
172
|
+
)
|
|
173
|
+
self._tables_container = _tables_container
|
|
155
174
|
return self._tables_container
|
|
156
175
|
|
|
157
176
|
@property
|
|
@@ -403,61 +422,88 @@ class OmeZarrContainer:
|
|
|
403
422
|
self,
|
|
404
423
|
store: StoreOrGroup,
|
|
405
424
|
ref_path: str | None = None,
|
|
425
|
+
# Metadata parameters
|
|
406
426
|
shape: Sequence[int] | None = None,
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
427
|
+
pixelsize: float | tuple[float, float] | None = None,
|
|
428
|
+
z_spacing: float | None = None,
|
|
429
|
+
time_spacing: float | None = None,
|
|
410
430
|
name: str | None = None,
|
|
411
|
-
|
|
412
|
-
dtype: str | None = None,
|
|
413
|
-
dimension_separator: Literal[".", "/"] | None = None,
|
|
414
|
-
compressors: CompressorLike | None = None,
|
|
415
|
-
copy_labels: bool = False,
|
|
416
|
-
copy_tables: bool = False,
|
|
431
|
+
channels_meta: Sequence[str | Channel] | None = None,
|
|
417
432
|
ngff_version: NgffVersions | None = None,
|
|
433
|
+
# Zarr Array parameters
|
|
434
|
+
chunks: ChunksLike = "auto",
|
|
435
|
+
shards: ShardsLike | None = None,
|
|
436
|
+
dtype: str = "uint16",
|
|
437
|
+
dimension_separator: Literal[".", "/"] = "/",
|
|
438
|
+
compressors: CompressorLike = "auto",
|
|
439
|
+
extra_array_kwargs: Mapping[str, Any] | None = None,
|
|
418
440
|
overwrite: bool = False,
|
|
441
|
+
# Copy from current image
|
|
442
|
+
copy_labels: bool = False,
|
|
443
|
+
copy_tables: bool = False,
|
|
444
|
+
# Deprecated arguments
|
|
445
|
+
labels: Sequence[str] | None = None,
|
|
446
|
+
pixel_size: PixelSize | None = None,
|
|
419
447
|
) -> "OmeZarrContainer":
|
|
420
|
-
"""
|
|
448
|
+
"""Derive a new OME-Zarr container from the current image.
|
|
449
|
+
|
|
450
|
+
If a kwarg is not provided, the value from the reference image will be used.
|
|
421
451
|
|
|
422
452
|
Args:
|
|
423
453
|
store (StoreOrGroup): The Zarr store or group to create the image in.
|
|
424
|
-
ref_path (str | None): The path to the reference image in
|
|
425
|
-
|
|
454
|
+
ref_path (str | None): The path to the reference image in the image
|
|
455
|
+
container.
|
|
426
456
|
shape (Sequence[int] | None): The shape of the new image.
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
dtype (str | None): The data type of the new image.
|
|
457
|
+
pixelsize (float | tuple[float, float] | None): The pixel size of the new
|
|
458
|
+
image.
|
|
459
|
+
z_spacing (float | None): The z spacing of the new image.
|
|
460
|
+
time_spacing (float | None): The time spacing of the new image.
|
|
432
461
|
name (str | None): The name of the new image.
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
462
|
+
channels_meta (Sequence[str | Channel] | None): The channels metadata
|
|
463
|
+
of the new image.
|
|
464
|
+
ngff_version (NgffVersions | None): The NGFF version to use.
|
|
465
|
+
chunks (ChunksLike): The chunk shape of the new image. Defaults to "auto".
|
|
466
|
+
shards (ShardsLike | None): The shard shape of the new image.
|
|
467
|
+
dtype (str): The data type of the new image. Defaults to "uint16".
|
|
468
|
+
dimension_separator (Literal[".", "/"]): The separator to use for
|
|
469
|
+
dimensions. Defaults to "/".
|
|
470
|
+
compressors (CompressorLike): The compressors to use. Defaults to "auto".
|
|
471
|
+
extra_array_kwargs (Mapping[str, Any] | None): Extra arguments to pass to
|
|
472
|
+
the zarr array creation.
|
|
473
|
+
overwrite (bool): Whether to overwrite an existing image. Defaults to False.
|
|
474
|
+
copy_labels (bool): Whether to copy the labels from the current image.
|
|
475
|
+
Defaults to False.
|
|
476
|
+
copy_tables (bool): Whether to copy the tables from the current image.
|
|
477
|
+
Defaults to False.
|
|
478
|
+
labels (Sequence[str] | None): Deprecated. This argument is deprecated,
|
|
479
|
+
please use channels_meta instead.
|
|
480
|
+
pixel_size (PixelSize | None): Deprecated. The pixel size of the new image.
|
|
481
|
+
This argument is deprecated, please use pixelsize, z_spacing,
|
|
482
|
+
and time_spacing instead.
|
|
442
483
|
|
|
443
484
|
Returns:
|
|
444
|
-
OmeZarrContainer: The new
|
|
485
|
+
OmeZarrContainer: The new derived OME-Zarr container.
|
|
445
486
|
|
|
446
487
|
"""
|
|
447
488
|
new_container = self._images_container.derive(
|
|
448
489
|
store=store,
|
|
449
490
|
ref_path=ref_path,
|
|
450
491
|
shape=shape,
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
492
|
+
pixelsize=pixelsize,
|
|
493
|
+
z_spacing=z_spacing,
|
|
494
|
+
time_spacing=time_spacing,
|
|
454
495
|
name=name,
|
|
496
|
+
channels_meta=channels_meta,
|
|
497
|
+
ngff_version=ngff_version,
|
|
455
498
|
chunks=chunks,
|
|
499
|
+
shards=shards,
|
|
456
500
|
dtype=dtype,
|
|
457
501
|
dimension_separator=dimension_separator,
|
|
458
502
|
compressors=compressors,
|
|
459
|
-
|
|
503
|
+
extra_array_kwargs=extra_array_kwargs,
|
|
460
504
|
overwrite=overwrite,
|
|
505
|
+
labels=labels,
|
|
506
|
+
pixel_size=pixel_size,
|
|
461
507
|
)
|
|
462
508
|
|
|
463
509
|
new_ome_zarr = OmeZarrContainer(
|
|
@@ -466,19 +512,19 @@ class OmeZarrContainer:
|
|
|
466
512
|
)
|
|
467
513
|
|
|
468
514
|
if copy_labels:
|
|
469
|
-
self.labels_container._group_handler.
|
|
470
|
-
new_ome_zarr.labels_container._group_handler
|
|
515
|
+
self.labels_container._group_handler.copy_group(
|
|
516
|
+
new_ome_zarr.labels_container._group_handler.group
|
|
471
517
|
)
|
|
472
518
|
|
|
473
519
|
if copy_tables:
|
|
474
|
-
self.tables_container._group_handler.
|
|
475
|
-
new_ome_zarr.tables_container._group_handler
|
|
520
|
+
self.tables_container._group_handler.copy_group(
|
|
521
|
+
new_ome_zarr.tables_container._group_handler.group
|
|
476
522
|
)
|
|
477
523
|
return new_ome_zarr
|
|
478
524
|
|
|
479
525
|
def list_tables(self, filter_types: TypedTable | str | None = None) -> list[str]:
|
|
480
526
|
"""List all tables in the image."""
|
|
481
|
-
table_container = self._get_tables_container()
|
|
527
|
+
table_container = self._get_tables_container(create_mode=False)
|
|
482
528
|
if table_container is None:
|
|
483
529
|
return []
|
|
484
530
|
|
|
@@ -621,7 +667,7 @@ class OmeZarrContainer:
|
|
|
621
667
|
|
|
622
668
|
def list_labels(self) -> list[str]:
|
|
623
669
|
"""List all labels in the image."""
|
|
624
|
-
label_container = self._get_labels_container()
|
|
670
|
+
label_container = self._get_labels_container(create_mode=False)
|
|
625
671
|
if label_container is None:
|
|
626
672
|
return []
|
|
627
673
|
return label_container.list()
|
|
@@ -688,38 +734,62 @@ class OmeZarrContainer:
|
|
|
688
734
|
self,
|
|
689
735
|
name: str,
|
|
690
736
|
ref_image: Image | Label | None = None,
|
|
737
|
+
# Metadata parameters
|
|
691
738
|
shape: Sequence[int] | None = None,
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
739
|
+
pixelsize: float | tuple[float, float] | None = None,
|
|
740
|
+
z_spacing: float | None = None,
|
|
741
|
+
time_spacing: float | None = None,
|
|
742
|
+
channels_policy: Literal["same", "squeeze"] | int = "squeeze",
|
|
743
|
+
ngff_version: NgffVersions | None = None,
|
|
744
|
+
# Zarr Array parameters
|
|
745
|
+
chunks: ChunksLike = "auto",
|
|
746
|
+
shards: ShardsLike | None = None,
|
|
747
|
+
dtype: str | None = None,
|
|
696
748
|
dimension_separator: Literal[".", "/"] | None = None,
|
|
697
749
|
compressors: CompressorLike | None = None,
|
|
750
|
+
extra_array_kwargs: Mapping[str, Any] | None = None,
|
|
698
751
|
overwrite: bool = False,
|
|
752
|
+
# Deprecated arguments
|
|
753
|
+
labels: Sequence[str] | None = None,
|
|
754
|
+
pixel_size: PixelSize | None = None,
|
|
699
755
|
) -> "Label":
|
|
700
|
-
"""
|
|
756
|
+
"""Derive a new label from an existing image or label.
|
|
701
757
|
|
|
702
|
-
|
|
758
|
+
If a kwarg is not provided, the value from the reference image will be used.
|
|
703
759
|
|
|
704
760
|
Args:
|
|
705
|
-
name (str): The name of the new
|
|
706
|
-
ref_image (Image | Label | None):
|
|
707
|
-
|
|
708
|
-
shape (Sequence[int] | None): The shape of the new
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
761
|
+
name (str): The name of the new label.
|
|
762
|
+
ref_image (Image | Label | None): The reference image to derive the new
|
|
763
|
+
label from. If None, the first level image will be used.
|
|
764
|
+
shape (Sequence[int] | None): The shape of the new label.
|
|
765
|
+
pixelsize (float | tuple[float, float] | None): The pixel size of the new
|
|
766
|
+
label.
|
|
767
|
+
z_spacing (float | None): The z spacing of the new label.
|
|
768
|
+
time_spacing (float | None): The time spacing of the new label.
|
|
769
|
+
channels_policy (Literal["same", "squeeze"] | int): Possible policies:
|
|
770
|
+
- If "squeeze", the channels axis will be removed (no matter its size).
|
|
771
|
+
- If "same", the channels axis will be kept as is (if it exists).
|
|
772
|
+
- If an integer is provided, the channels axis will be changed to have
|
|
773
|
+
that size.
|
|
774
|
+
Defaults to "squeeze".
|
|
775
|
+
ngff_version (NgffVersions | None): The NGFF version to use.
|
|
776
|
+
chunks (ChunksLike): The chunk shape of the new label. Defaults to "auto".
|
|
777
|
+
shards (ShardsLike | None): The shard shape of the new label.
|
|
778
|
+
dtype (str | None): The data type of the new label.
|
|
779
|
+
dimension_separator (Literal[".", "/"] | None): The separator to use for
|
|
780
|
+
dimensions.
|
|
781
|
+
compressors (CompressorLike | None): The compressors to use.
|
|
782
|
+
extra_array_kwargs (Mapping[str, Any] | None): Extra arguments to pass to
|
|
783
|
+
the zarr array creation.
|
|
784
|
+
overwrite (bool): Whether to overwrite an existing label. Defaults to False.
|
|
785
|
+
labels (Sequence[str] | None): Deprecated. This argument is deprecated,
|
|
786
|
+
please use channels_meta instead.
|
|
787
|
+
pixel_size (PixelSize | None): Deprecated. The pixel size of the new label.
|
|
788
|
+
This argument is deprecated, please use pixelsize, z_spacing,
|
|
789
|
+
and time_spacing instead.
|
|
720
790
|
|
|
721
791
|
Returns:
|
|
722
|
-
Label: The new label.
|
|
792
|
+
Label: The new derived label.
|
|
723
793
|
|
|
724
794
|
"""
|
|
725
795
|
if ref_image is None:
|
|
@@ -728,13 +798,20 @@ class OmeZarrContainer:
|
|
|
728
798
|
name=name,
|
|
729
799
|
ref_image=ref_image,
|
|
730
800
|
shape=shape,
|
|
731
|
-
|
|
732
|
-
|
|
801
|
+
pixelsize=pixelsize,
|
|
802
|
+
z_spacing=z_spacing,
|
|
803
|
+
time_spacing=time_spacing,
|
|
804
|
+
channels_policy=channels_policy,
|
|
805
|
+
ngff_version=ngff_version,
|
|
733
806
|
chunks=chunks,
|
|
807
|
+
shards=shards,
|
|
734
808
|
dtype=dtype,
|
|
735
809
|
dimension_separator=dimension_separator,
|
|
736
810
|
compressors=compressors,
|
|
811
|
+
extra_array_kwargs=extra_array_kwargs,
|
|
737
812
|
overwrite=overwrite,
|
|
813
|
+
labels=labels,
|
|
814
|
+
pixel_size=pixel_size,
|
|
738
815
|
)
|
|
739
816
|
|
|
740
817
|
|
|
@@ -808,10 +885,12 @@ def open_label(
|
|
|
808
885
|
"""
|
|
809
886
|
group_handler = ZarrGroupHandler(store=store, cache=cache, mode=mode)
|
|
810
887
|
if name is None:
|
|
811
|
-
label_meta_handler =
|
|
812
|
-
path =
|
|
813
|
-
|
|
814
|
-
|
|
888
|
+
label_meta_handler = LabelMetaHandler(group_handler)
|
|
889
|
+
path = (
|
|
890
|
+
label_meta_handler.get_meta()
|
|
891
|
+
.get_dataset(path=path, pixel_size=pixel_size, strict=strict)
|
|
892
|
+
.path
|
|
893
|
+
)
|
|
815
894
|
return Label(group_handler, path, label_meta_handler)
|
|
816
895
|
|
|
817
896
|
labels_container = LabelsContainer(group_handler)
|
|
@@ -826,196 +905,282 @@ def open_label(
|
|
|
826
905
|
def create_empty_ome_zarr(
|
|
827
906
|
store: StoreOrGroup,
|
|
828
907
|
shape: Sequence[int],
|
|
829
|
-
|
|
908
|
+
pixelsize: float | tuple[float, float] | None = None,
|
|
830
909
|
z_spacing: float = 1.0,
|
|
831
910
|
time_spacing: float = 1.0,
|
|
911
|
+
scaling_factors: Sequence[float] | Literal["auto"] = "auto",
|
|
832
912
|
levels: int | list[str] = 5,
|
|
833
|
-
xy_scaling_factor: float = 2,
|
|
834
|
-
z_scaling_factor: float = 1.0,
|
|
835
913
|
space_unit: SpaceUnits = DefaultSpaceUnit,
|
|
836
914
|
time_unit: TimeUnits = DefaultTimeUnit,
|
|
837
915
|
axes_names: Sequence[str] | None = None,
|
|
916
|
+
channels_meta: Sequence[str | Channel] | None = None,
|
|
838
917
|
name: str | None = None,
|
|
839
|
-
|
|
918
|
+
ngff_version: NgffVersions = DefaultNgffVersion,
|
|
919
|
+
chunks: ChunksLike = "auto",
|
|
920
|
+
shards: ShardsLike | None = None,
|
|
840
921
|
dtype: str = "uint16",
|
|
841
922
|
dimension_separator: Literal[".", "/"] = "/",
|
|
842
923
|
compressors: CompressorLike = "auto",
|
|
924
|
+
extra_array_kwargs: Mapping[str, Any] | None = None,
|
|
925
|
+
overwrite: bool = False,
|
|
926
|
+
# Deprecated arguments
|
|
927
|
+
xy_pixelsize: float | None = None,
|
|
928
|
+
xy_scaling_factor: float | None = None,
|
|
929
|
+
z_scaling_factor: float | None = None,
|
|
843
930
|
channel_labels: list[str] | None = None,
|
|
844
931
|
channel_wavelengths: list[str] | None = None,
|
|
845
932
|
channel_colors: Sequence[str] | None = None,
|
|
846
933
|
channel_active: Sequence[bool] | None = None,
|
|
847
|
-
overwrite: bool = False,
|
|
848
|
-
ngff_version: NgffVersions = DefaultNgffVersion,
|
|
849
934
|
) -> OmeZarrContainer:
|
|
850
935
|
"""Create an empty OME-Zarr image with the given shape and metadata.
|
|
851
936
|
|
|
852
937
|
Args:
|
|
853
938
|
store (StoreOrGroup): The Zarr store or group to create the image in.
|
|
854
939
|
shape (Sequence[int]): The shape of the image.
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
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.
|
|
940
|
+
pixelsize (float | tuple[float, float] | None): The pixel size in x and y
|
|
941
|
+
dimensions.
|
|
942
|
+
z_spacing (float): The spacing between z slices. Defaults to 1.0.
|
|
943
|
+
time_spacing (float): The spacing between time points. Defaults to 1.0.
|
|
944
|
+
scaling_factors (Sequence[float] | Literal["auto"]): The down-scaling factors
|
|
945
|
+
for the pyramid levels. Defaults to "auto".
|
|
946
|
+
levels (int | list[str]): The number of levels in the pyramid or a list of
|
|
947
|
+
level names. Defaults to 5.
|
|
948
|
+
space_unit (SpaceUnits): The unit of space. Defaults to DefaultSpaceUnit.
|
|
949
|
+
time_unit (TimeUnits): The unit of time. Defaults to DefaultTimeUnit.
|
|
950
|
+
axes_names (Sequence[str] | None): The names of the axes. If None the
|
|
951
|
+
canonical names are used. Defaults to None.
|
|
952
|
+
channels_meta (Sequence[str | Channel] | None): The channels metadata.
|
|
879
953
|
Defaults to None.
|
|
880
|
-
|
|
881
|
-
|
|
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
|
-
ngff_version (NgffVersion, optional): The version of the OME-Zarr specification.
|
|
954
|
+
name (str | None): The name of the image. Defaults to None.
|
|
955
|
+
ngff_version (NgffVersions): The version of the OME-Zarr specification.
|
|
889
956
|
Defaults to DefaultNgffVersion.
|
|
957
|
+
chunks (ChunksLike): The chunk shape. Defaults to "auto".
|
|
958
|
+
shards (ShardsLike | None): The shard shape. Defaults to None.
|
|
959
|
+
dtype (str): The data type of the image. Defaults to "uint16".
|
|
960
|
+
dimension_separator (Literal[".", "/"]): The dimension separator to use.
|
|
961
|
+
Defaults to "/".
|
|
962
|
+
compressors (CompressorLike): The compressor to use. Defaults to "auto".
|
|
963
|
+
extra_array_kwargs (Mapping[str, Any] | None): Extra arguments to pass to
|
|
964
|
+
the zarr array creation. Defaults to None.
|
|
965
|
+
overwrite (bool): Whether to overwrite an existing image. Defaults to False.
|
|
966
|
+
xy_pixelsize (float | None): Deprecated. Use pixelsize instead.
|
|
967
|
+
xy_scaling_factor (float | None): Deprecated. Use scaling_factors instead.
|
|
968
|
+
z_scaling_factor (float | None): Deprecated. Use scaling_factors instead.
|
|
969
|
+
channel_labels (list[str] | None): Deprecated. Use channels_meta instead.
|
|
970
|
+
channel_wavelengths (list[str] | None): Deprecated. Use channels_meta instead.
|
|
971
|
+
channel_colors (Sequence[str] | None): Deprecated. Use channels_meta instead.
|
|
972
|
+
channel_active (Sequence[bool] | None): Deprecated. Use channels_meta instead.
|
|
890
973
|
"""
|
|
891
|
-
|
|
974
|
+
if xy_pixelsize is not None:
|
|
975
|
+
warnings.warn(
|
|
976
|
+
"'xy_pixelsize' is deprecated and will be removed in a future "
|
|
977
|
+
"version. Please use 'pixelsize' instead.",
|
|
978
|
+
DeprecationWarning,
|
|
979
|
+
stacklevel=2,
|
|
980
|
+
)
|
|
981
|
+
pixelsize = xy_pixelsize
|
|
982
|
+
if xy_scaling_factor is not None or z_scaling_factor is not None:
|
|
983
|
+
warnings.warn(
|
|
984
|
+
"'xy_scaling_factor' and 'z_scaling_factor' are deprecated and will be "
|
|
985
|
+
"removed in a future version. Please use 'scaling_factors' instead.",
|
|
986
|
+
DeprecationWarning,
|
|
987
|
+
stacklevel=2,
|
|
988
|
+
)
|
|
989
|
+
xy_scaling_factor_ = xy_scaling_factor or 2.0
|
|
990
|
+
z_scaling_factor_ = z_scaling_factor or 1.0
|
|
991
|
+
if len(shape) == 2:
|
|
992
|
+
scaling_factors = (xy_scaling_factor_, xy_scaling_factor_)
|
|
993
|
+
else:
|
|
994
|
+
zyx_factors = (z_scaling_factor_, xy_scaling_factor_, xy_scaling_factor_)
|
|
995
|
+
scaling_factors = (1.0,) * (len(shape) - 3) + zyx_factors
|
|
996
|
+
|
|
997
|
+
if channel_labels is not None:
|
|
998
|
+
warnings.warn(
|
|
999
|
+
"'channel_labels' is deprecated and will be removed in a future "
|
|
1000
|
+
"version. Please use 'channels_meta' instead.",
|
|
1001
|
+
DeprecationWarning,
|
|
1002
|
+
stacklevel=2,
|
|
1003
|
+
)
|
|
1004
|
+
channels_meta = channel_labels
|
|
1005
|
+
|
|
1006
|
+
if channel_wavelengths is not None:
|
|
1007
|
+
warnings.warn(
|
|
1008
|
+
"'channel_wavelengths' is deprecated and will be removed in a future "
|
|
1009
|
+
"version. Please use 'channels_meta' instead.",
|
|
1010
|
+
DeprecationWarning,
|
|
1011
|
+
stacklevel=2,
|
|
1012
|
+
)
|
|
1013
|
+
if channel_colors is not None:
|
|
1014
|
+
warnings.warn(
|
|
1015
|
+
"'channel_colors' is deprecated and will be removed in a future "
|
|
1016
|
+
"version. Please use 'channels_meta' instead.",
|
|
1017
|
+
DeprecationWarning,
|
|
1018
|
+
stacklevel=2,
|
|
1019
|
+
)
|
|
1020
|
+
if channel_active is not None:
|
|
1021
|
+
warnings.warn(
|
|
1022
|
+
"'channel_active' is deprecated and will be removed in a future "
|
|
1023
|
+
"version. Please use 'channels_meta' instead.",
|
|
1024
|
+
DeprecationWarning,
|
|
1025
|
+
stacklevel=2,
|
|
1026
|
+
)
|
|
1027
|
+
|
|
1028
|
+
if pixelsize is None:
|
|
1029
|
+
raise NgioValueError("pixelsize must be provided.")
|
|
1030
|
+
|
|
1031
|
+
handler = init_image_like(
|
|
892
1032
|
store=store,
|
|
1033
|
+
meta_type=NgioImageMeta,
|
|
893
1034
|
shape=shape,
|
|
894
|
-
pixelsize=
|
|
1035
|
+
pixelsize=pixelsize,
|
|
895
1036
|
z_spacing=z_spacing,
|
|
896
1037
|
time_spacing=time_spacing,
|
|
1038
|
+
scaling_factors=scaling_factors,
|
|
897
1039
|
levels=levels,
|
|
898
|
-
yx_scaling_factor=xy_scaling_factor,
|
|
899
|
-
z_scaling_factor=z_scaling_factor,
|
|
900
1040
|
space_unit=space_unit,
|
|
901
1041
|
time_unit=time_unit,
|
|
902
1042
|
axes_names=axes_names,
|
|
1043
|
+
channels_meta=channels_meta,
|
|
903
1044
|
name=name,
|
|
1045
|
+
ngff_version=ngff_version,
|
|
904
1046
|
chunks=chunks,
|
|
1047
|
+
shards=shards,
|
|
905
1048
|
dtype=dtype,
|
|
906
1049
|
dimension_separator=dimension_separator,
|
|
907
1050
|
compressors=compressors,
|
|
1051
|
+
extra_array_kwargs=extra_array_kwargs,
|
|
908
1052
|
overwrite=overwrite,
|
|
909
|
-
ngff_version=ngff_version,
|
|
910
1053
|
)
|
|
911
1054
|
|
|
912
1055
|
ome_zarr = OmeZarrContainer(group_handler=handler)
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
1056
|
+
if (
|
|
1057
|
+
channel_wavelengths is not None
|
|
1058
|
+
or channel_colors is not None
|
|
1059
|
+
or channel_active is not None
|
|
1060
|
+
):
|
|
1061
|
+
channel_names = ome_zarr.channel_labels
|
|
1062
|
+
ome_zarr.set_channel_meta(
|
|
1063
|
+
labels=channel_names,
|
|
1064
|
+
wavelength_id=channel_wavelengths,
|
|
1065
|
+
percentiles=None,
|
|
1066
|
+
colors=channel_colors,
|
|
1067
|
+
active=channel_active,
|
|
1068
|
+
)
|
|
1069
|
+
else:
|
|
1070
|
+
ome_zarr.set_channel_meta(
|
|
1071
|
+
labels=ome_zarr.channel_labels,
|
|
1072
|
+
percentiles=None,
|
|
1073
|
+
)
|
|
920
1074
|
return ome_zarr
|
|
921
1075
|
|
|
922
1076
|
|
|
923
1077
|
def create_ome_zarr_from_array(
|
|
924
1078
|
store: StoreOrGroup,
|
|
925
1079
|
array: np.ndarray,
|
|
926
|
-
|
|
1080
|
+
pixelsize: float | tuple[float, float] | None = None,
|
|
927
1081
|
z_spacing: float = 1.0,
|
|
928
1082
|
time_spacing: float = 1.0,
|
|
1083
|
+
scaling_factors: Sequence[float] | Literal["auto"] = "auto",
|
|
929
1084
|
levels: int | list[str] = 5,
|
|
930
|
-
xy_scaling_factor: float = 2.0,
|
|
931
|
-
z_scaling_factor: float = 1.0,
|
|
932
1085
|
space_unit: SpaceUnits = DefaultSpaceUnit,
|
|
933
1086
|
time_unit: TimeUnits = DefaultTimeUnit,
|
|
934
1087
|
axes_names: Sequence[str] | None = None,
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
percentiles: tuple[float, float] | None = (0.1, 99.9),
|
|
938
|
-
channel_colors: Sequence[str] | None = None,
|
|
939
|
-
channel_active: Sequence[bool] | None = None,
|
|
1088
|
+
channels_meta: Sequence[str | Channel] | None = None,
|
|
1089
|
+
percentiles: tuple[float, float] = (0.1, 99.9),
|
|
940
1090
|
name: str | None = None,
|
|
941
|
-
|
|
1091
|
+
ngff_version: NgffVersions = DefaultNgffVersion,
|
|
1092
|
+
chunks: ChunksLike = "auto",
|
|
1093
|
+
shards: ShardsLike | None = None,
|
|
942
1094
|
dimension_separator: Literal[".", "/"] = "/",
|
|
943
1095
|
compressors: CompressorLike = "auto",
|
|
1096
|
+
extra_array_kwargs: Mapping[str, Any] | None = None,
|
|
944
1097
|
overwrite: bool = False,
|
|
945
|
-
|
|
1098
|
+
# Deprecated arguments
|
|
1099
|
+
xy_pixelsize: float | None = None,
|
|
1100
|
+
xy_scaling_factor: float | None = None,
|
|
1101
|
+
z_scaling_factor: float | None = None,
|
|
1102
|
+
channel_labels: list[str] | None = None,
|
|
1103
|
+
channel_wavelengths: list[str] | None = None,
|
|
1104
|
+
channel_colors: Sequence[str] | None = None,
|
|
1105
|
+
channel_active: Sequence[bool] | None = None,
|
|
946
1106
|
) -> OmeZarrContainer:
|
|
947
1107
|
"""Create an OME-Zarr image from a numpy array.
|
|
948
1108
|
|
|
949
1109
|
Args:
|
|
950
1110
|
store (StoreOrGroup): The Zarr store or group to create the image in.
|
|
951
1111
|
array (np.ndarray): The image data.
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
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.
|
|
972
|
-
Defaults to None.
|
|
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.
|
|
1112
|
+
pixelsize (float | tuple[float, float] | None): The pixel size in x and y
|
|
1113
|
+
dimensions.
|
|
1114
|
+
z_spacing (float): The spacing between z slices. Defaults to 1.0.
|
|
1115
|
+
time_spacing (float): The spacing between time points. Defaults to 1.0.
|
|
1116
|
+
scaling_factors (Sequence[float] | Literal["auto"]): The down-scaling factors
|
|
1117
|
+
for the pyramid levels. Defaults to "auto".
|
|
1118
|
+
levels (int | list[str]): The number of levels in the pyramid or a list of
|
|
1119
|
+
level names. Defaults to 5.
|
|
1120
|
+
space_unit (SpaceUnits): The unit of space. Defaults to DefaultSpaceUnit.
|
|
1121
|
+
time_unit (TimeUnits): The unit of time. Defaults to DefaultTimeUnit.
|
|
1122
|
+
axes_names (Sequence[str] | None): The names of the axes. If None the
|
|
1123
|
+
canonical names are used. Defaults to None.
|
|
1124
|
+
channels_meta (Sequence[str | Channel] | None): The channels metadata.
|
|
978
1125
|
Defaults to None.
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
1126
|
+
percentiles (tuple[float, float]): The percentiles of the channels for
|
|
1127
|
+
computing display ranges. Defaults to (0.1, 99.9).
|
|
1128
|
+
name (str | None): The name of the image. Defaults to None.
|
|
1129
|
+
ngff_version (NgffVersions): The version of the OME-Zarr specification.
|
|
1130
|
+
Defaults to DefaultNgffVersion.
|
|
1131
|
+
chunks (ChunksLike): The chunk shape. Defaults to "auto".
|
|
1132
|
+
shards (ShardsLike | None): The shard shape. Defaults to None.
|
|
1133
|
+
dimension_separator (Literal[".", "/"]): The separator to use for
|
|
982
1134
|
dimensions. Defaults to "/".
|
|
983
1135
|
compressors (CompressorLike): The compressors to use. Defaults to "auto".
|
|
984
|
-
|
|
985
|
-
Defaults to
|
|
986
|
-
|
|
987
|
-
|
|
1136
|
+
extra_array_kwargs (Mapping[str, Any] | None): Extra arguments to pass to
|
|
1137
|
+
the zarr array creation. Defaults to None.
|
|
1138
|
+
overwrite (bool): Whether to overwrite an existing image. Defaults to False.
|
|
1139
|
+
xy_pixelsize (float | None): Deprecated. Use pixelsize instead.
|
|
1140
|
+
xy_scaling_factor (float | None): Deprecated. Use scaling_factors instead.
|
|
1141
|
+
z_scaling_factor (float | None): Deprecated. Use scaling_factors instead.
|
|
1142
|
+
channel_labels (list[str] | None): Deprecated. Use channels_meta instead.
|
|
1143
|
+
channel_wavelengths (list[str] | None): Deprecated. Use channels_meta instead.
|
|
1144
|
+
channel_colors (Sequence[str] | None): Deprecated. Use channels_meta instead.
|
|
1145
|
+
channel_active (Sequence[bool] | None): Deprecated. Use channels_meta instead.
|
|
988
1146
|
"""
|
|
989
|
-
|
|
1147
|
+
ome_zarr = create_empty_ome_zarr(
|
|
990
1148
|
store=store,
|
|
991
1149
|
shape=array.shape,
|
|
992
|
-
pixelsize=
|
|
1150
|
+
pixelsize=pixelsize,
|
|
993
1151
|
z_spacing=z_spacing,
|
|
994
1152
|
time_spacing=time_spacing,
|
|
1153
|
+
scaling_factors=scaling_factors,
|
|
995
1154
|
levels=levels,
|
|
996
|
-
yx_scaling_factor=xy_scaling_factor,
|
|
997
|
-
z_scaling_factor=z_scaling_factor,
|
|
998
1155
|
space_unit=space_unit,
|
|
999
1156
|
time_unit=time_unit,
|
|
1000
1157
|
axes_names=axes_names,
|
|
1158
|
+
channels_meta=channels_meta,
|
|
1001
1159
|
name=name,
|
|
1160
|
+
ngff_version=ngff_version,
|
|
1002
1161
|
chunks=chunks,
|
|
1003
|
-
|
|
1004
|
-
overwrite=overwrite,
|
|
1162
|
+
shards=shards,
|
|
1005
1163
|
dimension_separator=dimension_separator,
|
|
1006
1164
|
compressors=compressors,
|
|
1007
|
-
|
|
1165
|
+
extra_array_kwargs=extra_array_kwargs,
|
|
1166
|
+
overwrite=overwrite,
|
|
1167
|
+
xy_pixelsize=xy_pixelsize,
|
|
1168
|
+
xy_scaling_factor=xy_scaling_factor,
|
|
1169
|
+
z_scaling_factor=z_scaling_factor,
|
|
1170
|
+
channel_labels=channel_labels,
|
|
1171
|
+
channel_wavelengths=channel_wavelengths,
|
|
1172
|
+
channel_colors=channel_colors,
|
|
1173
|
+
channel_active=channel_active,
|
|
1008
1174
|
)
|
|
1009
|
-
|
|
1010
|
-
ome_zarr = OmeZarrContainer(group_handler=handler)
|
|
1011
1175
|
image = ome_zarr.get_image()
|
|
1012
1176
|
image.set_array(array)
|
|
1013
1177
|
image.consolidate()
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1178
|
+
if len(percentiles) != 2:
|
|
1179
|
+
raise NgioValueError(
|
|
1180
|
+
f"'percentiles' must be a tuple of two values. Got {percentiles}"
|
|
1181
|
+
)
|
|
1182
|
+
ome_zarr.set_channel_percentiles(
|
|
1183
|
+
start_percentile=percentiles[0],
|
|
1184
|
+
end_percentile=percentiles[1],
|
|
1020
1185
|
)
|
|
1021
1186
|
return ome_zarr
|