ngio 0.3.4__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.
- ngio/__init__.py +6 -0
- ngio/common/__init__.py +50 -48
- ngio/common/_array_io_pipes.py +549 -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 +571 -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 +278 -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 +6 -15
- 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 -2
- 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.4.dist-info → ngio-0.4.0a1.dist-info}/METADATA +12 -10
- ngio-0.4.0a1.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.4.dist-info/RECORD +0 -61
- {ngio-0.3.4.dist-info → ngio-0.4.0a1.dist-info}/WHEEL +0 -0
- {ngio-0.3.4.dist-info → ngio-0.4.0a1.dist-info}/licenses/LICENSE +0 -0
ngio/common/_array_pipe.py
DELETED
|
@@ -1,288 +0,0 @@
|
|
|
1
|
-
from collections.abc import Collection, Iterable
|
|
2
|
-
from typing import Literal
|
|
3
|
-
|
|
4
|
-
import dask.array as da
|
|
5
|
-
import numpy as np
|
|
6
|
-
import zarr
|
|
7
|
-
from dask.array import Array as DaskArray
|
|
8
|
-
from dask.delayed import Delayed, delayed
|
|
9
|
-
|
|
10
|
-
from ngio.common._axes_transforms import transform_dask_array, transform_numpy_array
|
|
11
|
-
from ngio.common._common_types import ArrayLike
|
|
12
|
-
from ngio.common._dimensions import Dimensions
|
|
13
|
-
from ngio.common._slicer import (
|
|
14
|
-
SliceTransform,
|
|
15
|
-
compute_and_slices,
|
|
16
|
-
dask_get_slice,
|
|
17
|
-
dask_set_slice,
|
|
18
|
-
numpy_get_slice,
|
|
19
|
-
numpy_set_slice,
|
|
20
|
-
)
|
|
21
|
-
from ngio.ome_zarr_meta.ngio_specs import AxesTransformation
|
|
22
|
-
from ngio.utils import NgioValueError
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
def _compute_from_disk_transforms(
|
|
26
|
-
*,
|
|
27
|
-
dimensions: Dimensions,
|
|
28
|
-
axes_order: Collection[str] | None = None,
|
|
29
|
-
**slice_kwargs: slice | int | Iterable[int],
|
|
30
|
-
) -> tuple[SliceTransform, tuple[AxesTransformation, ...]]:
|
|
31
|
-
slices = compute_and_slices(dimensions=dimensions, **slice_kwargs)
|
|
32
|
-
|
|
33
|
-
if axes_order is None:
|
|
34
|
-
return slices, ()
|
|
35
|
-
|
|
36
|
-
additional_transformations = dimensions._axes_mapper.to_order(axes_order)
|
|
37
|
-
return slices, additional_transformations
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
def _compute_to_disk_transforms(
|
|
41
|
-
*,
|
|
42
|
-
dimensions: Dimensions,
|
|
43
|
-
axes_order: Collection[str] | None = None,
|
|
44
|
-
**slice_kwargs: slice | int | Iterable[int],
|
|
45
|
-
) -> tuple[SliceTransform, tuple[AxesTransformation, ...]]:
|
|
46
|
-
slices = compute_and_slices(dimensions=dimensions, **slice_kwargs)
|
|
47
|
-
if axes_order is None:
|
|
48
|
-
return slices, ()
|
|
49
|
-
|
|
50
|
-
additional_transformations = dimensions._axes_mapper.from_order(axes_order)
|
|
51
|
-
return slices, additional_transformations
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
def _numpy_get_pipe(
|
|
55
|
-
array: zarr.Array,
|
|
56
|
-
slices: SliceTransform,
|
|
57
|
-
transformations: tuple[AxesTransformation, ...],
|
|
58
|
-
) -> np.ndarray:
|
|
59
|
-
_array = numpy_get_slice(array, slices)
|
|
60
|
-
return transform_numpy_array(_array, transformations)
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
def _delayed_numpy_get_pipe(
|
|
64
|
-
array: zarr.Array,
|
|
65
|
-
slices: SliceTransform,
|
|
66
|
-
transformations: tuple[AxesTransformation, ...],
|
|
67
|
-
) -> Delayed:
|
|
68
|
-
_array = delayed(numpy_get_slice)(array, slices)
|
|
69
|
-
return delayed(transform_numpy_array)(_array, transformations)
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
def _dask_get_pipe(
|
|
73
|
-
array: zarr.Array,
|
|
74
|
-
slices: SliceTransform,
|
|
75
|
-
transformations: tuple[AxesTransformation, ...],
|
|
76
|
-
) -> DaskArray:
|
|
77
|
-
_array = dask_get_slice(array, slices)
|
|
78
|
-
return transform_dask_array(_array, transformations)
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
def _numpy_set_pipe(
|
|
82
|
-
array: zarr.Array,
|
|
83
|
-
patch: np.ndarray,
|
|
84
|
-
slices: SliceTransform,
|
|
85
|
-
transformations: tuple[AxesTransformation, ...],
|
|
86
|
-
) -> None:
|
|
87
|
-
patch = transform_numpy_array(patch, transformations)
|
|
88
|
-
numpy_set_slice(array, patch, slices)
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
def _dask_set_pipe(
|
|
92
|
-
array: zarr.Array,
|
|
93
|
-
patch: DaskArray,
|
|
94
|
-
slices: SliceTransform,
|
|
95
|
-
transformations: tuple[AxesTransformation, ...],
|
|
96
|
-
) -> None:
|
|
97
|
-
_patch = transform_dask_array(patch, transformations)
|
|
98
|
-
dask_set_slice(array, _patch, slices)
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
def _delayed_numpy_set_pipe(
|
|
102
|
-
array: zarr.Array,
|
|
103
|
-
patch: np.ndarray | Delayed,
|
|
104
|
-
slices: SliceTransform,
|
|
105
|
-
transformations: tuple[AxesTransformation, ...],
|
|
106
|
-
) -> Delayed:
|
|
107
|
-
_patch = delayed(transform_numpy_array)(patch, transformations)
|
|
108
|
-
return delayed(numpy_set_slice)(array, _patch, slices)
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
def get_pipe(
|
|
112
|
-
array: zarr.Array,
|
|
113
|
-
*,
|
|
114
|
-
dimensions: Dimensions,
|
|
115
|
-
axes_order: Collection[str] | None = None,
|
|
116
|
-
mode: Literal["numpy", "dask", "delayed"] = "numpy",
|
|
117
|
-
**slice_kwargs: slice | int | Iterable[int],
|
|
118
|
-
):
|
|
119
|
-
slices, transformations = _compute_from_disk_transforms(
|
|
120
|
-
dimensions=dimensions, axes_order=axes_order, **slice_kwargs
|
|
121
|
-
)
|
|
122
|
-
match mode:
|
|
123
|
-
case "numpy":
|
|
124
|
-
return _numpy_get_pipe(array, slices, transformations)
|
|
125
|
-
case "dask":
|
|
126
|
-
return _dask_get_pipe(array, slices, transformations)
|
|
127
|
-
|
|
128
|
-
case "delayed":
|
|
129
|
-
return _delayed_numpy_get_pipe(array, slices, transformations)
|
|
130
|
-
|
|
131
|
-
case _:
|
|
132
|
-
raise NgioValueError(
|
|
133
|
-
f"Unknown get pipe mode {mode}, expected 'numpy', 'dask' or 'delayed'."
|
|
134
|
-
)
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
def set_pipe(
|
|
138
|
-
array: zarr.Array,
|
|
139
|
-
patch: ArrayLike,
|
|
140
|
-
*,
|
|
141
|
-
dimensions: Dimensions,
|
|
142
|
-
axes_order: Collection[str] | None = None,
|
|
143
|
-
**slice_kwargs: slice | int | Iterable[int],
|
|
144
|
-
):
|
|
145
|
-
slices, transformations = _compute_to_disk_transforms(
|
|
146
|
-
dimensions=dimensions, axes_order=axes_order, **slice_kwargs
|
|
147
|
-
)
|
|
148
|
-
if isinstance(patch, DaskArray):
|
|
149
|
-
_dask_set_pipe(
|
|
150
|
-
array=array, patch=patch, slices=slices, transformations=transformations
|
|
151
|
-
)
|
|
152
|
-
elif isinstance(patch, np.ndarray):
|
|
153
|
-
_numpy_set_pipe(
|
|
154
|
-
array=array, patch=patch, slices=slices, transformations=transformations
|
|
155
|
-
)
|
|
156
|
-
elif isinstance(patch, Delayed):
|
|
157
|
-
_delayed_numpy_set_pipe(
|
|
158
|
-
array=array, patch=patch, slices=slices, transformations=transformations
|
|
159
|
-
)
|
|
160
|
-
else:
|
|
161
|
-
raise NgioValueError("Unknown patch type, expected numpy, dask or delayed.")
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
def _mask_pipe_common(
|
|
165
|
-
array: zarr.Array,
|
|
166
|
-
label_array: zarr.Array,
|
|
167
|
-
label: int,
|
|
168
|
-
*,
|
|
169
|
-
dimensions_array: Dimensions,
|
|
170
|
-
dimensions_label: Dimensions,
|
|
171
|
-
axes_order: Collection[str] | None = None,
|
|
172
|
-
mode: Literal["numpy", "dask", "delayed"] = "numpy",
|
|
173
|
-
**slice_kwargs: slice | int | Iterable[int],
|
|
174
|
-
):
|
|
175
|
-
array_patch = get_pipe(
|
|
176
|
-
array,
|
|
177
|
-
dimensions=dimensions_array,
|
|
178
|
-
axes_order=axes_order,
|
|
179
|
-
mode=mode,
|
|
180
|
-
**slice_kwargs,
|
|
181
|
-
)
|
|
182
|
-
|
|
183
|
-
if not dimensions_label.has_axis("c"):
|
|
184
|
-
# Remove the 'c' from the slice_kwargs
|
|
185
|
-
# This will not work if the query uses non-default
|
|
186
|
-
# axes names for channel
|
|
187
|
-
slice_kwargs = {k: v for k, v in slice_kwargs.items() if k != "c"}
|
|
188
|
-
|
|
189
|
-
label_patch = get_pipe(
|
|
190
|
-
label_array,
|
|
191
|
-
dimensions=dimensions_label,
|
|
192
|
-
axes_order=axes_order,
|
|
193
|
-
mode=mode,
|
|
194
|
-
**slice_kwargs,
|
|
195
|
-
)
|
|
196
|
-
|
|
197
|
-
if isinstance(array_patch, np.ndarray) and isinstance(label_patch, np.ndarray):
|
|
198
|
-
label_patch = np.broadcast_to(label_patch, array_patch.shape)
|
|
199
|
-
elif isinstance(array_patch, DaskArray) and isinstance(label_patch, DaskArray):
|
|
200
|
-
label_patch = da.broadcast_to(label_patch, array_patch.shape)
|
|
201
|
-
else:
|
|
202
|
-
raise NgioValueError(
|
|
203
|
-
"Incompatible types for array and label: "
|
|
204
|
-
f"{type(array_patch)} and {type(label_patch)}"
|
|
205
|
-
)
|
|
206
|
-
|
|
207
|
-
mask = label_patch == label
|
|
208
|
-
return array_patch, mask
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
def get_masked_pipe(
|
|
212
|
-
array: zarr.Array,
|
|
213
|
-
label_array: zarr.Array,
|
|
214
|
-
label: int,
|
|
215
|
-
*,
|
|
216
|
-
dimensions_array: Dimensions,
|
|
217
|
-
dimensions_label: Dimensions,
|
|
218
|
-
axes_order: Collection[str] | None = None,
|
|
219
|
-
mode: Literal["numpy", "dask", "delayed"] = "numpy",
|
|
220
|
-
**slice_kwargs: slice | int | Iterable[int],
|
|
221
|
-
):
|
|
222
|
-
array_patch, mask = _mask_pipe_common(
|
|
223
|
-
array=array,
|
|
224
|
-
label_array=label_array,
|
|
225
|
-
label=label,
|
|
226
|
-
dimensions_array=dimensions_array,
|
|
227
|
-
dimensions_label=dimensions_label,
|
|
228
|
-
axes_order=axes_order,
|
|
229
|
-
mode=mode,
|
|
230
|
-
**slice_kwargs,
|
|
231
|
-
)
|
|
232
|
-
if isinstance(array_patch, np.ndarray):
|
|
233
|
-
array_patch[~mask] = 0
|
|
234
|
-
elif isinstance(array_patch, DaskArray):
|
|
235
|
-
array_patch = da.where(mask, array_patch, 0)
|
|
236
|
-
else:
|
|
237
|
-
raise NgioValueError(
|
|
238
|
-
"Mode not yet supported for masked array. Expected a numpy or dask array."
|
|
239
|
-
)
|
|
240
|
-
return array_patch
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
def set_masked_pipe(
|
|
244
|
-
array: zarr.Array,
|
|
245
|
-
label_array: zarr.Array,
|
|
246
|
-
label: int,
|
|
247
|
-
patch: ArrayLike,
|
|
248
|
-
*,
|
|
249
|
-
dimensions_array: Dimensions,
|
|
250
|
-
dimensions_label: Dimensions,
|
|
251
|
-
axes_order: Collection[str] | None = None,
|
|
252
|
-
**slice_kwargs: slice | int | Iterable[int],
|
|
253
|
-
):
|
|
254
|
-
if isinstance(patch, DaskArray):
|
|
255
|
-
mode = "dask"
|
|
256
|
-
elif isinstance(patch, np.ndarray):
|
|
257
|
-
mode = "numpy"
|
|
258
|
-
else:
|
|
259
|
-
raise NgioValueError(
|
|
260
|
-
"Mode not yet supported for masked array. Expected a numpy or dask array."
|
|
261
|
-
)
|
|
262
|
-
|
|
263
|
-
array_patch, mask = _mask_pipe_common(
|
|
264
|
-
array=array,
|
|
265
|
-
label_array=label_array,
|
|
266
|
-
label=label,
|
|
267
|
-
dimensions_array=dimensions_array,
|
|
268
|
-
dimensions_label=dimensions_label,
|
|
269
|
-
axes_order=axes_order,
|
|
270
|
-
mode=mode,
|
|
271
|
-
**slice_kwargs,
|
|
272
|
-
)
|
|
273
|
-
if isinstance(patch, np.ndarray):
|
|
274
|
-
assert isinstance(array_patch, np.ndarray)
|
|
275
|
-
_patch = np.where(mask, patch, array_patch)
|
|
276
|
-
elif isinstance(patch, DaskArray):
|
|
277
|
-
_patch = da.where(mask, patch, array_patch)
|
|
278
|
-
else:
|
|
279
|
-
raise NgioValueError(
|
|
280
|
-
"Mode not yet supported for masked array. Expected a numpy or dask array."
|
|
281
|
-
)
|
|
282
|
-
set_pipe(
|
|
283
|
-
array,
|
|
284
|
-
_patch,
|
|
285
|
-
dimensions=dimensions_array,
|
|
286
|
-
axes_order=axes_order,
|
|
287
|
-
**slice_kwargs,
|
|
288
|
-
)
|
ngio/common/_axes_transforms.py
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
from typing import TypeVar
|
|
2
|
-
|
|
3
|
-
import dask.array as da
|
|
4
|
-
import numpy as np
|
|
5
|
-
|
|
6
|
-
from ngio.ome_zarr_meta.ngio_specs._axes import (
|
|
7
|
-
AxesExpand,
|
|
8
|
-
AxesSqueeze,
|
|
9
|
-
AxesTransformation,
|
|
10
|
-
AxesTranspose,
|
|
11
|
-
)
|
|
12
|
-
from ngio.utils import NgioValueError
|
|
13
|
-
|
|
14
|
-
T = TypeVar("T")
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
def transform_list(
|
|
18
|
-
input_list: list[T], default: T, operations: tuple[AxesTransformation, ...]
|
|
19
|
-
) -> list[T]:
|
|
20
|
-
if isinstance(input_list, tuple):
|
|
21
|
-
input_list = list(input_list)
|
|
22
|
-
|
|
23
|
-
for operation in operations:
|
|
24
|
-
if isinstance(operation, AxesTranspose):
|
|
25
|
-
input_list = [input_list[i] for i in operation.axes]
|
|
26
|
-
|
|
27
|
-
if isinstance(operation, AxesExpand):
|
|
28
|
-
for ax in operation.axes:
|
|
29
|
-
input_list.insert(ax, default)
|
|
30
|
-
elif isinstance(operation, AxesSqueeze):
|
|
31
|
-
for offset, ax in enumerate(operation.axes):
|
|
32
|
-
input_list.pop(ax - offset)
|
|
33
|
-
|
|
34
|
-
return input_list
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
def transform_numpy_array(
|
|
38
|
-
array: np.ndarray, operations: tuple[AxesTransformation, ...]
|
|
39
|
-
) -> np.ndarray:
|
|
40
|
-
for operation in operations:
|
|
41
|
-
if isinstance(operation, AxesTranspose):
|
|
42
|
-
array = np.transpose(array, operation.axes)
|
|
43
|
-
elif isinstance(operation, AxesExpand):
|
|
44
|
-
array = np.expand_dims(array, axis=operation.axes)
|
|
45
|
-
elif isinstance(operation, AxesSqueeze):
|
|
46
|
-
array = np.squeeze(array, axis=operation.axes)
|
|
47
|
-
else:
|
|
48
|
-
raise NgioValueError(f"Unknown operation {operation}")
|
|
49
|
-
return array
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
def transform_dask_array(
|
|
53
|
-
array: da.Array, operations: tuple[AxesTransformation, ...]
|
|
54
|
-
) -> da.Array:
|
|
55
|
-
for operation in operations:
|
|
56
|
-
if isinstance(operation, AxesTranspose):
|
|
57
|
-
array = da.transpose(array, axes=operation.axes)
|
|
58
|
-
elif isinstance(operation, AxesExpand):
|
|
59
|
-
array = da.expand_dims(array, axis=operation.axes)
|
|
60
|
-
elif isinstance(operation, AxesSqueeze):
|
|
61
|
-
array = da.squeeze(array, axis=operation.axes)
|
|
62
|
-
else:
|
|
63
|
-
raise NgioValueError(f"Unknown operation {operation}")
|
|
64
|
-
return array
|
ngio/common/_common_types.py
DELETED
ngio/common/_slicer.py
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
from collections.abc import Iterable
|
|
2
|
-
|
|
3
|
-
import dask.array as da
|
|
4
|
-
import numpy as np
|
|
5
|
-
import zarr
|
|
6
|
-
|
|
7
|
-
from ngio.common._dimensions import Dimensions
|
|
8
|
-
from ngio.ome_zarr_meta.ngio_specs import AxesTransformation
|
|
9
|
-
from ngio.utils import NgioValueError
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def _validate_int(value: int, shape: int) -> int:
|
|
13
|
-
if not isinstance(value, int):
|
|
14
|
-
raise NgioValueError(f"Invalid value {value} of type {type(value)}")
|
|
15
|
-
if value < 0 or value >= shape:
|
|
16
|
-
raise NgioValueError(
|
|
17
|
-
f"Invalid value {value}. Index out of bounds for axis of shape {shape}"
|
|
18
|
-
)
|
|
19
|
-
return value
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
def _validate_iter_of_ints(value: Iterable[int], shape: int) -> list[int]:
|
|
23
|
-
if not isinstance(value, list):
|
|
24
|
-
raise NgioValueError(f"Invalid value {value} of type {type(value)}")
|
|
25
|
-
value = [_validate_int(v, shape=shape) for v in value]
|
|
26
|
-
return value
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
def _validate_slice(value: slice, shape: int) -> slice:
|
|
30
|
-
start = value.start if value.start is not None else 0
|
|
31
|
-
start = max(start, 0)
|
|
32
|
-
stop = value.stop if value.stop is not None else shape
|
|
33
|
-
return slice(start, stop)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
class SliceTransform(AxesTransformation):
|
|
37
|
-
slices: tuple[slice | tuple[int, ...], ...]
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
def compute_and_slices(
|
|
41
|
-
*,
|
|
42
|
-
dimensions: Dimensions,
|
|
43
|
-
**slice_kwargs: slice | int | Iterable[int],
|
|
44
|
-
) -> SliceTransform:
|
|
45
|
-
_slices = {}
|
|
46
|
-
axes_names = dimensions._axes_mapper.on_disk_axes_names
|
|
47
|
-
for axis_name, slice_ in slice_kwargs.items():
|
|
48
|
-
axis = dimensions._axes_mapper.get_axis(axis_name)
|
|
49
|
-
if axis is None:
|
|
50
|
-
raise NgioValueError(
|
|
51
|
-
f"Invalid axis {axis_name}. "
|
|
52
|
-
f"Not found on the on-disk axes {axes_names}. "
|
|
53
|
-
"If you want to get/set a singletorn value include "
|
|
54
|
-
"it in the axes_order parameter."
|
|
55
|
-
)
|
|
56
|
-
|
|
57
|
-
shape = dimensions.get(axis.on_disk_name)
|
|
58
|
-
|
|
59
|
-
if isinstance(slice_, int):
|
|
60
|
-
slice_ = _validate_int(slice_, shape)
|
|
61
|
-
slice_ = slice(slice_, slice_ + 1)
|
|
62
|
-
|
|
63
|
-
elif isinstance(slice_, Iterable):
|
|
64
|
-
slice_ = _validate_iter_of_ints(slice_, shape)
|
|
65
|
-
slice_ = tuple(slice_)
|
|
66
|
-
|
|
67
|
-
elif isinstance(slice_, slice):
|
|
68
|
-
slice_ = _validate_slice(slice_, shape)
|
|
69
|
-
|
|
70
|
-
elif not isinstance(slice_, slice):
|
|
71
|
-
raise NgioValueError(
|
|
72
|
-
f"Invalid slice definition {slice_} of type {type(slice_)}"
|
|
73
|
-
)
|
|
74
|
-
_slices[axis.on_disk_name] = slice_
|
|
75
|
-
|
|
76
|
-
slices = tuple(_slices.get(axis, slice(None)) for axis in axes_names)
|
|
77
|
-
return SliceTransform(slices=slices)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
def numpy_get_slice(array: zarr.Array, slices: SliceTransform) -> np.ndarray:
|
|
81
|
-
return array[slices.slices]
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
def dask_get_slice(array: zarr.Array, slices: SliceTransform) -> da.Array:
|
|
85
|
-
da_array = da.from_zarr(array)
|
|
86
|
-
return da_array[slices.slices]
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
def numpy_set_slice(
|
|
90
|
-
array: zarr.Array, patch: np.ndarray, slices: SliceTransform
|
|
91
|
-
) -> None:
|
|
92
|
-
array[slices.slices] = patch
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
def dask_set_slice(array: zarr.Array, patch: da.Array, slices: SliceTransform) -> None:
|
|
96
|
-
da.to_zarr(arr=patch, url=array, region=slices.slices)
|
ngio-0.3.4.dist-info/RECORD
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
ngio/__init__.py,sha256=zce-RIfRhkiFyfKwO6s7A1-9ZCD3n6RuVuW3GeRj_VA,1309
|
|
2
|
-
ngio/common/__init__.py,sha256=BttXCAV2ks6_oXVDfapk1Lvlxp4J0ffX7-FXR3LL1BM,1834
|
|
3
|
-
ngio/common/_array_pipe.py,sha256=mvBsOtNSow9S6bSPMJ0288gCqQFYffGnaTTLyuB2XHw,8641
|
|
4
|
-
ngio/common/_axes_transforms.py,sha256=kWU0M5erNmgWBXdu5LNv-tLW3jqkT00MMYX7cz-kyHs,2035
|
|
5
|
-
ngio/common/_common_types.py,sha256=OkAYNSNjZkixL1MI-HPBVuXamheFBr862uJ4PvTxmhk,129
|
|
6
|
-
ngio/common/_dimensions.py,sha256=UV2XulWaROb3Y2f4fv27ZkTIu-MoS53U26aDkrv-_lk,3900
|
|
7
|
-
ngio/common/_masking_roi.py,sha256=-o6meGP17iTXEbkO9aGh1VX2drkc2laIcRJvCy_pRRM,4919
|
|
8
|
-
ngio/common/_pyramid.py,sha256=SJzPauuduuqcm9B7nFCJhMTzIg6Knjsnp4CY4lN61Is,7411
|
|
9
|
-
ngio/common/_roi.py,sha256=xJZ3vSusxhM1wXOizyjPbgzYhneva4IlhaWQc13Kuk4,5186
|
|
10
|
-
ngio/common/_slicer.py,sha256=AKpwXRncOmF9nhjKYma0C_41WqAgSv860beKGx-aw-0,3075
|
|
11
|
-
ngio/common/_table_ops.py,sha256=ToNR7F053l1dubVv-gvBD-523T10HnE2UzqeU2BuNy8,15494
|
|
12
|
-
ngio/common/_zoom.py,sha256=KsURa5VuixmpbAAY5-6obmuQV8vfiHKZqBxZDXvchpM,5473
|
|
13
|
-
ngio/hcs/__init__.py,sha256=G8j9vD-liLeB_UeGtKYIgshWvJnUA6ks9GwjvWBLdHs,357
|
|
14
|
-
ngio/hcs/_plate.py,sha256=o-Myg1sPUT9mCfYjHOuUTIpm2Nl0siacmuztGoPcYc0,44265
|
|
15
|
-
ngio/images/__init__.py,sha256=PlYvbHOMvZLDgn_PeGrytOEU3e_-AO8GWpRjEqoX_Gw,536
|
|
16
|
-
ngio/images/_abstract_image.py,sha256=8PNQPZjiDz-pcTFXSJAVw7nUr4yL_iRwqDEUTKkAnp0,10266
|
|
17
|
-
ngio/images/_create.py,sha256=XYn30m_2OSZeHHASYHc3eK9u_gZIYy9wo6mGdRGaq5c,9473
|
|
18
|
-
ngio/images/_image.py,sha256=B9MTk3Cei-FBR4jbhSujTSNcKM_ySape28yXR_JlY0A,17980
|
|
19
|
-
ngio/images/_label.py,sha256=Q1vPrXDcjJ7Gdd0wDz6NCVYQLNe1Ae6YDI4iK0oq31s,10557
|
|
20
|
-
ngio/images/_masked_image.py,sha256=sd6aQetNVwtDkwUvKX-lssQyHzt5m-CYZL8ZFkwDSn8,8533
|
|
21
|
-
ngio/images/_ome_zarr_container.py,sha256=CygzzFMYFT35ztLSPKe6iKLzCtgCnVWk8M9xOj6Tc5U,31221
|
|
22
|
-
ngio/ome_zarr_meta/__init__.py,sha256=oZ8PEsWM7U0KwzpsnvVfX9k4UfuTz5sZ8B6B9eY5hyY,1193
|
|
23
|
-
ngio/ome_zarr_meta/_meta_handlers.py,sha256=ctknNDT8jxwyvxQf9on5gW31H1tRRsnneO38GT2UXoE,25880
|
|
24
|
-
ngio/ome_zarr_meta/ngio_specs/__init__.py,sha256=05NQukZG0nNvjzf8AKWGu7PhjhQcImGSAOK3D3Bg-Js,1786
|
|
25
|
-
ngio/ome_zarr_meta/ngio_specs/_axes.py,sha256=tHtx6NfBgDcCgDk9CosjIjw1KZJ2qi0i_eoLgrdiEWw,16681
|
|
26
|
-
ngio/ome_zarr_meta/ngio_specs/_channels.py,sha256=Jwys1yYC8q6_gIaJ52KcKcTP7hzqVjBE-VlVQvJurCs,15394
|
|
27
|
-
ngio/ome_zarr_meta/ngio_specs/_dataset.py,sha256=hY8ogPPxvCgVg6k02t3zUr24lasYrvnxBd1iPEigdG4,5892
|
|
28
|
-
ngio/ome_zarr_meta/ngio_specs/_ngio_hcs.py,sha256=uh345KQmEQtslIyMmLK9sB-NbjPYxi0Y9FuYIFhd3Rc,17465
|
|
29
|
-
ngio/ome_zarr_meta/ngio_specs/_ngio_image.py,sha256=8E38Mgw-l0Ff1nkmCJIzo64G_paAVhM8xktUS_V5egY,17960
|
|
30
|
-
ngio/ome_zarr_meta/ngio_specs/_pixel_size.py,sha256=5TT8250XdCKUnk3OwZeyXIMNFKOg_jx4NnoCo9RLsXI,4079
|
|
31
|
-
ngio/ome_zarr_meta/v04/__init__.py,sha256=dJRzzxyYc81kf-0Hip_bqvbdManaM8XTdQX2meWyCSs,583
|
|
32
|
-
ngio/ome_zarr_meta/v04/_custom_models.py,sha256=5GxiDERvLuvq4QvApcA6EiKLS6hLFX1R0R_9rSaa85A,530
|
|
33
|
-
ngio/ome_zarr_meta/v04/_v04_spec_utils.py,sha256=05tEr2eEP_XVIfBMOAWLT7lzJV4KS5eYrpK8l94tn3w,15876
|
|
34
|
-
ngio/tables/__init__.py,sha256=_BV3sclNMLITu_J8_3DkkUrCB6Kro0HzeWLDCD1ivKM,877
|
|
35
|
-
ngio/tables/_abstract_table.py,sha256=rwGa47TzbFmosucBWVfFq6JEXtgGvOdUVtU9DIelV88,8204
|
|
36
|
-
ngio/tables/_tables_container.py,sha256=3xmpREaN671l40MPprnl1BD-VoOb6xfjECb5mNoMW0w,12173
|
|
37
|
-
ngio/tables/backends/__init__.py,sha256=MwSRXNF1rWQBFOTDA_vT3oGoNZpviVgytsL5Txnu08I,1619
|
|
38
|
-
ngio/tables/backends/_abstract_backend.py,sha256=tsbHzSPTX88fiCbVc8khXv5aN68ck6HKG8r5OHkY3S8,7457
|
|
39
|
-
ngio/tables/backends/_anndata.py,sha256=EdzGH0Zr85GBjVVBy3OxnRoDGgsi5zZLWRWpSLF2GhQ,2832
|
|
40
|
-
ngio/tables/backends/_anndata_utils.py,sha256=DBWIcR0btnH-DIvDvzlcnMXoYhhtXc9DstryiOP0Qsg,3122
|
|
41
|
-
ngio/tables/backends/_csv.py,sha256=Ev61D-AUKo4LIhXRmWPJgYbHI7eQdxiajQR574DevEM,932
|
|
42
|
-
ngio/tables/backends/_json.py,sha256=1ZsEuXDJm1rOZV_KjFm8CB0qhv7L1W7L2EGWPf4q_p0,3137
|
|
43
|
-
ngio/tables/backends/_non_zarr_backends.py,sha256=SvPPhT6n5TrKUOyV1mNcdHQK49huZ5lwR8EVe9MdydM,7254
|
|
44
|
-
ngio/tables/backends/_parquet.py,sha256=ic-p86h8lce8q9luBJGRzy6vxlWyJvA0-2l5cUD6OqY,1398
|
|
45
|
-
ngio/tables/backends/_table_backends.py,sha256=56lMLrkmRS8-NTwNF0wkMzrRwTmOFLk1g_LBDA2i6wg,7318
|
|
46
|
-
ngio/tables/backends/_utils.py,sha256=tJBSWN6OhO_1ybxl4vT2l3ImB028Fb6h0vaitPRcr8A,19668
|
|
47
|
-
ngio/tables/v1/__init__.py,sha256=Wr1_9RZFpaN8FYMTnxT9Yjkw4AS7y9FMWailmB_uj5g,617
|
|
48
|
-
ngio/tables/v1/_condition_table.py,sha256=T0Uq5BKkmMoEspt_Rx0U99Ow6S9GAMZDHqvUO5obCAM,1780
|
|
49
|
-
ngio/tables/v1/_feature_table.py,sha256=n9uMHwoBh-_dlOhUXCFbmAjXFVXncNCR3SjE2qzXI68,3821
|
|
50
|
-
ngio/tables/v1/_generic_table.py,sha256=1ktJHeuv7U1g5Z8PFUuTkCjOzcYMQd8xegKHKUedJB8,1240
|
|
51
|
-
ngio/tables/v1/_roi_table.py,sha256=DgXhp-DHTeEJwzSsSRSlnPghjMhYGa3IGSpwTt5LKZU,13603
|
|
52
|
-
ngio/utils/__init__.py,sha256=VxPVDKF0QF9HtG8wY0J6PXESNcWLaMXQNZiw5dHflBU,1179
|
|
53
|
-
ngio/utils/_datasets.py,sha256=2g-Neg78dNcqyDz39QQw-Ifp9GITHjVHisdqgvvDNDE,5475
|
|
54
|
-
ngio/utils/_errors.py,sha256=pKQ12LUjQLYE1nUawemA5h7HsgznjaSvV1n2PQU33N0,759
|
|
55
|
-
ngio/utils/_fractal_fsspec_store.py,sha256=RdcCFOgHexRKX9zZvJV5RI-5OPc7VOPS6q_IeRxm24I,1548
|
|
56
|
-
ngio/utils/_logger.py,sha256=HIuqD_2ShfFGDswBddcouStbKfL0Vz_ah8cAIFGhbS8,888
|
|
57
|
-
ngio/utils/_zarr_utils.py,sha256=qOI-HL2HsfFLCj_yxsTR-aq4oHpSqS9KR13aEIvhGDY,13593
|
|
58
|
-
ngio-0.3.4.dist-info/METADATA,sha256=CejDvwMriZ2JvTO2bLW3AA0W3zlAGmWjU10Hw20thy8,5868
|
|
59
|
-
ngio-0.3.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
60
|
-
ngio-0.3.4.dist-info/licenses/LICENSE,sha256=UgN_a1QCeNh9rZWfz-wORQFxE3elQzLWPQaoK6N6fxQ,1502
|
|
61
|
-
ngio-0.3.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|