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