ngio 0.3.5__py3-none-any.whl → 0.4.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.
- ngio/__init__.py +6 -0
- ngio/common/__init__.py +50 -48
- ngio/common/_array_io_pipes.py +554 -0
- ngio/common/_array_io_utils.py +508 -0
- ngio/common/_dimensions.py +63 -27
- ngio/common/_masking_roi.py +38 -10
- ngio/common/_pyramid.py +9 -7
- ngio/common/_roi.py +583 -72
- ngio/common/_synt_images_utils.py +101 -0
- ngio/common/_zoom.py +17 -12
- ngio/common/transforms/__init__.py +5 -0
- ngio/common/transforms/_label.py +12 -0
- ngio/common/transforms/_zoom.py +109 -0
- ngio/experimental/__init__.py +5 -0
- ngio/experimental/iterators/__init__.py +17 -0
- ngio/experimental/iterators/_abstract_iterator.py +170 -0
- ngio/experimental/iterators/_feature.py +151 -0
- ngio/experimental/iterators/_image_processing.py +169 -0
- ngio/experimental/iterators/_rois_utils.py +127 -0
- ngio/experimental/iterators/_segmentation.py +282 -0
- ngio/hcs/_plate.py +41 -36
- ngio/images/__init__.py +22 -1
- ngio/images/_abstract_image.py +247 -117
- ngio/images/_create.py +15 -15
- ngio/images/_create_synt_container.py +128 -0
- ngio/images/_image.py +425 -62
- ngio/images/_label.py +33 -30
- ngio/images/_masked_image.py +396 -122
- ngio/images/_ome_zarr_container.py +203 -66
- ngio/{common → images}/_table_ops.py +41 -41
- ngio/ome_zarr_meta/ngio_specs/__init__.py +2 -8
- ngio/ome_zarr_meta/ngio_specs/_axes.py +151 -128
- ngio/ome_zarr_meta/ngio_specs/_channels.py +55 -18
- ngio/ome_zarr_meta/ngio_specs/_dataset.py +7 -7
- ngio/ome_zarr_meta/ngio_specs/_ngio_hcs.py +3 -3
- ngio/ome_zarr_meta/ngio_specs/_ngio_image.py +11 -68
- ngio/ome_zarr_meta/v04/_v04_spec_utils.py +1 -1
- ngio/resources/20200812-CardiomyocyteDifferentiation14-Cycle1_B03/mask.png +0 -0
- ngio/resources/20200812-CardiomyocyteDifferentiation14-Cycle1_B03/nuclei.png +0 -0
- ngio/resources/20200812-CardiomyocyteDifferentiation14-Cycle1_B03/raw.jpg +0 -0
- ngio/resources/__init__.py +54 -0
- ngio/resources/resource_model.py +35 -0
- ngio/tables/backends/_abstract_backend.py +5 -6
- ngio/tables/backends/_anndata.py +1 -1
- ngio/tables/backends/_anndata_utils.py +3 -3
- ngio/tables/backends/_non_zarr_backends.py +1 -1
- ngio/tables/backends/_table_backends.py +0 -1
- ngio/tables/backends/_utils.py +3 -3
- ngio/tables/v1/_roi_table.py +156 -69
- ngio/utils/__init__.py +2 -3
- ngio/utils/_logger.py +19 -0
- ngio/utils/_zarr_utils.py +1 -5
- {ngio-0.3.5.dist-info → ngio-0.4.0a2.dist-info}/METADATA +3 -1
- ngio-0.4.0a2.dist-info/RECORD +76 -0
- ngio/common/_array_pipe.py +0 -288
- ngio/common/_axes_transforms.py +0 -64
- ngio/common/_common_types.py +0 -5
- ngio/common/_slicer.py +0 -96
- ngio-0.3.5.dist-info/RECORD +0 -61
- {ngio-0.3.5.dist-info → ngio-0.4.0a2.dist-info}/WHEEL +0 -0
- {ngio-0.3.5.dist-info → ngio-0.4.0a2.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
|
|
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
|
|
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
|
-
|
|
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:
|
|
165
|
+
shape: Sequence[int] | None = None,
|
|
156
166
|
pixel_size: PixelSize | None = None,
|
|
157
|
-
axes_names:
|
|
158
|
-
chunks:
|
|
159
|
-
dtype: str
|
|
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 (
|
|
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 (
|
|
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 (
|
|
176
|
-
dtype (str
|
|
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:
|
|
225
|
+
shape: Sequence[int] | None = None,
|
|
216
226
|
pixel_size: PixelSize | None = None,
|
|
217
|
-
axes_names:
|
|
218
|
-
chunks:
|
|
219
|
-
dtype: str
|
|
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 (
|
|
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 (
|
|
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 (
|
|
234
|
-
dtype (str
|
|
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.
|
|
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
|
-
|
|
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)
|