ngio 0.1.6__py3-none-any.whl → 0.2.0a2__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.
Files changed (84) hide show
  1. ngio/__init__.py +31 -5
  2. ngio/common/__init__.py +44 -0
  3. ngio/common/_array_pipe.py +160 -0
  4. ngio/common/_axes_transforms.py +63 -0
  5. ngio/common/_common_types.py +5 -0
  6. ngio/common/_dimensions.py +113 -0
  7. ngio/common/_pyramid.py +223 -0
  8. ngio/{core/roi.py → common/_roi.py} +22 -23
  9. ngio/common/_slicer.py +97 -0
  10. ngio/{pipes/_zoom_utils.py → common/_zoom.py} +2 -78
  11. ngio/hcs/__init__.py +60 -0
  12. ngio/images/__init__.py +23 -0
  13. ngio/images/abstract_image.py +240 -0
  14. ngio/images/create.py +251 -0
  15. ngio/images/image.py +389 -0
  16. ngio/images/label.py +236 -0
  17. ngio/images/omezarr_container.py +535 -0
  18. ngio/ome_zarr_meta/__init__.py +35 -0
  19. ngio/ome_zarr_meta/_generic_handlers.py +320 -0
  20. ngio/ome_zarr_meta/_meta_handlers.py +142 -0
  21. ngio/ome_zarr_meta/ngio_specs/__init__.py +63 -0
  22. ngio/ome_zarr_meta/ngio_specs/_axes.py +481 -0
  23. ngio/ome_zarr_meta/ngio_specs/_channels.py +378 -0
  24. ngio/ome_zarr_meta/ngio_specs/_dataset.py +134 -0
  25. ngio/ome_zarr_meta/ngio_specs/_ngio_hcs.py +5 -0
  26. ngio/ome_zarr_meta/ngio_specs/_ngio_image.py +434 -0
  27. ngio/ome_zarr_meta/ngio_specs/_pixel_size.py +84 -0
  28. ngio/ome_zarr_meta/v04/__init__.py +11 -0
  29. ngio/ome_zarr_meta/v04/_meta_handlers.py +54 -0
  30. ngio/ome_zarr_meta/v04/_v04_spec_utils.py +412 -0
  31. ngio/tables/__init__.py +21 -5
  32. ngio/tables/_validators.py +192 -0
  33. ngio/tables/backends/__init__.py +8 -0
  34. ngio/tables/backends/_abstract_backend.py +71 -0
  35. ngio/tables/backends/_anndata_utils.py +194 -0
  36. ngio/tables/backends/_anndata_v1.py +75 -0
  37. ngio/tables/backends/_json_v1.py +56 -0
  38. ngio/tables/backends/_table_backends.py +102 -0
  39. ngio/tables/tables_container.py +300 -0
  40. ngio/tables/v1/__init__.py +6 -5
  41. ngio/tables/v1/_feature_table.py +161 -0
  42. ngio/tables/v1/_generic_table.py +99 -182
  43. ngio/tables/v1/_masking_roi_table.py +175 -0
  44. ngio/tables/v1/_roi_table.py +226 -0
  45. ngio/utils/__init__.py +23 -10
  46. ngio/utils/_datasets.py +51 -0
  47. ngio/utils/_errors.py +10 -4
  48. ngio/utils/_zarr_utils.py +378 -0
  49. {ngio-0.1.6.dist-info → ngio-0.2.0a2.dist-info}/METADATA +18 -39
  50. ngio-0.2.0a2.dist-info/RECORD +53 -0
  51. ngio/core/__init__.py +0 -7
  52. ngio/core/dimensions.py +0 -122
  53. ngio/core/image_handler.py +0 -228
  54. ngio/core/image_like_handler.py +0 -549
  55. ngio/core/label_handler.py +0 -410
  56. ngio/core/ngff_image.py +0 -387
  57. ngio/core/utils.py +0 -287
  58. ngio/io/__init__.py +0 -19
  59. ngio/io/_zarr.py +0 -88
  60. ngio/io/_zarr_array_utils.py +0 -0
  61. ngio/io/_zarr_group_utils.py +0 -60
  62. ngio/iterators/__init__.py +0 -1
  63. ngio/ngff_meta/__init__.py +0 -27
  64. ngio/ngff_meta/fractal_image_meta.py +0 -1267
  65. ngio/ngff_meta/meta_handler.py +0 -92
  66. ngio/ngff_meta/utils.py +0 -235
  67. ngio/ngff_meta/v04/__init__.py +0 -6
  68. ngio/ngff_meta/v04/specs.py +0 -158
  69. ngio/ngff_meta/v04/zarr_utils.py +0 -376
  70. ngio/pipes/__init__.py +0 -7
  71. ngio/pipes/_slicer_transforms.py +0 -176
  72. ngio/pipes/_transforms.py +0 -33
  73. ngio/pipes/data_pipe.py +0 -52
  74. ngio/tables/_ad_reader.py +0 -80
  75. ngio/tables/_utils.py +0 -301
  76. ngio/tables/tables_group.py +0 -252
  77. ngio/tables/v1/feature_tables.py +0 -182
  78. ngio/tables/v1/masking_roi_tables.py +0 -243
  79. ngio/tables/v1/roi_tables.py +0 -285
  80. ngio/utils/_common_types.py +0 -5
  81. ngio/utils/_pydantic_utils.py +0 -52
  82. ngio-0.1.6.dist-info/RECORD +0 -44
  83. {ngio-0.1.6.dist-info → ngio-0.2.0a2.dist-info}/WHEEL +0 -0
  84. {ngio-0.1.6.dist-info → ngio-0.2.0a2.dist-info}/licenses/LICENSE +0 -0
ngio/io/_zarr.py DELETED
@@ -1,88 +0,0 @@
1
- from importlib.metadata import version
2
- from pathlib import Path
3
- from typing import Literal
4
-
5
- import zarr
6
- from packaging.version import Version
7
-
8
- from ngio.utils import NgioFileExistsError, NgioFileNotFoundError
9
-
10
- zarr_version = version("zarr")
11
- ZARR_PYTHON_V = 2 if Version(zarr_version) < Version("3.0.0a") else 3
12
-
13
- if ZARR_PYTHON_V == 2:
14
- from zarr.errors import ContainsGroupError, GroupNotFoundError
15
-
16
- # Zarr v3 Imports
17
- # import zarr.store
18
- # from zarr.core.common import AccessModeLiteral, ZarrFormat
19
- # from zarr.store.common import StoreLike
20
-
21
- AccessModeLiteral = Literal["r", "r+", "w", "w-", "a"]
22
- ZarrFormat = Literal[2, 3]
23
- StoreLike = str | Path # This type alias more narrrow than necessary
24
- StoreOrGroup = StoreLike | zarr.Group
25
-
26
-
27
- class ZarrV3Error(Exception):
28
- pass
29
-
30
-
31
- def _pass_through_group(
32
- group: zarr.Group, mode: AccessModeLiteral, zarr_format: ZarrFormat = 2
33
- ) -> zarr.Group:
34
- if ZARR_PYTHON_V == 2:
35
- if zarr_format == 3:
36
- raise ZarrV3Error("Zarr v3 is not supported in when using zarr-python v2.")
37
- else:
38
- return group
39
-
40
- else:
41
- if group.metadata.zarr_format != zarr_format:
42
- raise ValueError(
43
- f"Zarr format mismatch. Expected {zarr_format}, "
44
- "got {store.metadata.zarr_format}."
45
- )
46
- else:
47
- return group
48
-
49
- raise ValueError("This should never be reached.")
50
-
51
-
52
- def _open_group_v2_v3(
53
- store: StoreOrGroup, mode: AccessModeLiteral, zarr_format: ZarrFormat = 2
54
- ) -> zarr.Group:
55
- """Wrapper around zarr.open_group with some additional checks.
56
-
57
- Args:
58
- store (StoreOrGroup): The store (can also be a Path/str) or group to open.
59
- mode (ReadOrEdirLiteral): The mode to open the group in.
60
- zarr_format (ZarrFormat): The Zarr format to use.
61
-
62
- Returns:
63
- zarr.Group: The opened Zarr group.
64
- """
65
- if ZARR_PYTHON_V == 3:
66
- return zarr.open_group(store=store, mode=mode, zarr_format=zarr_format)
67
- else:
68
- try:
69
- group = zarr.open_group(store=store, mode=mode)
70
-
71
- except ContainsGroupError as e:
72
- raise NgioFileExistsError(
73
- f"A Zarr group already exists at {store}, "
74
- "consider setting overwrite=True."
75
- ) from e
76
-
77
- except GroupNotFoundError as e:
78
- raise NgioFileNotFoundError(f"No Zarr group found at {store}") from e
79
-
80
- return group
81
-
82
-
83
- def _is_group_readonly(group: zarr.Group) -> bool:
84
- if ZARR_PYTHON_V == 3:
85
- return group.store_path.store.mode.readonly
86
-
87
- else:
88
- return not group.store.is_writeable()
File without changes
@@ -1,60 +0,0 @@
1
- from pathlib import Path
2
-
3
- import fsspec
4
- import zarr
5
-
6
- from ngio.io._zarr import (
7
- AccessModeLiteral,
8
- StoreLike,
9
- StoreOrGroup,
10
- ZarrFormat,
11
- _open_group_v2_v3,
12
- _pass_through_group,
13
- )
14
- from ngio.utils import ngio_logger
15
-
16
- # Zarr v3 Imports
17
- # import zarr.store
18
- # from zarr.core.common import AccessModeLiteral, ZarrFormat
19
- # from zarr.store.common import StoreLike
20
-
21
-
22
- def _check_store(store: StoreLike) -> StoreLike:
23
- if isinstance(store, str) or isinstance(store, Path):
24
- return store
25
-
26
- if isinstance(store, fsspec.mapping.FSMap) or isinstance(
27
- store, zarr.storage.FSStore
28
- ):
29
- return store
30
-
31
- raise NotImplementedError(
32
- f"Store type {type(store)} is not supported. supported types are: "
33
- "str, Path, fsspec.mapping.FSMap, zarr.storage.FSStore"
34
- )
35
-
36
-
37
- def open_group_wrapper(
38
- store: StoreOrGroup, mode: AccessModeLiteral, zarr_format: ZarrFormat = 2
39
- ) -> zarr.Group:
40
- """Wrapper around zarr.open_group with some additional checks.
41
-
42
- Args:
43
- store (StoreOrGroup): The store (can also be a Path/str) or group to open.
44
- mode (ReadOrEdirLiteral): The mode to open the group in.
45
- zarr_format (ZarrFormat): The Zarr format to use.
46
-
47
- Returns:
48
- zarr.Group: The opened Zarr group.
49
- """
50
- if isinstance(store, zarr.Group):
51
- _group = _pass_through_group(store, mode=mode, zarr_format=zarr_format)
52
- ngio_logger.debug(
53
- f"Passing through group: {_group}, located in store: {_group.store.path}"
54
- )
55
- return _group
56
-
57
- store = _check_store(store)
58
- _group = _open_group_v2_v3(store=store, mode=mode, zarr_format=zarr_format)
59
- ngio_logger.debug(f"Opened located in store: {store}")
60
- return _group
@@ -1 +0,0 @@
1
- """Ngio iterators module."""
@@ -1,27 +0,0 @@
1
- """IO and validation of NGFF metadata."""
2
-
3
- from ngio.ngff_meta.fractal_image_meta import (
4
- Dataset,
5
- ImageLabelMeta,
6
- ImageMeta,
7
- LabelMeta,
8
- PixelSize,
9
- SpaceUnits,
10
- )
11
- from ngio.ngff_meta.meta_handler import get_ngff_image_meta_handler
12
- from ngio.ngff_meta.utils import (
13
- create_image_metadata,
14
- create_label_metadata,
15
- )
16
-
17
- __all__ = [
18
- "Dataset",
19
- "ImageMeta",
20
- "LabelMeta",
21
- "ImageLabelMeta",
22
- "PixelSize",
23
- "SpaceUnits",
24
- "get_ngff_image_meta_handler",
25
- "create_image_metadata",
26
- "create_label_metadata",
27
- ]