ngio 0.4.0a3__py3-none-any.whl → 0.4.0b1__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 (54) hide show
  1. ngio/__init__.py +1 -2
  2. ngio/common/__init__.py +2 -51
  3. ngio/common/_dimensions.py +253 -74
  4. ngio/common/_pyramid.py +42 -23
  5. ngio/common/_roi.py +49 -413
  6. ngio/common/_zoom.py +32 -7
  7. ngio/experimental/iterators/__init__.py +0 -2
  8. ngio/experimental/iterators/_abstract_iterator.py +246 -26
  9. ngio/experimental/iterators/_feature.py +90 -52
  10. ngio/experimental/iterators/_image_processing.py +24 -63
  11. ngio/experimental/iterators/_mappers.py +48 -0
  12. ngio/experimental/iterators/_rois_utils.py +4 -4
  13. ngio/experimental/iterators/_segmentation.py +38 -85
  14. ngio/images/_abstract_image.py +192 -95
  15. ngio/images/_create.py +16 -0
  16. ngio/images/_create_synt_container.py +10 -0
  17. ngio/images/_image.py +35 -9
  18. ngio/images/_label.py +26 -3
  19. ngio/images/_masked_image.py +45 -61
  20. ngio/images/_ome_zarr_container.py +33 -0
  21. ngio/io_pipes/__init__.py +75 -0
  22. ngio/io_pipes/_io_pipes.py +361 -0
  23. ngio/io_pipes/_io_pipes_masked.py +488 -0
  24. ngio/io_pipes/_io_pipes_roi.py +152 -0
  25. ngio/io_pipes/_io_pipes_types.py +56 -0
  26. ngio/io_pipes/_match_shape.py +376 -0
  27. ngio/io_pipes/_ops_axes.py +344 -0
  28. ngio/io_pipes/_ops_slices.py +446 -0
  29. ngio/io_pipes/_ops_slices_utils.py +196 -0
  30. ngio/io_pipes/_ops_transforms.py +104 -0
  31. ngio/io_pipes/_zoom_transform.py +175 -0
  32. ngio/ome_zarr_meta/__init__.py +4 -2
  33. ngio/ome_zarr_meta/ngio_specs/__init__.py +4 -4
  34. ngio/ome_zarr_meta/ngio_specs/_axes.py +129 -141
  35. ngio/ome_zarr_meta/ngio_specs/_dataset.py +47 -121
  36. ngio/ome_zarr_meta/ngio_specs/_ngio_image.py +30 -22
  37. ngio/ome_zarr_meta/ngio_specs/_pixel_size.py +17 -1
  38. ngio/ome_zarr_meta/v04/_v04_spec_utils.py +33 -30
  39. ngio/resources/20200812-CardiomyocyteDifferentiation14-Cycle1_B03/nuclei.png +0 -0
  40. ngio/resources/__init__.py +1 -0
  41. ngio/resources/resource_model.py +1 -0
  42. ngio/{common/transforms → transforms}/__init__.py +1 -1
  43. ngio/transforms/_zoom.py +19 -0
  44. ngio/utils/_datasets.py +5 -0
  45. ngio/utils/_zarr_utils.py +5 -1
  46. {ngio-0.4.0a3.dist-info → ngio-0.4.0b1.dist-info}/METADATA +1 -1
  47. ngio-0.4.0b1.dist-info/RECORD +85 -0
  48. ngio/common/_array_io_pipes.py +0 -554
  49. ngio/common/_array_io_utils.py +0 -508
  50. ngio/common/transforms/_label.py +0 -12
  51. ngio/common/transforms/_zoom.py +0 -109
  52. ngio-0.4.0a3.dist-info/RECORD +0 -76
  53. {ngio-0.4.0a3.dist-info → ngio-0.4.0b1.dist-info}/WHEEL +0 -0
  54. {ngio-0.4.0a3.dist-info → ngio-0.4.0b1.dist-info}/licenses/LICENSE +0 -0
ngio/images/_image.py CHANGED
@@ -6,17 +6,20 @@ from typing import Literal
6
6
  import dask.array as da
7
7
  import numpy as np
8
8
  from pydantic import BaseModel, model_validator
9
+ from zarr.types import DIMENSION_SEPARATOR
9
10
 
10
11
  from ngio.common import (
11
- ArrayLike,
12
12
  Dimensions,
13
+ InterpolationOrder,
13
14
  Roi,
14
15
  RoiPixels,
15
- SlicingInputType,
16
- TransformProtocol,
17
16
  )
18
17
  from ngio.images._abstract_image import AbstractImage
19
18
  from ngio.images._create import create_empty_image_container
19
+ from ngio.io_pipes import (
20
+ SlicingInputType,
21
+ TransformProtocol,
22
+ )
20
23
  from ngio.ome_zarr_meta import (
21
24
  ImageMetaHandler,
22
25
  NgioImageMeta,
@@ -269,7 +272,7 @@ class Image(AbstractImage[ImageMetaHandler]):
269
272
  transforms: Sequence[TransformProtocol] | None = None,
270
273
  mode: Literal["numpy", "dask"] = "numpy",
271
274
  **slicing_kwargs: SlicingInputType,
272
- ) -> ArrayLike:
275
+ ) -> np.ndarray | da.Array:
273
276
  """Get the image as a zarr array.
274
277
 
275
278
  Args:
@@ -299,7 +302,7 @@ class Image(AbstractImage[ImageMetaHandler]):
299
302
  transforms: Sequence[TransformProtocol] | None = None,
300
303
  mode: Literal["numpy", "dask"] = "numpy",
301
304
  **slicing_kwargs: SlicingInputType,
302
- ) -> ArrayLike:
305
+ ) -> np.ndarray | da.Array:
303
306
  """Get the image as a zarr array for a region of interest.
304
307
 
305
308
  Args:
@@ -328,7 +331,7 @@ class Image(AbstractImage[ImageMetaHandler]):
328
331
 
329
332
  def set_array(
330
333
  self,
331
- patch: ArrayLike,
334
+ patch: np.ndarray | da.Array,
332
335
  channel_selection: ChannelSlicingInputType = None,
333
336
  axes_order: Sequence[str] | None = None,
334
337
  transforms: Sequence[TransformProtocol] | None = None,
@@ -354,7 +357,7 @@ class Image(AbstractImage[ImageMetaHandler]):
354
357
  def set_roi(
355
358
  self,
356
359
  roi: Roi | RoiPixels,
357
- patch: ArrayLike,
360
+ patch: np.ndarray | da.Array,
358
361
  channel_selection: ChannelSlicingInputType = None,
359
362
  axes_order: Sequence[str] | None = None,
360
363
  transforms: Sequence[TransformProtocol] | None = None,
@@ -383,7 +386,7 @@ class Image(AbstractImage[ImageMetaHandler]):
383
386
 
384
387
  def consolidate(
385
388
  self,
386
- order: Literal[0, 1, 2] = 1,
389
+ order: InterpolationOrder = "linear",
387
390
  mode: Literal["dask", "numpy", "coarsen"] = "dask",
388
391
  ) -> None:
389
392
  """Consolidate the label on disk."""
@@ -601,6 +604,8 @@ class ImagesContainer:
601
604
  name: str | None = None,
602
605
  chunks: Sequence[int] | None = None,
603
606
  dtype: str | None = None,
607
+ dimension_separator: DIMENSION_SEPARATOR | None = None,
608
+ compressor: str | None = None,
604
609
  overwrite: bool = False,
605
610
  ) -> "ImagesContainer":
606
611
  """Create an empty OME-Zarr image from an existing image.
@@ -615,6 +620,10 @@ class ImagesContainer:
615
620
  axes_names (Sequence[str] | None): The axes names of the new image.
616
621
  name (str | None): The name of the new image.
617
622
  chunks (Sequence[int] | None): The chunk shape of the new image.
623
+ dimension_separator (DIMENSION_SEPARATOR | None): The separator to use for
624
+ dimensions. If None it will use the same as the reference image.
625
+ compressor (str | None): The compressor to use. If None it will use
626
+ the same as the reference image.
618
627
  dtype (str | None): The data type of the new image.
619
628
  overwrite (bool): Whether to overwrite an existing image.
620
629
 
@@ -632,6 +641,8 @@ class ImagesContainer:
632
641
  name=name,
633
642
  chunks=chunks,
634
643
  dtype=dtype,
644
+ dimension_separator=dimension_separator,
645
+ compressor=compressor,
635
646
  overwrite=overwrite,
636
647
  )
637
648
 
@@ -714,6 +725,8 @@ def derive_image_container(
714
725
  name: str | None = None,
715
726
  chunks: Sequence[int] | None = None,
716
727
  dtype: str | None = None,
728
+ dimension_separator: DIMENSION_SEPARATOR | None = None,
729
+ compressor=None,
717
730
  overwrite: bool = False,
718
731
  ) -> ImagesContainer:
719
732
  """Create an empty OME-Zarr image from an existing image.
@@ -728,6 +741,10 @@ def derive_image_container(
728
741
  axes_names (Sequence[str] | None): The axes names of the new image.
729
742
  name (str | None): The name of the new image.
730
743
  chunks (Sequence[int] | None): The chunk shape of the new image.
744
+ dimension_separator (DIMENSION_SEPARATOR | None): The separator to use for
745
+ dimensions. If None it will use the same as the reference image.
746
+ compressor: The compressor to use. If None it will use
747
+ the same as the reference image.
731
748
  dtype (str | None): The data type of the new image.
732
749
  overwrite (bool): Whether to overwrite an existing image.
733
750
 
@@ -749,7 +766,7 @@ def derive_image_container(
749
766
  pixel_size = ref_image.pixel_size
750
767
 
751
768
  if axes_names is None:
752
- axes_names = ref_meta.axes_mapper.axes_names
769
+ axes_names = ref_meta.axes_handler.axes_names
753
770
 
754
771
  if len(axes_names) != len(shape):
755
772
  raise NgioValidationError(
@@ -771,6 +788,13 @@ def derive_image_container(
771
788
 
772
789
  if dtype is None:
773
790
  dtype = ref_image.dtype
791
+
792
+ if dimension_separator is None:
793
+ dimension_separator = ref_image.zarr_array._dimension_separator # type: ignore
794
+
795
+ if compressor is None:
796
+ compressor = ref_image.zarr_array.compressor # type: ignore
797
+
774
798
  handler = create_empty_image_container(
775
799
  store=store,
776
800
  shape=shape,
@@ -786,6 +810,8 @@ def derive_image_container(
786
810
  name=name,
787
811
  chunks=chunks,
788
812
  dtype=dtype,
813
+ dimension_separator=dimension_separator, # type: ignore
814
+ compressor=compressor, # type: ignore
789
815
  overwrite=overwrite,
790
816
  version=ref_meta.version,
791
817
  )
ngio/images/_label.py CHANGED
@@ -3,6 +3,8 @@
3
3
  from collections.abc import Sequence
4
4
  from typing import Literal
5
5
 
6
+ from zarr.types import DIMENSION_SEPARATOR
7
+
6
8
  from ngio.common import compute_masking_roi
7
9
  from ngio.images._abstract_image import AbstractImage
8
10
  from ngio.images._create import create_empty_label_container
@@ -94,7 +96,7 @@ class Label(AbstractImage[LabelMetaHandler]):
94
96
  ) -> None:
95
97
  """Consolidate the label on disk."""
96
98
  self._consolidate(
97
- order=0,
99
+ order="nearest",
98
100
  mode=mode,
99
101
  )
100
102
 
@@ -167,6 +169,8 @@ class LabelsContainer:
167
169
  axes_names: Sequence[str] | None = None,
168
170
  chunks: Sequence[int] | None = None,
169
171
  dtype: str = "uint32",
172
+ dimension_separator: DIMENSION_SEPARATOR | None = None,
173
+ compressor=None,
170
174
  overwrite: bool = False,
171
175
  ) -> "Label":
172
176
  """Create an empty OME-Zarr label from a reference image.
@@ -184,6 +188,10 @@ class LabelsContainer:
184
188
  For labels, the channel axis is not allowed.
185
189
  chunks (Sequence[int] | None): The chunk shape of the new image.
186
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.
187
195
  overwrite (bool): Whether to overwrite an existing image.
188
196
 
189
197
  Returns:
@@ -208,6 +216,8 @@ class LabelsContainer:
208
216
  axes_names=axes_names,
209
217
  chunks=chunks,
210
218
  dtype=dtype,
219
+ dimension_separator=dimension_separator,
220
+ compressor=compressor,
211
221
  overwrite=overwrite,
212
222
  )
213
223
 
@@ -226,6 +236,8 @@ def derive_label(
226
236
  pixel_size: PixelSize | None = None,
227
237
  axes_names: Sequence[str] | None = None,
228
238
  chunks: Sequence[int] | None = None,
239
+ dimension_separator: DIMENSION_SEPARATOR | None = None,
240
+ compressor=None,
229
241
  dtype: str = "uint32",
230
242
  overwrite: bool = False,
231
243
  ) -> None:
@@ -242,6 +254,10 @@ def derive_label(
242
254
  For labels, the channel axis is not allowed.
243
255
  chunks (Sequence[int] | None): The chunk shape of the new image.
244
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.
245
261
  overwrite (bool): Whether to overwrite an existing image.
246
262
 
247
263
  Returns:
@@ -257,8 +273,8 @@ def derive_label(
257
273
  pixel_size = ref_image.pixel_size
258
274
 
259
275
  if axes_names is None:
260
- axes_names = ref_meta.axes_mapper.axes_names
261
- 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")
262
278
  else:
263
279
  if "c" in axes_names:
264
280
  raise NgioValidationError(
@@ -291,6 +307,11 @@ def derive_label(
291
307
  axes_names = list(axes_names)
292
308
  axes_names = axes_names[:c_axis] + axes_names[c_axis + 1 :]
293
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
+
294
315
  _ = create_empty_label_container(
295
316
  store=store,
296
317
  shape=shape,
@@ -305,6 +326,8 @@ def derive_label(
305
326
  axes_names=axes_names,
306
327
  chunks=chunks,
307
328
  dtype=dtype,
329
+ dimension_separator=dimension_separator, # type: ignore
330
+ compressor=compressor, # type: ignore
308
331
  overwrite=overwrite,
309
332
  version=ref_meta.version,
310
333
  name=name,
@@ -6,14 +6,6 @@ from typing import Literal
6
6
  import dask.array as da
7
7
  import numpy as np
8
8
 
9
- from ngio.common import (
10
- ArrayLike,
11
- TransformProtocol,
12
- build_roi_masked_dask_getter,
13
- build_roi_masked_dask_setter,
14
- build_roi_masked_numpy_getter,
15
- build_roi_masked_numpy_setter,
16
- )
17
9
  from ngio.images._image import (
18
10
  ChannelSlicingInputType,
19
11
  Image,
@@ -21,6 +13,13 @@ from ngio.images._image import (
21
13
  add_channel_selection_to_slicing_dict,
22
14
  )
23
15
  from ngio.images._label import Label
16
+ from ngio.io_pipes import (
17
+ DaskGetterMasked,
18
+ DaskSetterMasked,
19
+ NumpyGetterMasked,
20
+ NumpySetterMasked,
21
+ TransformProtocol,
22
+ )
24
23
  from ngio.ome_zarr_meta import ImageMetaHandler, LabelMetaHandler
25
24
  from ngio.tables import MaskingRoiTable
26
25
  from ngio.utils import (
@@ -70,7 +69,7 @@ class MaskedImage(Image):
70
69
  axes_order: Sequence[str] | None = None,
71
70
  transforms: Sequence[TransformProtocol] | None = None,
72
71
  **slicing_kwargs: slice | int | Sequence[int],
73
- ) -> ArrayLike:
72
+ ) -> np.ndarray:
74
73
  """Return the array for a given ROI."""
75
74
  roi = self._masking_roi_table.get_label(label)
76
75
  roi = roi.zoom(zoom_factor)
@@ -111,7 +110,7 @@ class MaskedImage(Image):
111
110
  transforms: Sequence[TransformProtocol] | None = None,
112
111
  mode: Literal["numpy", "dask"] = "numpy",
113
112
  **slicing_kwargs: slice | int | Sequence[int],
114
- ) -> ArrayLike:
113
+ ) -> np.ndarray | da.Array:
115
114
  """Return the array for a given ROI."""
116
115
  roi = self._masking_roi_table.get_label(label)
117
116
  roi = roi.zoom(zoom_factor)
@@ -127,7 +126,7 @@ class MaskedImage(Image):
127
126
  def set_roi( # type: ignore (this ignore the method override issue)
128
127
  self,
129
128
  label: int,
130
- patch: ArrayLike,
129
+ patch: np.ndarray | da.Array,
131
130
  zoom_factor: float = 1.0,
132
131
  channel_selection: ChannelSlicingInputType | None = None,
133
132
  axes_order: Sequence[str] | None = None,
@@ -153,7 +152,7 @@ class MaskedImage(Image):
153
152
  zoom_factor: float = 1.0,
154
153
  axes_order: Sequence[str] | None = None,
155
154
  transforms: Sequence[TransformProtocol] | None = None,
156
- allow_scaling: bool = True,
155
+ allow_rescaling: bool = True,
157
156
  **slicing_kwargs: SlicingInputType,
158
157
  ) -> np.ndarray:
159
158
  """Return the masked array for a given label as a NumPy array."""
@@ -163,18 +162,16 @@ class MaskedImage(Image):
163
162
 
164
163
  roi = self._masking_roi_table.get_label(label)
165
164
  roi = roi.zoom(zoom_factor)
166
- masked_getter = build_roi_masked_numpy_getter(
165
+ masked_getter = NumpyGetterMasked(
167
166
  roi=roi,
168
167
  zarr_array=self.zarr_array,
169
168
  label_zarr_array=self._label.zarr_array,
170
169
  dimensions=self.dimensions,
171
- pixel_size=self.pixel_size,
172
170
  label_dimensions=self._label.dimensions,
173
- label_pixel_size=self._label.pixel_size,
174
171
  axes_order=axes_order,
175
172
  transforms=transforms,
176
173
  slicing_dict=slicing_kwargs,
177
- allow_scaling=allow_scaling,
174
+ allow_rescaling=allow_rescaling,
178
175
  )
179
176
  return masked_getter()
180
177
 
@@ -185,7 +182,7 @@ class MaskedImage(Image):
185
182
  zoom_factor: float = 1.0,
186
183
  axes_order: Sequence[str] | None = None,
187
184
  transforms: Sequence[TransformProtocol] | None = None,
188
- allow_scaling: bool = True,
185
+ allow_rescaling: bool = True,
189
186
  **slicing_kwargs: SlicingInputType,
190
187
  ) -> da.Array:
191
188
  """Return the masked array for a given label as a Dask array."""
@@ -195,18 +192,16 @@ class MaskedImage(Image):
195
192
 
196
193
  roi = self._masking_roi_table.get_label(label)
197
194
  roi = roi.zoom(zoom_factor)
198
- masked_getter = build_roi_masked_dask_getter(
195
+ masked_getter = DaskGetterMasked(
199
196
  roi=roi,
200
197
  zarr_array=self.zarr_array,
201
198
  label_zarr_array=self._label.zarr_array,
202
199
  dimensions=self.dimensions,
203
- pixel_size=self.pixel_size,
204
200
  label_dimensions=self._label.dimensions,
205
- label_pixel_size=self._label.pixel_size,
206
201
  axes_order=axes_order,
207
202
  transforms=transforms,
208
203
  slicing_dict=slicing_kwargs,
209
- allow_scaling=allow_scaling,
204
+ allow_rescaling=allow_rescaling,
210
205
  )
211
206
  return masked_getter()
212
207
 
@@ -218,9 +213,9 @@ class MaskedImage(Image):
218
213
  axes_order: Sequence[str] | None = None,
219
214
  transforms: Sequence[TransformProtocol] | None = None,
220
215
  mode: Literal["numpy", "dask"] = "numpy",
221
- allow_scaling: bool = True,
216
+ allow_rescaling: bool = True,
222
217
  **slicing_kwargs: SlicingInputType,
223
- ) -> ArrayLike:
218
+ ) -> np.ndarray | da.Array:
224
219
  """Return the masked array for a given label."""
225
220
  if mode == "numpy":
226
221
  return self.get_roi_masked_as_numpy(
@@ -229,9 +224,10 @@ class MaskedImage(Image):
229
224
  zoom_factor=zoom_factor,
230
225
  axes_order=axes_order,
231
226
  transforms=transforms,
232
- allow_scaling=allow_scaling,
227
+ allow_rescaling=allow_rescaling,
233
228
  **slicing_kwargs,
234
229
  )
230
+
235
231
  elif mode == "dask":
236
232
  return self.get_roi_masked_as_dask(
237
233
  label=label,
@@ -239,7 +235,7 @@ class MaskedImage(Image):
239
235
  zoom_factor=zoom_factor,
240
236
  axes_order=axes_order,
241
237
  transforms=transforms,
242
- allow_scaling=allow_scaling,
238
+ allow_rescaling=allow_rescaling,
243
239
  **slicing_kwargs,
244
240
  )
245
241
  else:
@@ -248,12 +244,12 @@ class MaskedImage(Image):
248
244
  def set_roi_masked(
249
245
  self,
250
246
  label: int,
251
- patch: ArrayLike,
247
+ patch: np.ndarray | da.Array,
252
248
  channel_selection: ChannelSlicingInputType | None = None,
253
249
  axes_order: Sequence[str] | None = None,
254
250
  zoom_factor: float = 1.0,
255
251
  transforms: Sequence[TransformProtocol] | None = None,
256
- allow_scaling: bool = True,
252
+ allow_rescaling: bool = True,
257
253
  **slicing_kwargs: SlicingInputType,
258
254
  ) -> None:
259
255
  """Set the masked array for a given label."""
@@ -264,33 +260,29 @@ class MaskedImage(Image):
264
260
  roi = self._masking_roi_table.get_label(label)
265
261
  roi = roi.zoom(zoom_factor)
266
262
  if isinstance(patch, da.Array):
267
- path_setter = build_roi_masked_dask_setter(
263
+ path_setter = DaskSetterMasked(
268
264
  roi=roi,
269
265
  zarr_array=self.zarr_array,
270
266
  label_zarr_array=self._label.zarr_array,
271
267
  dimensions=self.dimensions,
272
- pixel_size=self.pixel_size,
273
268
  label_dimensions=self._label.dimensions,
274
- label_pixel_size=self._label.pixel_size,
275
269
  axes_order=axes_order,
276
270
  transforms=transforms,
277
271
  slicing_dict=slicing_kwargs,
278
- allow_scaling=allow_scaling,
272
+ allow_rescaling=allow_rescaling,
279
273
  )
280
274
  path_setter(patch)
281
275
  elif isinstance(patch, np.ndarray):
282
- path_setter = build_roi_masked_numpy_setter(
276
+ path_setter = NumpySetterMasked(
283
277
  roi=roi,
284
278
  zarr_array=self.zarr_array,
285
279
  label_zarr_array=self._label.zarr_array,
286
280
  dimensions=self.dimensions,
287
- pixel_size=self.pixel_size,
288
281
  label_dimensions=self._label.dimensions,
289
- label_pixel_size=self._label.pixel_size,
290
282
  axes_order=axes_order,
291
283
  transforms=transforms,
292
284
  slicing_dict=slicing_kwargs,
293
- allow_scaling=allow_scaling,
285
+ allow_rescaling=allow_rescaling,
294
286
  )
295
287
  path_setter(patch)
296
288
  else:
@@ -378,7 +370,7 @@ class MaskedLabel(Label):
378
370
  mode: Literal["numpy", "dask"] = "numpy",
379
371
  transforms: Sequence[TransformProtocol] | None = None,
380
372
  **slicing_kwargs: slice | int | Sequence[int],
381
- ) -> ArrayLike:
373
+ ) -> np.ndarray | da.Array:
382
374
  """Return the array for a given ROI."""
383
375
  roi = self._masking_roi_table.get_label(label)
384
376
  roi = roi.zoom(zoom_factor)
@@ -393,7 +385,7 @@ class MaskedLabel(Label):
393
385
  def set_roi(
394
386
  self,
395
387
  label: int,
396
- patch: ArrayLike,
388
+ patch: np.ndarray | da.Array,
397
389
  zoom_factor: float = 1.0,
398
390
  axes_order: Sequence[str] | None = None,
399
391
  transforms: Sequence[TransformProtocol] | None = None,
@@ -416,24 +408,22 @@ class MaskedLabel(Label):
416
408
  zoom_factor: float = 1.0,
417
409
  axes_order: Sequence[str] | None = None,
418
410
  transforms: Sequence[TransformProtocol] | None = None,
419
- allow_scaling: bool = True,
411
+ allow_rescaling: bool = True,
420
412
  **slicing_kwargs: SlicingInputType,
421
413
  ) -> np.ndarray:
422
414
  """Return the masked array for a given label as a NumPy array."""
423
415
  roi = self._masking_roi_table.get_label(label)
424
416
  roi = roi.zoom(zoom_factor)
425
- masked_getter = build_roi_masked_numpy_getter(
417
+ masked_getter = NumpyGetterMasked(
426
418
  roi=roi,
427
419
  zarr_array=self.zarr_array,
428
420
  label_zarr_array=self._label.zarr_array,
429
421
  dimensions=self.dimensions,
430
- pixel_size=self.pixel_size,
431
422
  label_dimensions=self._label.dimensions,
432
- label_pixel_size=self._label.pixel_size,
433
423
  axes_order=axes_order,
434
424
  transforms=transforms,
435
425
  slicing_dict=slicing_kwargs,
436
- allow_scaling=allow_scaling,
426
+ allow_rescaling=allow_rescaling,
437
427
  )
438
428
  return masked_getter()
439
429
 
@@ -443,24 +433,22 @@ class MaskedLabel(Label):
443
433
  zoom_factor: float = 1.0,
444
434
  axes_order: Sequence[str] | None = None,
445
435
  transforms: Sequence[TransformProtocol] | None = None,
446
- allow_scaling: bool = True,
436
+ allow_rescaling: bool = True,
447
437
  **slicing_kwargs: SlicingInputType,
448
438
  ) -> da.Array:
449
439
  """Return the masked array for a given label as a Dask array."""
450
440
  roi = self._masking_roi_table.get_label(label)
451
441
  roi = roi.zoom(zoom_factor)
452
- masked_getter = build_roi_masked_dask_getter(
442
+ masked_getter = DaskGetterMasked(
453
443
  roi=roi,
454
444
  zarr_array=self.zarr_array,
455
445
  label_zarr_array=self._label.zarr_array,
456
446
  dimensions=self.dimensions,
457
- pixel_size=self.pixel_size,
458
447
  label_dimensions=self._label.dimensions,
459
- label_pixel_size=self._label.pixel_size,
460
448
  axes_order=axes_order,
461
449
  transforms=transforms,
462
450
  slicing_dict=slicing_kwargs,
463
- allow_scaling=allow_scaling,
451
+ allow_rescaling=allow_rescaling,
464
452
  )
465
453
  return masked_getter()
466
454
 
@@ -471,9 +459,9 @@ class MaskedLabel(Label):
471
459
  axes_order: Sequence[str] | None = None,
472
460
  mode: Literal["numpy", "dask"] = "numpy",
473
461
  transforms: Sequence[TransformProtocol] | None = None,
474
- allow_scaling: bool = True,
462
+ allow_rescaling: bool = True,
475
463
  **slicing_kwargs: SlicingInputType,
476
- ) -> ArrayLike:
464
+ ) -> np.ndarray | da.Array:
477
465
  """Return the masked array for a given label."""
478
466
  if mode == "numpy":
479
467
  return self.get_roi_masked_as_numpy(
@@ -481,7 +469,7 @@ class MaskedLabel(Label):
481
469
  zoom_factor=zoom_factor,
482
470
  axes_order=axes_order,
483
471
  transforms=transforms,
484
- allow_scaling=allow_scaling,
472
+ allow_rescaling=allow_rescaling,
485
473
  **slicing_kwargs,
486
474
  )
487
475
 
@@ -491,7 +479,7 @@ class MaskedLabel(Label):
491
479
  zoom_factor=zoom_factor,
492
480
  axes_order=axes_order,
493
481
  transforms=transforms,
494
- allow_scaling=allow_scaling,
482
+ allow_rescaling=allow_rescaling,
495
483
  **slicing_kwargs,
496
484
  )
497
485
  else:
@@ -500,44 +488,40 @@ class MaskedLabel(Label):
500
488
  def set_roi_masked(
501
489
  self,
502
490
  label: int,
503
- patch: ArrayLike,
491
+ patch: np.ndarray | da.Array,
504
492
  axes_order: Sequence[str] | None = None,
505
493
  zoom_factor: float = 1.0,
506
494
  transforms: Sequence[TransformProtocol] | None = None,
507
- allow_scaling: bool = True,
495
+ allow_rescaling: bool = True,
508
496
  **slicing_kwargs: SlicingInputType,
509
497
  ) -> None:
510
498
  """Set the masked array for a given label."""
511
499
  roi = self._masking_roi_table.get_label(label)
512
500
  roi = roi.zoom(zoom_factor)
513
501
  if isinstance(patch, da.Array):
514
- path_setter = build_roi_masked_dask_setter(
502
+ path_setter = DaskSetterMasked(
515
503
  roi=roi,
516
504
  zarr_array=self.zarr_array,
517
505
  label_zarr_array=self._label.zarr_array,
518
506
  dimensions=self.dimensions,
519
- pixel_size=self.pixel_size,
520
507
  label_dimensions=self._label.dimensions,
521
- label_pixel_size=self._label.pixel_size,
522
508
  axes_order=axes_order,
523
509
  transforms=transforms,
524
510
  slicing_dict=slicing_kwargs,
525
- allow_scaling=allow_scaling,
511
+ allow_rescaling=allow_rescaling,
526
512
  )
527
513
  path_setter(patch)
528
514
  elif isinstance(patch, np.ndarray):
529
- path_setter = build_roi_masked_numpy_setter(
515
+ path_setter = NumpySetterMasked(
530
516
  roi=roi,
531
517
  zarr_array=self.zarr_array,
532
518
  label_zarr_array=self._label.zarr_array,
533
519
  dimensions=self.dimensions,
534
- pixel_size=self.pixel_size,
535
520
  label_dimensions=self._label.dimensions,
536
- label_pixel_size=self._label.pixel_size,
537
521
  axes_order=axes_order,
538
522
  transforms=transforms,
539
523
  slicing_dict=slicing_kwargs,
540
- allow_scaling=allow_scaling,
524
+ allow_rescaling=allow_rescaling,
541
525
  )
542
526
  path_setter(patch)
543
527
  else: