ngio 0.3.4__py3-none-any.whl → 0.4.0__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 (73) hide show
  1. ngio/__init__.py +7 -2
  2. ngio/common/__init__.py +5 -52
  3. ngio/common/_dimensions.py +270 -55
  4. ngio/common/_masking_roi.py +38 -10
  5. ngio/common/_pyramid.py +51 -30
  6. ngio/common/_roi.py +269 -82
  7. ngio/common/_synt_images_utils.py +101 -0
  8. ngio/common/_zoom.py +49 -19
  9. ngio/experimental/__init__.py +5 -0
  10. ngio/experimental/iterators/__init__.py +15 -0
  11. ngio/experimental/iterators/_abstract_iterator.py +390 -0
  12. ngio/experimental/iterators/_feature.py +189 -0
  13. ngio/experimental/iterators/_image_processing.py +130 -0
  14. ngio/experimental/iterators/_mappers.py +48 -0
  15. ngio/experimental/iterators/_rois_utils.py +127 -0
  16. ngio/experimental/iterators/_segmentation.py +235 -0
  17. ngio/hcs/_plate.py +41 -36
  18. ngio/images/__init__.py +22 -1
  19. ngio/images/_abstract_image.py +403 -176
  20. ngio/images/_create.py +31 -15
  21. ngio/images/_create_synt_container.py +138 -0
  22. ngio/images/_image.py +452 -63
  23. ngio/images/_label.py +56 -30
  24. ngio/images/_masked_image.py +387 -129
  25. ngio/images/_ome_zarr_container.py +237 -67
  26. ngio/{common → images}/_table_ops.py +41 -41
  27. ngio/io_pipes/__init__.py +75 -0
  28. ngio/io_pipes/_io_pipes.py +361 -0
  29. ngio/io_pipes/_io_pipes_masked.py +488 -0
  30. ngio/io_pipes/_io_pipes_roi.py +152 -0
  31. ngio/io_pipes/_io_pipes_types.py +56 -0
  32. ngio/io_pipes/_match_shape.py +376 -0
  33. ngio/io_pipes/_ops_axes.py +344 -0
  34. ngio/io_pipes/_ops_slices.py +446 -0
  35. ngio/io_pipes/_ops_slices_utils.py +196 -0
  36. ngio/io_pipes/_ops_transforms.py +104 -0
  37. ngio/io_pipes/_zoom_transform.py +175 -0
  38. ngio/ome_zarr_meta/__init__.py +4 -2
  39. ngio/ome_zarr_meta/ngio_specs/__init__.py +4 -10
  40. ngio/ome_zarr_meta/ngio_specs/_axes.py +186 -175
  41. ngio/ome_zarr_meta/ngio_specs/_channels.py +55 -18
  42. ngio/ome_zarr_meta/ngio_specs/_dataset.py +48 -122
  43. ngio/ome_zarr_meta/ngio_specs/_ngio_hcs.py +6 -15
  44. ngio/ome_zarr_meta/ngio_specs/_ngio_image.py +38 -87
  45. ngio/ome_zarr_meta/ngio_specs/_pixel_size.py +17 -1
  46. ngio/ome_zarr_meta/v04/_v04_spec_utils.py +34 -31
  47. ngio/resources/20200812-CardiomyocyteDifferentiation14-Cycle1_B03/mask.png +0 -0
  48. ngio/resources/20200812-CardiomyocyteDifferentiation14-Cycle1_B03/nuclei.png +0 -0
  49. ngio/resources/20200812-CardiomyocyteDifferentiation14-Cycle1_B03/raw.jpg +0 -0
  50. ngio/resources/__init__.py +55 -0
  51. ngio/resources/resource_model.py +36 -0
  52. ngio/tables/backends/_abstract_backend.py +5 -6
  53. ngio/tables/backends/_anndata.py +1 -2
  54. ngio/tables/backends/_anndata_utils.py +3 -3
  55. ngio/tables/backends/_non_zarr_backends.py +1 -1
  56. ngio/tables/backends/_table_backends.py +0 -1
  57. ngio/tables/backends/_utils.py +3 -3
  58. ngio/tables/v1/_roi_table.py +165 -70
  59. ngio/transforms/__init__.py +5 -0
  60. ngio/transforms/_zoom.py +19 -0
  61. ngio/utils/__init__.py +2 -3
  62. ngio/utils/_datasets.py +5 -0
  63. ngio/utils/_logger.py +19 -0
  64. ngio/utils/_zarr_utils.py +6 -6
  65. {ngio-0.3.4.dist-info → ngio-0.4.0.dist-info}/METADATA +24 -22
  66. ngio-0.4.0.dist-info/RECORD +85 -0
  67. ngio/common/_array_pipe.py +0 -288
  68. ngio/common/_axes_transforms.py +0 -64
  69. ngio/common/_common_types.py +0 -5
  70. ngio/common/_slicer.py +0 -96
  71. ngio-0.3.4.dist-info/RECORD +0 -61
  72. {ngio-0.3.4.dist-info → ngio-0.4.0.dist-info}/WHEEL +0 -0
  73. {ngio-0.3.4.dist-info → ngio-0.4.0.dist-info}/licenses/LICENSE +0 -0
ngio/images/_label.py CHANGED
@@ -1,12 +1,12 @@
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
6
+ from zarr.types import DIMENSION_SEPARATOR
7
7
 
8
8
  from ngio.common import compute_masking_roi
9
- from ngio.images._abstract_image import AbstractImage, consolidate_image
9
+ from ngio.images._abstract_image import AbstractImage
10
10
  from ngio.images._create import create_empty_label_container
11
11
  from ngio.images._image import Image
12
12
  from ngio.ome_zarr_meta import (
@@ -33,6 +33,15 @@ from ngio.utils import (
33
33
  class Label(AbstractImage[LabelMetaHandler]):
34
34
  """Placeholder class for a label."""
35
35
 
36
+ get_as_numpy = AbstractImage._get_as_numpy
37
+ get_as_dask = AbstractImage._get_as_dask
38
+ get_array = AbstractImage._get_array
39
+ get_roi_as_numpy = AbstractImage._get_roi_as_numpy
40
+ get_roi_as_dask = AbstractImage._get_roi_as_dask
41
+ get_roi = AbstractImage._get_roi
42
+ set_array = AbstractImage._set_array
43
+ set_roi = AbstractImage._set_roi
44
+
36
45
  def __init__(
37
46
  self,
38
47
  group_handler: ZarrGroupHandler,
@@ -86,7 +95,10 @@ class Label(AbstractImage[LabelMetaHandler]):
86
95
  mode: Literal["dask", "numpy", "coarsen"] = "dask",
87
96
  ) -> None:
88
97
  """Consolidate the label on disk."""
89
- consolidate_image(self, mode=mode, order=0)
98
+ self._consolidate(
99
+ order="nearest",
100
+ mode=mode,
101
+ )
90
102
 
91
103
 
92
104
  class LabelsContainer:
@@ -152,11 +164,13 @@ class LabelsContainer:
152
164
  self,
153
165
  name: str,
154
166
  ref_image: Image | Label,
155
- shape: Collection[int] | None = None,
167
+ shape: Sequence[int] | None = None,
156
168
  pixel_size: PixelSize | None = None,
157
- axes_names: Collection[str] | None = None,
158
- chunks: Collection[int] | None = None,
159
- dtype: str | None = None,
169
+ axes_names: Sequence[str] | None = None,
170
+ chunks: Sequence[int] | None = None,
171
+ dtype: str = "uint32",
172
+ dimension_separator: DIMENSION_SEPARATOR | None = None,
173
+ compressor=None,
160
174
  overwrite: bool = False,
161
175
  ) -> "Label":
162
176
  """Create an empty OME-Zarr label from a reference image.
@@ -168,12 +182,16 @@ class LabelsContainer:
168
182
  ref_image (Image | Label): A reference image that will be used to create
169
183
  the new image.
170
184
  name (str): The name of the new image.
171
- shape (Collection[int] | None): The shape of the new image.
185
+ shape (Sequence[int] | None): The shape of the new image.
172
186
  pixel_size (PixelSize | None): The pixel size of the new image.
173
- axes_names (Collection[str] | None): The axes names of the new image.
187
+ axes_names (Sequence[str] | None): The axes names of the new image.
174
188
  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.
189
+ chunks (Sequence[int] | None): The chunk shape of the new image.
190
+ dtype (str): The data type of the new label.
191
+ dimension_separator (DIMENSION_SEPARATOR | None): The separator to use for
192
+ dimensions. If None it will use the same as the reference image.
193
+ compressor: The compressor to use. If None it will use
194
+ the same as the reference image.
177
195
  overwrite (bool): Whether to overwrite an existing image.
178
196
 
179
197
  Returns:
@@ -198,6 +216,8 @@ class LabelsContainer:
198
216
  axes_names=axes_names,
199
217
  chunks=chunks,
200
218
  dtype=dtype,
219
+ dimension_separator=dimension_separator,
220
+ compressor=compressor,
201
221
  overwrite=overwrite,
202
222
  )
203
223
 
@@ -212,11 +232,13 @@ def derive_label(
212
232
  store: StoreOrGroup,
213
233
  ref_image: Image | Label,
214
234
  name: str,
215
- shape: Collection[int] | None = None,
235
+ shape: Sequence[int] | None = None,
216
236
  pixel_size: PixelSize | None = None,
217
- axes_names: Collection[str] | None = None,
218
- chunks: Collection[int] | None = None,
219
- dtype: str | None = None,
237
+ axes_names: Sequence[str] | None = None,
238
+ chunks: Sequence[int] | None = None,
239
+ dimension_separator: DIMENSION_SEPARATOR | None = None,
240
+ compressor=None,
241
+ dtype: str = "uint32",
220
242
  overwrite: bool = False,
221
243
  ) -> None:
222
244
  """Create an empty OME-Zarr label from a reference image.
@@ -226,12 +248,16 @@ def derive_label(
226
248
  ref_image (Image | Label): A reference image that will be used to
227
249
  create the new image.
228
250
  name (str): The name of the new image.
229
- shape (Collection[int] | None): The shape of the new image.
251
+ shape (Sequence[int] | None): The shape of the new image.
230
252
  pixel_size (PixelSize | None): The pixel size of the new image.
231
- axes_names (Collection[str] | None): The axes names of the new image.
253
+ axes_names (Sequence[str] | None): The axes names of the new image.
232
254
  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.
255
+ chunks (Sequence[int] | None): The chunk shape of the new image.
256
+ dtype (str): The data type of the new label.
257
+ dimension_separator (DIMENSION_SEPARATOR | None): The separator to use for
258
+ dimensions. If None it will use the same as the reference image.
259
+ compressor: The compressor to use. If None it will use
260
+ the same as the reference image.
235
261
  overwrite (bool): Whether to overwrite an existing image.
236
262
 
237
263
  Returns:
@@ -247,8 +273,8 @@ def derive_label(
247
273
  pixel_size = ref_image.pixel_size
248
274
 
249
275
  if axes_names is None:
250
- axes_names = ref_meta.axes_mapper.on_disk_axes_names
251
- c_axis = ref_meta.axes_mapper.get_index("c")
276
+ axes_names = ref_meta.axes_handler.axes_names
277
+ c_axis = ref_meta.axes_handler.get_index("c")
252
278
  else:
253
279
  if "c" in axes_names:
254
280
  raise NgioValidationError(
@@ -272,9 +298,6 @@ def derive_label(
272
298
  f"Got {chunks} for shape {shape}."
273
299
  )
274
300
 
275
- if dtype is None:
276
- dtype = ref_image.dtype
277
-
278
301
  if c_axis is not None:
279
302
  # remove channel if present
280
303
  shape = list(shape)
@@ -284,6 +307,11 @@ def derive_label(
284
307
  axes_names = list(axes_names)
285
308
  axes_names = axes_names[:c_axis] + axes_names[c_axis + 1 :]
286
309
 
310
+ if dimension_separator is None:
311
+ dimension_separator = ref_image.zarr_array._dimension_separator # type: ignore
312
+ if compressor is None:
313
+ compressor = ref_image.zarr_array.compressor # type: ignore
314
+
287
315
  _ = create_empty_label_container(
288
316
  store=store,
289
317
  shape=shape,
@@ -298,6 +326,8 @@ def derive_label(
298
326
  axes_names=axes_names,
299
327
  chunks=chunks,
300
328
  dtype=dtype,
329
+ dimension_separator=dimension_separator, # type: ignore
330
+ compressor=compressor, # type: ignore
301
331
  overwrite=overwrite,
302
332
  version=ref_meta.version,
303
333
  name=name,
@@ -307,10 +337,6 @@ def derive_label(
307
337
 
308
338
  def build_masking_roi_table(label: Label) -> MaskingRoiTable:
309
339
  """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."
340
+ array = label.get_as_dask(axes_order=["t", "z", "y", "x"])
315
341
  rois = compute_masking_roi(array, label.pixel_size)
316
342
  return MaskingRoiTable(rois, reference_label=label.meta.name)