ngio 0.3.5__py3-none-any.whl → 0.4.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.
Files changed (61) hide show
  1. ngio/__init__.py +6 -0
  2. ngio/common/__init__.py +50 -48
  3. ngio/common/_array_io_pipes.py +549 -0
  4. ngio/common/_array_io_utils.py +508 -0
  5. ngio/common/_dimensions.py +63 -27
  6. ngio/common/_masking_roi.py +38 -10
  7. ngio/common/_pyramid.py +9 -7
  8. ngio/common/_roi.py +571 -72
  9. ngio/common/_synt_images_utils.py +101 -0
  10. ngio/common/_zoom.py +17 -12
  11. ngio/common/transforms/__init__.py +5 -0
  12. ngio/common/transforms/_label.py +12 -0
  13. ngio/common/transforms/_zoom.py +109 -0
  14. ngio/experimental/__init__.py +5 -0
  15. ngio/experimental/iterators/__init__.py +17 -0
  16. ngio/experimental/iterators/_abstract_iterator.py +170 -0
  17. ngio/experimental/iterators/_feature.py +151 -0
  18. ngio/experimental/iterators/_image_processing.py +169 -0
  19. ngio/experimental/iterators/_rois_utils.py +127 -0
  20. ngio/experimental/iterators/_segmentation.py +278 -0
  21. ngio/hcs/_plate.py +41 -36
  22. ngio/images/__init__.py +22 -1
  23. ngio/images/_abstract_image.py +247 -117
  24. ngio/images/_create.py +15 -15
  25. ngio/images/_create_synt_container.py +128 -0
  26. ngio/images/_image.py +425 -62
  27. ngio/images/_label.py +33 -30
  28. ngio/images/_masked_image.py +396 -122
  29. ngio/images/_ome_zarr_container.py +203 -66
  30. ngio/{common → images}/_table_ops.py +41 -41
  31. ngio/ome_zarr_meta/ngio_specs/__init__.py +2 -8
  32. ngio/ome_zarr_meta/ngio_specs/_axes.py +151 -128
  33. ngio/ome_zarr_meta/ngio_specs/_channels.py +55 -18
  34. ngio/ome_zarr_meta/ngio_specs/_dataset.py +7 -7
  35. ngio/ome_zarr_meta/ngio_specs/_ngio_hcs.py +3 -3
  36. ngio/ome_zarr_meta/ngio_specs/_ngio_image.py +11 -68
  37. ngio/ome_zarr_meta/v04/_v04_spec_utils.py +1 -1
  38. ngio/resources/20200812-CardiomyocyteDifferentiation14-Cycle1_B03/mask.png +0 -0
  39. ngio/resources/20200812-CardiomyocyteDifferentiation14-Cycle1_B03/nuclei.png +0 -0
  40. ngio/resources/20200812-CardiomyocyteDifferentiation14-Cycle1_B03/raw.jpg +0 -0
  41. ngio/resources/__init__.py +54 -0
  42. ngio/resources/resource_model.py +35 -0
  43. ngio/tables/backends/_abstract_backend.py +5 -6
  44. ngio/tables/backends/_anndata.py +1 -1
  45. ngio/tables/backends/_anndata_utils.py +3 -3
  46. ngio/tables/backends/_non_zarr_backends.py +1 -1
  47. ngio/tables/backends/_table_backends.py +0 -1
  48. ngio/tables/backends/_utils.py +3 -3
  49. ngio/tables/v1/_roi_table.py +156 -69
  50. ngio/utils/__init__.py +2 -3
  51. ngio/utils/_logger.py +19 -0
  52. ngio/utils/_zarr_utils.py +1 -5
  53. {ngio-0.3.5.dist-info → ngio-0.4.0a1.dist-info}/METADATA +3 -1
  54. ngio-0.4.0a1.dist-info/RECORD +76 -0
  55. ngio/common/_array_pipe.py +0 -288
  56. ngio/common/_axes_transforms.py +0 -64
  57. ngio/common/_common_types.py +0 -5
  58. ngio/common/_slicer.py +0 -96
  59. ngio-0.3.5.dist-info/RECORD +0 -61
  60. {ngio-0.3.5.dist-info → ngio-0.4.0a1.dist-info}/WHEEL +0 -0
  61. {ngio-0.3.5.dist-info → ngio-0.4.0a1.dist-info}/licenses/LICENSE +0 -0
ngio/images/_label.py CHANGED
@@ -1,12 +1,10 @@
1
1
  """A module for handling label images in OME-NGFF files."""
2
2
 
3
- from collections.abc import Collection
3
+ from collections.abc import Sequence
4
4
  from typing import Literal
5
5
 
6
- import dask.array as da
7
-
8
6
  from ngio.common import compute_masking_roi
9
- from ngio.images._abstract_image import AbstractImage, consolidate_image
7
+ from ngio.images._abstract_image import AbstractImage
10
8
  from ngio.images._create import create_empty_label_container
11
9
  from ngio.images._image import Image
12
10
  from ngio.ome_zarr_meta import (
@@ -33,6 +31,15 @@ from ngio.utils import (
33
31
  class Label(AbstractImage[LabelMetaHandler]):
34
32
  """Placeholder class for a label."""
35
33
 
34
+ get_as_numpy = AbstractImage._get_as_numpy
35
+ get_as_dask = AbstractImage._get_as_dask
36
+ get_array = AbstractImage._get_array
37
+ get_roi_as_numpy = AbstractImage._get_roi_as_numpy
38
+ get_roi_as_dask = AbstractImage._get_roi_as_dask
39
+ get_roi = AbstractImage._get_roi
40
+ set_array = AbstractImage._set_array
41
+ set_roi = AbstractImage._set_roi
42
+
36
43
  def __init__(
37
44
  self,
38
45
  group_handler: ZarrGroupHandler,
@@ -86,7 +93,10 @@ class Label(AbstractImage[LabelMetaHandler]):
86
93
  mode: Literal["dask", "numpy", "coarsen"] = "dask",
87
94
  ) -> None:
88
95
  """Consolidate the label on disk."""
89
- consolidate_image(self, mode=mode, order=0)
96
+ self._consolidate(
97
+ order=0,
98
+ mode=mode,
99
+ )
90
100
 
91
101
 
92
102
  class LabelsContainer:
@@ -152,11 +162,11 @@ class LabelsContainer:
152
162
  self,
153
163
  name: str,
154
164
  ref_image: Image | Label,
155
- shape: Collection[int] | None = None,
165
+ shape: Sequence[int] | None = None,
156
166
  pixel_size: PixelSize | None = None,
157
- axes_names: Collection[str] | None = None,
158
- chunks: Collection[int] | None = None,
159
- dtype: str | None = None,
167
+ axes_names: Sequence[str] | None = None,
168
+ chunks: Sequence[int] | None = None,
169
+ dtype: str = "uint32",
160
170
  overwrite: bool = False,
161
171
  ) -> "Label":
162
172
  """Create an empty OME-Zarr label from a reference image.
@@ -168,12 +178,12 @@ class LabelsContainer:
168
178
  ref_image (Image | Label): A reference image that will be used to create
169
179
  the new image.
170
180
  name (str): The name of the new image.
171
- shape (Collection[int] | None): The shape of the new image.
181
+ shape (Sequence[int] | None): The shape of the new image.
172
182
  pixel_size (PixelSize | None): The pixel size of the new image.
173
- axes_names (Collection[str] | None): The axes names of the new image.
183
+ axes_names (Sequence[str] | None): The axes names of the new image.
174
184
  For labels, the channel axis is not allowed.
175
- chunks (Collection[int] | None): The chunk shape of the new image.
176
- dtype (str | None): The data type of the new image.
185
+ chunks (Sequence[int] | None): The chunk shape of the new image.
186
+ dtype (str): The data type of the new label.
177
187
  overwrite (bool): Whether to overwrite an existing image.
178
188
 
179
189
  Returns:
@@ -212,11 +222,11 @@ def derive_label(
212
222
  store: StoreOrGroup,
213
223
  ref_image: Image | Label,
214
224
  name: str,
215
- shape: Collection[int] | None = None,
225
+ shape: Sequence[int] | None = None,
216
226
  pixel_size: PixelSize | None = None,
217
- axes_names: Collection[str] | None = None,
218
- chunks: Collection[int] | None = None,
219
- dtype: str | None = None,
227
+ axes_names: Sequence[str] | None = None,
228
+ chunks: Sequence[int] | None = None,
229
+ dtype: str = "uint32",
220
230
  overwrite: bool = False,
221
231
  ) -> None:
222
232
  """Create an empty OME-Zarr label from a reference image.
@@ -226,12 +236,12 @@ def derive_label(
226
236
  ref_image (Image | Label): A reference image that will be used to
227
237
  create the new image.
228
238
  name (str): The name of the new image.
229
- shape (Collection[int] | None): The shape of the new image.
239
+ shape (Sequence[int] | None): The shape of the new image.
230
240
  pixel_size (PixelSize | None): The pixel size of the new image.
231
- axes_names (Collection[str] | None): The axes names of the new image.
241
+ axes_names (Sequence[str] | None): The axes names of the new image.
232
242
  For labels, the channel axis is not allowed.
233
- chunks (Collection[int] | None): The chunk shape of the new image.
234
- dtype (str | None): The data type of the new image.
243
+ chunks (Sequence[int] | None): The chunk shape of the new image.
244
+ dtype (str): The data type of the new label.
235
245
  overwrite (bool): Whether to overwrite an existing image.
236
246
 
237
247
  Returns:
@@ -247,7 +257,7 @@ def derive_label(
247
257
  pixel_size = ref_image.pixel_size
248
258
 
249
259
  if axes_names is None:
250
- axes_names = ref_meta.axes_mapper.on_disk_axes_names
260
+ axes_names = ref_meta.axes_mapper.axes_names
251
261
  c_axis = ref_meta.axes_mapper.get_index("c")
252
262
  else:
253
263
  if "c" in axes_names:
@@ -272,9 +282,6 @@ def derive_label(
272
282
  f"Got {chunks} for shape {shape}."
273
283
  )
274
284
 
275
- if dtype is None:
276
- dtype = ref_image.dtype
277
-
278
285
  if c_axis is not None:
279
286
  # remove channel if present
280
287
  shape = list(shape)
@@ -307,10 +314,6 @@ def derive_label(
307
314
 
308
315
  def build_masking_roi_table(label: Label) -> MaskingRoiTable:
309
316
  """Compute the masking ROI table for a label."""
310
- if label.dimensions.is_time_series:
311
- raise NgioValueError("Time series labels are not supported.")
312
-
313
- array = label.get_array(axes_order=["z", "y", "x"], mode="dask")
314
- assert isinstance(array, da.Array), "Array must be a Dask array."
317
+ array = label.get_as_dask(axes_order=["t", "z", "y", "x"])
315
318
  rois = compute_masking_roi(array, label.pixel_size)
316
319
  return MaskingRoiTable(rois, reference_label=label.meta.name)