ngio 0.5.0b3__py3-none-any.whl → 0.5.0b5__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.
@@ -1,6 +1,7 @@
1
1
  """Utilities to build masking regions of interest (ROIs)."""
2
2
 
3
3
  import itertools
4
+ from collections.abc import Sequence
4
5
 
5
6
  import dask.array as da
6
7
  import numpy as np
@@ -115,7 +116,9 @@ def lazy_compute_slices(segmentation: da.Array) -> dict[int, tuple[slice, ...]]:
115
116
 
116
117
 
117
118
  def compute_masking_roi(
118
- segmentation: np.ndarray | da.Array, pixel_size: PixelSize
119
+ segmentation: np.ndarray | da.Array,
120
+ pixel_size: PixelSize,
121
+ axes_order: Sequence[str],
119
122
  ) -> list[Roi]:
120
123
  """Compute a ROIs for each label in a segmentation.
121
124
 
@@ -127,6 +130,12 @@ def compute_masking_roi(
127
130
  if segmentation.ndim not in [2, 3, 4]:
128
131
  raise NgioValueError("Only 2D, 3D, and 4D segmentations are supported.")
129
132
 
133
+ if len(axes_order) != segmentation.ndim:
134
+ raise NgioValueError(
135
+ "The length of axes_order must match the number of dimensions "
136
+ "of the segmentation."
137
+ )
138
+
130
139
  if isinstance(segmentation, da.Array):
131
140
  slices = lazy_compute_slices(segmentation)
132
141
  else:
@@ -134,24 +143,11 @@ def compute_masking_roi(
134
143
 
135
144
  rois = []
136
145
  for label, slice_ in slices.items():
137
- if len(slice_) == 2:
138
- slices = {"y": slice_[0], "x": slice_[1]}
139
- elif len(slice_) == 3:
140
- slices = {"z": slice_[0], "y": slice_[1], "x": slice_[2]}
141
- elif len(slice_) == 4:
142
- slices = {
143
- "t": slice_[0],
144
- "z": slice_[1],
145
- "y": slice_[2],
146
- "x": slice_[3],
147
- }
148
- else:
149
- raise ValueError("Invalid slice length.")
150
-
146
+ assert len(slice_) == len(axes_order)
147
+ slices = dict(zip(axes_order, slice_, strict=True))
151
148
  roi = Roi.from_values(
152
149
  name=str(label), slices=slices, label=label, space="pixel"
153
150
  )
154
-
155
151
  roi = roi.to_world(pixel_size=pixel_size)
156
152
  rois.append(roi)
157
153
  return rois
ngio/common/_pyramid.py CHANGED
@@ -92,16 +92,7 @@ def _on_disk_coarsen(
92
92
 
93
93
  coarsening_setup = {}
94
94
  for i, s in enumerate(_scale):
95
- factor = 1 / s
96
- # This check is very strict, but it is necessary to avoid
97
- # a few pixels shift in the coarsening
98
- # We could add a tolerance
99
- if factor.is_integer():
100
- coarsening_setup[i] = int(factor)
101
- else:
102
- raise NgioValueError(
103
- f"Coarsening factor must be an integer, got {factor} on axis {i}"
104
- )
95
+ coarsening_setup[i] = int(np.round(1 / s))
105
96
 
106
97
  out_target = da.coarsen(
107
98
  aggregation_function, source_array, coarsening_setup, trim_excess=True
ngio/common/_roi.py CHANGED
@@ -4,7 +4,7 @@ These are the interfaces bwteen the ROI tables / masking ROI tables and
4
4
  the ImageLikeHandler.
5
5
  """
6
6
 
7
- from collections.abc import Callable
7
+ from collections.abc import Callable, Mapping
8
8
  from typing import Literal, Self
9
9
 
10
10
  from pydantic import BaseModel, ConfigDict, Field, field_validator
@@ -183,7 +183,7 @@ class Roi(BaseModel):
183
183
  @classmethod
184
184
  def from_values(
185
185
  cls,
186
- slices: dict[str, float | tuple[float | None, float | None] | slice],
186
+ slices: Mapping[str, float | tuple[float | None, float | None] | slice],
187
187
  name: str | None,
188
188
  label: int | None = None,
189
189
  space: Literal["world", "pixel"] = "world",
@@ -615,7 +615,6 @@ def _shapes_from_ref_image(
615
615
  if len(shapes) == len(paths):
616
616
  return shapes
617
617
  missing_levels = len(paths) - len(shapes)
618
- print(ref_image.meta.scaling_factor())
619
618
  extended_shapes = shapes_from_scaling_factors(
620
619
  base_shape=shapes[-1],
621
620
  scaling_factors=ref_image.meta.scaling_factor(),
@@ -918,7 +917,6 @@ def abstract_derive(
918
917
 
919
918
  if chunks is None:
920
919
  chunks = ref_image.zarr_array.chunks
921
- print(chunks)
922
920
  if shards is None:
923
921
  shards = ref_image.zarr_array.shards
924
922
 
ngio/images/_label.py CHANGED
@@ -97,9 +97,11 @@ class Label(AbstractImage):
97
97
  meta = meta.to_units(space_unit=space_unit, time_unit=time_unit)
98
98
  self.meta_handler.update_meta(meta)
99
99
 
100
- def build_masking_roi_table(self) -> MaskingRoiTable:
100
+ def build_masking_roi_table(
101
+ self, axes_order: Sequence[str] | None = None
102
+ ) -> MaskingRoiTable:
101
103
  """Compute the masking ROI table."""
102
- return build_masking_roi_table(self)
104
+ return build_masking_roi_table(self, axes_order=axes_order)
103
105
 
104
106
  def consolidate(
105
107
  self,
@@ -405,8 +407,11 @@ def derive_label(
405
407
  return group_handler
406
408
 
407
409
 
408
- def build_masking_roi_table(label: Label) -> MaskingRoiTable:
410
+ def build_masking_roi_table(
411
+ label: Label, axes_order: Sequence[str] | None = None
412
+ ) -> MaskingRoiTable:
409
413
  """Compute the masking ROI table for a label."""
410
- array = label.get_as_dask(axes_order=["t", "z", "y", "x"])
411
- rois = compute_masking_roi(array, label.pixel_size)
414
+ axes_order = axes_order or label.axes
415
+ array = label.get_as_dask(axes_order=axes_order)
416
+ rois = compute_masking_roi(array, label.pixel_size, axes_order=axes_order)
412
417
  return MaskingRoiTable(rois, reference_label=label.meta.name)
ngio/utils/_datasets.py CHANGED
@@ -155,5 +155,11 @@ def download_ome_zarr_dataset(
155
155
  path=download_dir,
156
156
  processor=processor,
157
157
  progressbar=progressbar,
158
+ # Add User-Agent to avoid 403 errors from Zenodo
159
+ downloader=pooch.HTTPDownloader(
160
+ headers={
161
+ "User-Agent": f"pooch/{pooch.__version__} (https://github.com/BioVisionCenter/ngio)"
162
+ }
163
+ ),
158
164
  )
159
165
  return processor.output_file()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ngio
3
- Version: 0.5.0b3
3
+ Version: 0.5.0b5
4
4
  Summary: Next Generation file format IO
5
5
  Project-URL: homepage, https://github.com/BioVisionCenter/ngio
6
6
  Project-URL: repository, https://github.com/BioVisionCenter/ngio
@@ -13,8 +13,9 @@ Classifier: Programming Language :: Python :: 3
13
13
  Classifier: Programming Language :: Python :: 3.11
14
14
  Classifier: Programming Language :: Python :: 3.12
15
15
  Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Programming Language :: Python :: 3.14
16
17
  Classifier: Typing :: Typed
17
- Requires-Python: <3.14,>=3.11
18
+ Requires-Python: <3.15,>=3.11
18
19
  Requires-Dist: aiohttp
19
20
  Requires-Dist: anndata
20
21
  Requires-Dist: dask[array]<2025.11.0
@@ -1,9 +1,9 @@
1
1
  ngio/__init__.py,sha256=kyInohhWrBs4qkbMYFIQeAiy1CDpvbSOtXB4buFocbw,1535
2
2
  ngio/common/__init__.py,sha256=F3zAHQIhwig1xUA-SpmFVRtMeOrEj926-nHWhj-wS6c,684
3
3
  ngio/common/_dimensions.py,sha256=w8PYgyWxA8hgJETjFbw5CXf7WrasCL5FbzgfL1in86M,11361
4
- ngio/common/_masking_roi.py,sha256=YSEZ5nv3-TqMrQ04cI70U9NGx3LSy7Z1_cbw_NE-78k,4831
5
- ngio/common/_pyramid.py,sha256=JRqVm9eFyxHi1a2hCcAoTJU3L8vctRHbkVWkskyQG_U,14354
6
- ngio/common/_roi.py,sha256=UMr7ie7dIZ6gMcM0_AlFMev_PRKxBdzUy_1WKRZ4zQU,11403
4
+ ngio/common/_masking_roi.py,sha256=rWOvhT08KfxX5djvUsX6LsUVofyU0Fq5LcUmpOYElDg,4757
5
+ ngio/common/_pyramid.py,sha256=kvtacAhJb8zcV5ungNPYRDBShgti-kxtD_4LdBpnyDw,14012
6
+ ngio/common/_roi.py,sha256=G2KICRbxlYenbc1qmKmdxLrfJRmqYSUbeaBdEuUYW-Q,11415
7
7
  ngio/common/_synt_images_utils.py,sha256=B6uYOW1NyrM06YMR-csca3_YnAAkPRTbvnbLdy9tk9E,3188
8
8
  ngio/common/_zoom.py,sha256=U01c-vqXjzZkrpd9Yvs24frVfTls_xPJeeaFCGmUwYI,6727
9
9
  ngio/experimental/__init__.py,sha256=3pmBtHi-i8bKjTsvrOJM56ZyRX3Pv_dceCdt88-8COQ,147
@@ -17,11 +17,11 @@ ngio/experimental/iterators/_segmentation.py,sha256=xzotGvTn04HPeMeXZ_URnQqWco6d
17
17
  ngio/hcs/__init__.py,sha256=G8j9vD-liLeB_UeGtKYIgshWvJnUA6ks9GwjvWBLdHs,357
18
18
  ngio/hcs/_plate.py,sha256=l2a2ZMniutxRzZ88HOYwajug-svr6OanREG5mTy39x0,45773
19
19
  ngio/images/__init__.py,sha256=9Whvt7GTiCgT_vXaEEqGnDaY1-UsRk3dhLTv091F_g4,1211
20
- ngio/images/_abstract_image.py,sha256=gvOS7Nb52pgLgtBpvu3vYxwbSocqw2w-sEsJaJVrHWE,31925
20
+ ngio/images/_abstract_image.py,sha256=n7xIURa3QCfTuBZz-g58y0Q2maG41AL79C9Ae8I08Ko,31864
21
21
  ngio/images/_create_synt_container.py,sha256=Cvg_J0KSxK0PH8IBzlKLIcCwH2vRTuBj-nZo5uOKXXk,5182
22
22
  ngio/images/_create_utils.py,sha256=hXVbFM8D_0mZTfBAhcZiuGX2lLXSJCep8THuxpH4d4E,14374
23
23
  ngio/images/_image.py,sha256=A2dE9O3L1dLU3gdjQrNCFUYDF_NuxTxVm8klmBfmPCc,34792
24
- ngio/images/_label.py,sha256=0dqLKBVibqw6scSTWxzSyxjnXLs-fhBGQzol8C5Rzok,15676
24
+ ngio/images/_label.py,sha256=P4m6K6xaYoE7XrpCxbxHQwJOHncXdmXY057ZUv4a76E,15856
25
25
  ngio/images/_masked_image.py,sha256=YhbBzgPZMav6rX0WYue1BaxAzEIsfaQrxUIOK6ZWZcw,18848
26
26
  ngio/images/_ome_zarr_container.py,sha256=mD1PEos33EfapkUVMJnSZdQiQI57cZa_bB2hdEEJQuM,48276
27
27
  ngio/images/_table_ops.py,sha256=jFv_AMqoB4JBpoWsMtZppZVW7dAOC_u-JpfNm8b33kY,15292
@@ -78,11 +78,11 @@ ngio/transforms/__init__.py,sha256=JA0-Ui7skbXkm9ofN-AEhU1FTLutkMkwTdVD-310frQ,1
78
78
  ngio/transforms/_zoom.py,sha256=otyE-vxFnywUJ8U4mHjat-bNG_7_jv62ckTpqDMxyVQ,550
79
79
  ngio/utils/__init__.py,sha256=d2OHQGMFPpf8-_ipuqquxtqCNGJpX5yXt34A65nScUU,1037
80
80
  ngio/utils/_cache.py,sha256=Ey9fgc_BTdMyqg6c80C0CuGDhOafln8-3e_1MQ0MFzw,1283
81
- ngio/utils/_datasets.py,sha256=6GtxfPkjutNaeg5BHuJDBP0GudvQXHLU6mmHp_o0bGA,5650
81
+ ngio/utils/_datasets.py,sha256=YOV367skFA8nbKAqbyK0EsUU7E9UId_u5ButuLesrzk,5896
82
82
  ngio/utils/_errors.py,sha256=pKQ12LUjQLYE1nUawemA5h7HsgznjaSvV1n2PQU33N0,759
83
83
  ngio/utils/_fractal_fsspec_store.py,sha256=RdcCFOgHexRKX9zZvJV5RI-5OPc7VOPS6q_IeRxm24I,1548
84
84
  ngio/utils/_zarr_utils.py,sha256=MVbW-a0S3iuzMaknqkliJa_lp8i6mEO4Q2YN2XxmeDw,18158
85
- ngio-0.5.0b3.dist-info/METADATA,sha256=cTOSheYJVPvHvY-3CTTSxPXudzxMzGbN98tkvpFBzbs,6331
86
- ngio-0.5.0b3.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
87
- ngio-0.5.0b3.dist-info/licenses/LICENSE,sha256=UgN_a1QCeNh9rZWfz-wORQFxE3elQzLWPQaoK6N6fxQ,1502
88
- ngio-0.5.0b3.dist-info/RECORD,,
85
+ ngio-0.5.0b5.dist-info/METADATA,sha256=kDswYTjCsCUVZUZc2TA-tNK9CZZ4PhncumU74hE8vXc,6382
86
+ ngio-0.5.0b5.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
87
+ ngio-0.5.0b5.dist-info/licenses/LICENSE,sha256=UgN_a1QCeNh9rZWfz-wORQFxE3elQzLWPQaoK6N6fxQ,1502
88
+ ngio-0.5.0b5.dist-info/RECORD,,
File without changes