ngio 0.4.8__py3-none-any.whl → 0.5.0a1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ngio/common/_pyramid.py +41 -28
- ngio/images/_create.py +23 -16
- ngio/images/_create_synt_container.py +9 -8
- ngio/images/_image.py +26 -16
- ngio/images/_label.py +15 -15
- ngio/images/_ome_zarr_container.py +29 -29
- ngio/ome_zarr_meta/_meta_handlers.py +29 -0
- ngio/ome_zarr_meta/ngio_specs/_ngio_image.py +12 -1
- ngio/ome_zarr_meta/v04/_v04_spec_utils.py +2 -2
- ngio/ome_zarr_meta/v05/__init__.py +23 -0
- ngio/ome_zarr_meta/v05/_custom_models.py +18 -0
- ngio/ome_zarr_meta/v05/_v05_spec_utils.py +518 -0
- ngio/tables/_tables_container.py +3 -3
- ngio/tables/backends/_abstract_backend.py +7 -0
- ngio/tables/backends/_anndata.py +4 -1
- ngio/tables/backends/_anndata_utils.py +4 -1
- ngio/tables/backends/_non_zarr_backends.py +6 -6
- ngio/tables/backends/_utils.py +1 -1
- ngio/tables/v1/_roi_table.py +3 -3
- ngio/utils/_datasets.py +0 -6
- ngio/utils/_zarr_utils.py +108 -32
- {ngio-0.4.8.dist-info → ngio-0.5.0a1.dist-info}/METADATA +6 -6
- {ngio-0.4.8.dist-info → ngio-0.5.0a1.dist-info}/RECORD +25 -22
- {ngio-0.4.8.dist-info → ngio-0.5.0a1.dist-info}/WHEEL +1 -1
- {ngio-0.4.8.dist-info → ngio-0.5.0a1.dist-info}/licenses/LICENSE +0 -0
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
import warnings
|
|
4
4
|
from collections.abc import Sequence
|
|
5
|
+
from typing import Literal
|
|
5
6
|
|
|
6
7
|
import numpy as np
|
|
7
|
-
from zarr.
|
|
8
|
+
from zarr.core.array import CompressorLike
|
|
8
9
|
|
|
9
10
|
from ngio.images._create import create_empty_image_container
|
|
10
11
|
from ngio.images._image import Image, ImagesContainer
|
|
@@ -409,10 +410,11 @@ class OmeZarrContainer:
|
|
|
409
410
|
name: str | None = None,
|
|
410
411
|
chunks: Sequence[int] | None = None,
|
|
411
412
|
dtype: str | None = None,
|
|
412
|
-
dimension_separator:
|
|
413
|
-
|
|
413
|
+
dimension_separator: Literal[".", "/"] | None = None,
|
|
414
|
+
compressors: CompressorLike | None = None,
|
|
414
415
|
copy_labels: bool = False,
|
|
415
416
|
copy_tables: bool = False,
|
|
417
|
+
ngff_version: NgffVersions | None = None,
|
|
416
418
|
overwrite: bool = False,
|
|
417
419
|
) -> "OmeZarrContainer":
|
|
418
420
|
"""Create an empty OME-Zarr container from an existing image.
|
|
@@ -431,17 +433,18 @@ class OmeZarrContainer:
|
|
|
431
433
|
dimension_separator (DIMENSION_SEPARATOR | None): The dimension
|
|
432
434
|
separator to use. If None, the dimension separator of the
|
|
433
435
|
reference image will be used.
|
|
434
|
-
|
|
435
|
-
reference image will be used.
|
|
436
|
+
compressors (CompressorLike | None): The compressors to use. If None,
|
|
437
|
+
the compressors of the reference image will be used.
|
|
436
438
|
copy_labels (bool): Whether to copy the labels from the reference image.
|
|
437
439
|
copy_tables (bool): Whether to copy the tables from the reference image.
|
|
440
|
+
ngff_version (NgffVersions): The NGFF version to use.
|
|
438
441
|
overwrite (bool): Whether to overwrite an existing image.
|
|
439
442
|
|
|
440
443
|
Returns:
|
|
441
444
|
OmeZarrContainer: The new image container.
|
|
442
445
|
|
|
443
446
|
"""
|
|
444
|
-
|
|
447
|
+
new_container = self._images_container.derive(
|
|
445
448
|
store=store,
|
|
446
449
|
ref_path=ref_path,
|
|
447
450
|
shape=shape,
|
|
@@ -452,16 +455,13 @@ class OmeZarrContainer:
|
|
|
452
455
|
chunks=chunks,
|
|
453
456
|
dtype=dtype,
|
|
454
457
|
dimension_separator=dimension_separator,
|
|
455
|
-
|
|
458
|
+
compressors=compressors,
|
|
459
|
+
ngff_version=ngff_version,
|
|
456
460
|
overwrite=overwrite,
|
|
457
461
|
)
|
|
458
462
|
|
|
459
|
-
handler = ZarrGroupHandler(
|
|
460
|
-
store, cache=self._group_handler.use_cache, mode=self._group_handler.mode
|
|
461
|
-
)
|
|
462
|
-
|
|
463
463
|
new_ome_zarr = OmeZarrContainer(
|
|
464
|
-
group_handler=
|
|
464
|
+
group_handler=new_container._group_handler,
|
|
465
465
|
validate_paths=False,
|
|
466
466
|
)
|
|
467
467
|
|
|
@@ -693,8 +693,8 @@ class OmeZarrContainer:
|
|
|
693
693
|
axes_names: Sequence[str] | None = None,
|
|
694
694
|
chunks: Sequence[int] | None = None,
|
|
695
695
|
dtype: str = "uint32",
|
|
696
|
-
dimension_separator:
|
|
697
|
-
|
|
696
|
+
dimension_separator: Literal[".", "/"] | None = None,
|
|
697
|
+
compressors: CompressorLike | None = None,
|
|
698
698
|
overwrite: bool = False,
|
|
699
699
|
) -> "Label":
|
|
700
700
|
"""Create an empty OME-Zarr label from a reference image.
|
|
@@ -714,8 +714,8 @@ class OmeZarrContainer:
|
|
|
714
714
|
dimension_separator (DIMENSION_SEPARATOR | None): The dimension
|
|
715
715
|
separator to use. If None, the dimension separator of the
|
|
716
716
|
reference image will be used.
|
|
717
|
-
|
|
718
|
-
reference image will be used.
|
|
717
|
+
compressors (CompressorLike | None): The compressors to use. If None,
|
|
718
|
+
the compressors of the reference image will be used.
|
|
719
719
|
overwrite (bool): Whether to overwrite an existing image.
|
|
720
720
|
|
|
721
721
|
Returns:
|
|
@@ -733,7 +733,7 @@ class OmeZarrContainer:
|
|
|
733
733
|
chunks=chunks,
|
|
734
734
|
dtype=dtype,
|
|
735
735
|
dimension_separator=dimension_separator,
|
|
736
|
-
|
|
736
|
+
compressors=compressors,
|
|
737
737
|
overwrite=overwrite,
|
|
738
738
|
)
|
|
739
739
|
|
|
@@ -773,7 +773,7 @@ def open_image(
|
|
|
773
773
|
mode (AccessModeLiteral): The
|
|
774
774
|
access mode for the image. Defaults to "r+".
|
|
775
775
|
"""
|
|
776
|
-
group_handler = ZarrGroupHandler(store, cache, mode)
|
|
776
|
+
group_handler = ZarrGroupHandler(store=store, cache=cache, mode=mode)
|
|
777
777
|
images_container = ImagesContainer(group_handler)
|
|
778
778
|
return images_container.get(
|
|
779
779
|
path=path,
|
|
@@ -806,7 +806,7 @@ def open_label(
|
|
|
806
806
|
mode (AccessModeLiteral): The access mode for the image. Defaults to "r+".
|
|
807
807
|
|
|
808
808
|
"""
|
|
809
|
-
group_handler = ZarrGroupHandler(store, cache, mode)
|
|
809
|
+
group_handler = ZarrGroupHandler(store=store, cache=cache, mode=mode)
|
|
810
810
|
if name is None:
|
|
811
811
|
label_meta_handler = find_label_meta_handler(group_handler)
|
|
812
812
|
path = label_meta_handler.meta.get_dataset(
|
|
@@ -836,10 +836,10 @@ def create_empty_ome_zarr(
|
|
|
836
836
|
time_unit: TimeUnits = DefaultTimeUnit,
|
|
837
837
|
axes_names: Sequence[str] | None = None,
|
|
838
838
|
name: str | None = None,
|
|
839
|
-
chunks: Sequence[int] |
|
|
839
|
+
chunks: Sequence[int] | Literal["auto"] = "auto",
|
|
840
840
|
dtype: str = "uint16",
|
|
841
|
-
dimension_separator:
|
|
842
|
-
|
|
841
|
+
dimension_separator: Literal[".", "/"] = "/",
|
|
842
|
+
compressors: CompressorLike = "auto",
|
|
843
843
|
channel_labels: list[str] | None = None,
|
|
844
844
|
channel_wavelengths: list[str] | None = None,
|
|
845
845
|
channel_colors: Sequence[str] | None = None,
|
|
@@ -874,7 +874,7 @@ def create_empty_ome_zarr(
|
|
|
874
874
|
dtype (str, optional): The data type of the image. Defaults to "uint16".
|
|
875
875
|
dimension_separator (DIMENSION_SEPARATOR): The dimension
|
|
876
876
|
separator to use. Defaults to "/".
|
|
877
|
-
|
|
877
|
+
compressors (CompressorLike): The compressor to use. Defaults to "auto".
|
|
878
878
|
channel_labels (list[str] | None, optional): The labels of the channels.
|
|
879
879
|
Defaults to None.
|
|
880
880
|
channel_wavelengths (list[str] | None, optional): The wavelengths of the
|
|
@@ -904,7 +904,7 @@ def create_empty_ome_zarr(
|
|
|
904
904
|
chunks=chunks,
|
|
905
905
|
dtype=dtype,
|
|
906
906
|
dimension_separator=dimension_separator,
|
|
907
|
-
|
|
907
|
+
compressors=compressors,
|
|
908
908
|
overwrite=overwrite,
|
|
909
909
|
version=version,
|
|
910
910
|
)
|
|
@@ -938,9 +938,9 @@ def create_ome_zarr_from_array(
|
|
|
938
938
|
channel_colors: Sequence[str] | None = None,
|
|
939
939
|
channel_active: Sequence[bool] | None = None,
|
|
940
940
|
name: str | None = None,
|
|
941
|
-
chunks: Sequence[int] |
|
|
942
|
-
dimension_separator:
|
|
943
|
-
|
|
941
|
+
chunks: Sequence[int] | Literal["auto"] = "auto",
|
|
942
|
+
dimension_separator: Literal[".", "/"] = "/",
|
|
943
|
+
compressors: CompressorLike = "auto",
|
|
944
944
|
overwrite: bool = False,
|
|
945
945
|
version: NgffVersions = DefaultNgffVersion,
|
|
946
946
|
) -> OmeZarrContainer:
|
|
@@ -980,7 +980,7 @@ def create_ome_zarr_from_array(
|
|
|
980
980
|
active. Defaults to None.
|
|
981
981
|
dimension_separator (DIMENSION_SEPARATOR): The separator to use for
|
|
982
982
|
dimensions. Defaults to "/".
|
|
983
|
-
|
|
983
|
+
compressors (CompressorLike): The compressors to use. Defaults to "auto".
|
|
984
984
|
overwrite (bool, optional): Whether to overwrite an existing image.
|
|
985
985
|
Defaults to True.
|
|
986
986
|
version (str, optional): The version of the OME-Zarr specification.
|
|
@@ -1003,7 +1003,7 @@ def create_ome_zarr_from_array(
|
|
|
1003
1003
|
dtype=str(array.dtype),
|
|
1004
1004
|
overwrite=overwrite,
|
|
1005
1005
|
dimension_separator=dimension_separator,
|
|
1006
|
-
|
|
1006
|
+
compressors=compressors,
|
|
1007
1007
|
version=version,
|
|
1008
1008
|
)
|
|
1009
1009
|
|
|
@@ -21,6 +21,16 @@ from ngio.ome_zarr_meta.v04 import (
|
|
|
21
21
|
v04_to_ngio_plate_meta,
|
|
22
22
|
v04_to_ngio_well_meta,
|
|
23
23
|
)
|
|
24
|
+
from ngio.ome_zarr_meta.v05 import (
|
|
25
|
+
ngio_to_v05_image_meta,
|
|
26
|
+
ngio_to_v05_label_meta,
|
|
27
|
+
ngio_to_v05_plate_meta,
|
|
28
|
+
ngio_to_v05_well_meta,
|
|
29
|
+
v05_to_ngio_image_meta,
|
|
30
|
+
v05_to_ngio_label_meta,
|
|
31
|
+
v05_to_ngio_plate_meta,
|
|
32
|
+
v05_to_ngio_well_meta,
|
|
33
|
+
)
|
|
24
34
|
from ngio.utils import (
|
|
25
35
|
NgioValidationError,
|
|
26
36
|
NgioValueError,
|
|
@@ -678,17 +688,36 @@ ImplementedMetaImporterExporter().register_image_ie(
|
|
|
678
688
|
importer=v04_to_ngio_image_meta,
|
|
679
689
|
exporter=ngio_to_v04_image_meta,
|
|
680
690
|
)
|
|
691
|
+
|
|
692
|
+
ImplementedMetaImporterExporter().register_label_ie(
|
|
693
|
+
version="0.5",
|
|
694
|
+
importer=v05_to_ngio_label_meta,
|
|
695
|
+
exporter=ngio_to_v05_label_meta,
|
|
696
|
+
)
|
|
697
|
+
|
|
681
698
|
ImplementedMetaImporterExporter().register_label_ie(
|
|
682
699
|
version="0.4",
|
|
683
700
|
importer=v04_to_ngio_label_meta,
|
|
684
701
|
exporter=ngio_to_v04_label_meta,
|
|
685
702
|
)
|
|
703
|
+
ImplementedMetaImporterExporter().register_image_ie(
|
|
704
|
+
version="0.5",
|
|
705
|
+
importer=v05_to_ngio_image_meta,
|
|
706
|
+
exporter=ngio_to_v05_image_meta,
|
|
707
|
+
)
|
|
708
|
+
|
|
686
709
|
ImplementedMetaImporterExporter().register_well_ie(
|
|
687
710
|
version="0.4", importer=v04_to_ngio_well_meta, exporter=ngio_to_v04_well_meta
|
|
688
711
|
)
|
|
712
|
+
ImplementedMetaImporterExporter().register_well_ie(
|
|
713
|
+
version="0.5", importer=v05_to_ngio_well_meta, exporter=ngio_to_v05_well_meta
|
|
714
|
+
)
|
|
689
715
|
ImplementedMetaImporterExporter().register_plate_ie(
|
|
690
716
|
version="0.4", importer=v04_to_ngio_plate_meta, exporter=ngio_to_v04_plate_meta
|
|
691
717
|
)
|
|
718
|
+
ImplementedMetaImporterExporter().register_plate_ie(
|
|
719
|
+
version="0.5", importer=v05_to_ngio_plate_meta, exporter=ngio_to_v05_plate_meta
|
|
720
|
+
)
|
|
692
721
|
|
|
693
722
|
|
|
694
723
|
###########################################################################
|
|
@@ -25,7 +25,7 @@ from ngio.ome_zarr_meta.ngio_specs._pixel_size import PixelSize
|
|
|
25
25
|
from ngio.utils import NgioValidationError, NgioValueError
|
|
26
26
|
|
|
27
27
|
T = TypeVar("T")
|
|
28
|
-
NgffVersions = Literal["0.4"]
|
|
28
|
+
NgffVersions = Literal["0.4", "0.5"]
|
|
29
29
|
DefaultNgffVersion: Literal["0.4"] = "0.4"
|
|
30
30
|
|
|
31
31
|
|
|
@@ -146,6 +146,17 @@ class AbstractNgioImageMeta:
|
|
|
146
146
|
"""Version of the OME-NFF metadata used to build the object."""
|
|
147
147
|
return self._version # type: ignore (version is a Literal type)
|
|
148
148
|
|
|
149
|
+
@property
|
|
150
|
+
def zarr_format(self) -> Literal[2, 3]:
|
|
151
|
+
"""Zarr version used to store the data."""
|
|
152
|
+
match self.version:
|
|
153
|
+
case "0.4":
|
|
154
|
+
return 2
|
|
155
|
+
case "0.5":
|
|
156
|
+
return 3
|
|
157
|
+
case _:
|
|
158
|
+
raise NgioValueError(f"Unsupported NGFF version: {self.version}")
|
|
159
|
+
|
|
149
160
|
@property
|
|
150
161
|
def name(self) -> str | None:
|
|
151
162
|
"""Name of the image."""
|
|
@@ -9,7 +9,6 @@ For Images and Labels implements the following functionalities:
|
|
|
9
9
|
- A function to convert a ngio image metadata to a v04 image metadata.
|
|
10
10
|
"""
|
|
11
11
|
|
|
12
|
-
from ome_zarr_models.common.multiscales import ValidTransform as ValidTransformV04
|
|
13
12
|
from ome_zarr_models.v04.axes import Axis as AxisV04
|
|
14
13
|
from ome_zarr_models.v04.coordinate_transformations import VectorScale as VectorScaleV04
|
|
15
14
|
from ome_zarr_models.v04.coordinate_transformations import (
|
|
@@ -20,6 +19,7 @@ from ome_zarr_models.v04.image import ImageAttrs as ImageAttrsV04
|
|
|
20
19
|
from ome_zarr_models.v04.image_label import ImageLabelAttrs as LabelAttrsV04
|
|
21
20
|
from ome_zarr_models.v04.multiscales import Dataset as DatasetV04
|
|
22
21
|
from ome_zarr_models.v04.multiscales import Multiscale as MultiscaleV04
|
|
22
|
+
from ome_zarr_models.v04.multiscales import ValidTransform as ValidTransformV04
|
|
23
23
|
from ome_zarr_models.v04.omero import Channel as ChannelV04
|
|
24
24
|
from ome_zarr_models.v04.omero import Omero as OmeroV04
|
|
25
25
|
from ome_zarr_models.v04.omero import Window as WindowV04
|
|
@@ -169,7 +169,7 @@ def _v04_to_ngio_datasets(
|
|
|
169
169
|
unit = str(unit)
|
|
170
170
|
axes.append(
|
|
171
171
|
Axis(
|
|
172
|
-
name=v04_axis.name,
|
|
172
|
+
name=str(v04_axis.name),
|
|
173
173
|
axis_type=AxisType(v04_axis.type),
|
|
174
174
|
# (for some reason the type is a generic JsonValue,
|
|
175
175
|
# but it should be a string or None)
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""Utility to read/write OME-Zarr metadata v0.4."""
|
|
2
|
+
|
|
3
|
+
from ngio.ome_zarr_meta.v05._v05_spec_utils import (
|
|
4
|
+
ngio_to_v05_image_meta,
|
|
5
|
+
ngio_to_v05_label_meta,
|
|
6
|
+
ngio_to_v05_plate_meta,
|
|
7
|
+
ngio_to_v05_well_meta,
|
|
8
|
+
v05_to_ngio_image_meta,
|
|
9
|
+
v05_to_ngio_label_meta,
|
|
10
|
+
v05_to_ngio_plate_meta,
|
|
11
|
+
v05_to_ngio_well_meta,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"ngio_to_v05_image_meta",
|
|
16
|
+
"ngio_to_v05_label_meta",
|
|
17
|
+
"ngio_to_v05_plate_meta",
|
|
18
|
+
"ngio_to_v05_well_meta",
|
|
19
|
+
"v05_to_ngio_image_meta",
|
|
20
|
+
"v05_to_ngio_label_meta",
|
|
21
|
+
"v05_to_ngio_plate_meta",
|
|
22
|
+
"v05_to_ngio_well_meta",
|
|
23
|
+
]
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from typing import Annotated
|
|
2
|
+
|
|
3
|
+
from ome_zarr_models.v05.well import WellAttrs as WellAttrs05
|
|
4
|
+
from ome_zarr_models.v05.well_types import WellImage as WellImage05
|
|
5
|
+
from ome_zarr_models.v05.well_types import WellMeta as WellMeta05
|
|
6
|
+
from pydantic import SkipValidation
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class CustomWellImage(WellImage05):
|
|
10
|
+
path: Annotated[str, SkipValidation]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class CustomWellMeta(WellMeta05):
|
|
14
|
+
images: list[CustomWellImage] # type: ignore[valid-type]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class CustomWellAttrs(WellAttrs05):
|
|
18
|
+
well: CustomWellMeta # type: ignore[valid-type]
|