ngio 0.1.5__py3-none-any.whl → 0.1.6__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/core/ngff_image.py CHANGED
@@ -152,7 +152,7 @@ class NgffImage:
152
152
 
153
153
  if meta.omero is None:
154
154
  raise NotImplementedError(
155
- "OMERO metadata not found. " " Please add OMERO metadata to the image."
155
+ "OMERO metadata not found. Please add OMERO metadata to the image."
156
156
  )
157
157
 
158
158
  channel_list = meta.omero.channels
@@ -269,7 +269,7 @@ class NgffImage:
269
269
 
270
270
  if meta.omero is None:
271
271
  raise NotImplementedError(
272
- "OMERO metadata not found. " " Please add OMERO metadata to the image."
272
+ "OMERO metadata not found. Please add OMERO metadata to the image."
273
273
  )
274
274
 
275
275
  channel_list = meta.omero.channels
ngio/core/utils.py CHANGED
@@ -67,17 +67,17 @@ def _build_empty_pyramid(
67
67
 
68
68
  if chunks is not None and len(on_disk_shape) != len(chunks):
69
69
  raise ValueError(
70
- "The shape and chunks must have the same number " "of dimensions."
70
+ "The shape and chunks must have the same number of dimensions."
71
71
  )
72
72
 
73
73
  if len(on_disk_shape) != len(scaling_factor):
74
74
  raise ValueError(
75
- "The shape and scaling factor must have the same number " "of dimensions."
75
+ "The shape and scaling factor must have the same number of dimensions."
76
76
  )
77
77
 
78
78
  if len(on_disk_shape) != len(on_disk_axis):
79
79
  raise ValueError(
80
- "The shape and on-disk axis must have the same number " "of dimensions."
80
+ "The shape and on-disk axis must have the same number of dimensions."
81
81
  )
82
82
 
83
83
  for dataset in image_meta.datasets:
@@ -50,8 +50,7 @@ def open_group_wrapper(
50
50
  if isinstance(store, zarr.Group):
51
51
  _group = _pass_through_group(store, mode=mode, zarr_format=zarr_format)
52
52
  ngio_logger.debug(
53
- f"Passing through group: {_group}, "
54
- f"located in store: {_group.store.path}"
53
+ f"Passing through group: {_group}, located in store: {_group.store.path}"
55
54
  )
56
55
  return _group
57
56
 
ngio/pipes/_zoom_utils.py CHANGED
@@ -4,7 +4,48 @@ from typing import Literal
4
4
  import dask.array as da
5
5
  import numpy as np
6
6
  import zarr
7
- from scipy.ndimage import zoom
7
+ from scipy.ndimage import zoom as scipy_zoom
8
+
9
+
10
+ def _stacked_zoom(x, zoom_y, zoom_x, order=1, mode="grid-constant", grid_mode=True):
11
+ *rest, yshape, xshape = x.shape
12
+ x = x.reshape(-1, yshape, xshape)
13
+ scale_xy = (zoom_y, zoom_x)
14
+ x_out = np.stack(
15
+ [
16
+ scipy_zoom(x[i], scale_xy, order=order, mode=mode, grid_mode=True)
17
+ for i in range(x.shape[0])
18
+ ]
19
+ )
20
+ return x_out.reshape(*rest, *x_out.shape[1:])
21
+
22
+
23
+ def fast_zoom(x, zoom, order=1, mode="grid-constant", grid_mode=True, auto_stack=True):
24
+ """Fast zoom function.
25
+
26
+ Scipy zoom function that can handle singleton dimensions
27
+ but the performance degrades with the number of dimensions.
28
+
29
+ This function has two small optimizations:
30
+ - it removes singleton dimensions before calling zoom
31
+ - if it detects that the zoom is only on the last two dimensions
32
+ it stacks the first dimensions to call zoom only on the last two.
33
+ """
34
+ mask = np.isclose(x.shape, 1)
35
+ zoom = np.array(zoom)
36
+ singletons = tuple(np.where(mask)[0])
37
+ xs = np.squeeze(x, axis=singletons)
38
+ new_zoom = zoom[~mask]
39
+
40
+ *zoom_rest, zoom_y, zoom_x = new_zoom
41
+ if auto_stack and np.allclose(zoom_rest, 1):
42
+ xs = _stacked_zoom(
43
+ xs, zoom_y, zoom_x, order=order, mode=mode, grid_mode=grid_mode
44
+ )
45
+ else:
46
+ xs = scipy_zoom(xs, new_zoom, order=order, mode=mode, grid_mode=grid_mode)
47
+ x = np.expand_dims(xs, axis=singletons)
48
+ return x
8
49
 
9
50
 
10
51
  def _zoom_inputs_check(
@@ -73,7 +114,7 @@ def _dask_zoom(
73
114
  block_output_shape = tuple(np.ceil(better_source_chunks * _scale).astype(int))
74
115
 
75
116
  zoom_wrapper = partial(
76
- zoom, zoom=_scale, order=order, mode="grid-constant", grid_mode=True
117
+ fast_zoom, zoom=_scale, order=order, mode="grid-constant", grid_mode=True
77
118
  )
78
119
 
79
120
  out_array = da.map_blocks(
@@ -109,7 +150,7 @@ def _numpy_zoom(
109
150
  source_array=source_array, scale=scale, target_shape=target_shape
110
151
  )
111
152
 
112
- out_array = zoom(
153
+ out_array = fast_zoom(
113
154
  source_array, zoom=_scale, order=order, mode="grid-constant", grid_mode=True
114
155
  )
115
156
  assert isinstance(out_array, np.ndarray)
@@ -149,6 +190,7 @@ def on_disk_zoom(
149
190
  target_array = _dask_zoom(source_array, target_shape=target.shape, order=order)
150
191
 
151
192
  target_array = target_array.rechunk(target.chunks)
193
+ target_array.compute_chunk_sizes()
152
194
  target_array.to_zarr(target)
153
195
 
154
196
 
@@ -180,7 +222,7 @@ def on_disk_coarsen(
180
222
  coarsening_setup[i] = int(factor)
181
223
  else:
182
224
  raise ValueError(
183
- "Coarsening factor must be an integer, got " f"{factor} on axis {i}"
225
+ f"Coarsening factor must be an integer, got {factor} on axis {i}"
184
226
  )
185
227
 
186
228
  out_target = da.coarsen(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ngio
3
- Version: 0.1.5
3
+ Version: 0.1.6
4
4
  Summary: Next Generation file format IO
5
5
  Project-URL: homepage, https://github.com/lorenzocerrone/ngio
6
6
  Project-URL: repository, https://github.com/lorenzocerrone/ngio
@@ -13,6 +13,7 @@ Classifier: Programming Language :: Python :: 3
13
13
  Classifier: Programming Language :: Python :: 3.10
14
14
  Classifier: Programming Language :: Python :: 3.11
15
15
  Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
16
17
  Classifier: Typing :: Typed
17
18
  Requires-Python: >=3.10
18
19
  Requires-Dist: aiohttp
@@ -4,13 +4,13 @@ ngio/core/dimensions.py,sha256=AyiXXwgfwe1LiJ7cNhefUVTG2GQqVzDiO0ge_KePf8Q,3722
4
4
  ngio/core/image_handler.py,sha256=2eiklMWCSZD9ajZHEwYJHB1WoQE92YTVOy7qslrtSaw,7569
5
5
  ngio/core/image_like_handler.py,sha256=_k1xs3Uct_FXKoyUDTfQwG755SmiMGlztGhsQW-OtOA,18821
6
6
  ngio/core/label_handler.py,sha256=yBWMQbhme0j4XhXcoWuNY0x3Kt_MH3aYTu6peOfWyTc,14102
7
- ngio/core/ngff_image.py,sha256=3C4FE9Q-wtKwLn0Cdy7sCGIvFstgZbRWbUq-pUReOG4,13757
7
+ ngio/core/ngff_image.py,sha256=F3TOWzL2SuQmnkilWuKjYRcpnCS67LW4z7ayCj9pfYs,13751
8
8
  ngio/core/roi.py,sha256=Vn9aKNxRvJs77ZfVFMAdjOzhy2I2ctpikLcbFP5aj74,2884
9
- ngio/core/utils.py,sha256=Z3_nI7nLtMZT2gHFgEFtAox6fcENiFuQA5n6UuK2uDo,10170
9
+ ngio/core/utils.py,sha256=GsujsKwOJDeFhcj3DgkZO99wG_Dm0wO7nTNL-uiD78c,10161
10
10
  ngio/io/__init__.py,sha256=g7KmkgRcVBTZbVkqstl_FldUFzz66R-b__HV9hsLvtc,400
11
11
  ngio/io/_zarr.py,sha256=4AM8p7ENDPAqSuR99HaP0uosPqwY80h86GZch3l7C20,2605
12
12
  ngio/io/_zarr_array_utils.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
- ngio/io/_zarr_group_utils.py,sha256=-cqgxQBvSqPhy5m7iXADOCji3IiEmCgc7zOLeJW5fYw,1754
13
+ ngio/io/_zarr_group_utils.py,sha256=ZvVQ7Z0UvLNepNyU_NmKgjKKuVXACOLPi8-OkaI6H30,1738
14
14
  ngio/iterators/__init__.py,sha256=-jQ5h6oNftLKtiHDru8nPOrR3x8H1rMo85hzvqkhxmw,29
15
15
  ngio/ngff_meta/__init__.py,sha256=HhtHzjjk55gaHYbjiHoHRyYmOs1QZgBdWeCBb7O19Vo,560
16
16
  ngio/ngff_meta/fractal_image_meta.py,sha256=yc97iEGj5VjaCWv0Md94b5I2p9qzx94DMu_HlyKmrmg,43353
@@ -22,7 +22,7 @@ ngio/ngff_meta/v04/zarr_utils.py,sha256=02ISrsAGIXB1iLfcXPpqDljDlp0vC8Y_MyL5c016
22
22
  ngio/pipes/__init__.py,sha256=Ypt9bCqrk0qSg81GTBNqH5oljMg2rQPwyOWVZRKzaYg,299
23
23
  ngio/pipes/_slicer_transforms.py,sha256=UyN_aeAg-mtO9wsbqcvUIvnV5PJFTbj8AUmegMsF05k,5812
24
24
  ngio/pipes/_transforms.py,sha256=S7PqIwyf10i1cjQ-lKcJLr7YLfW2zKJKGf6DKKP3bTA,1067
25
- ngio/pipes/_zoom_utils.py,sha256=mDH2llMcoG01tnGRXXFu8UUVBu7KRsOEkNAE8wFQXeQ,6460
25
+ ngio/pipes/_zoom_utils.py,sha256=omkaJFNeqS09qdIsBmEQaSc_xKjP8hoHwOpsx_yd5B4,7957
26
26
  ngio/pipes/data_pipe.py,sha256=SBe-3kTgbHyvFC2lVYyVZj12JazmHCx9QaTDZW1PNxU,1907
27
27
  ngio/tables/__init__.py,sha256=kedgmeeFVxBAJACoZ1yxfoyTmlmI1HCBWFhgyprbNWI,260
28
28
  ngio/tables/_ad_reader.py,sha256=OQJ3ZwS0wMedlSjz-wQuovIDBojnHRk2Qhq6FL29248,2677
@@ -38,7 +38,7 @@ ngio/utils/_common_types.py,sha256=ylo6RfCyKVyXPx1Mz7WAwFfz8F85R9yd2_TPlRGRUyo,1
38
38
  ngio/utils/_errors.py,sha256=rLy9LOFkaEmsSD0-nToKUrXY1ZuPfcpcGpmeHVSnTNg,583
39
39
  ngio/utils/_logger.py,sha256=zvFG-Ta3ZIJxTyY93zYoPGp2A6TTUf7mSO0zr_uFy4A,837
40
40
  ngio/utils/_pydantic_utils.py,sha256=uN5-76cjE3bvV8GvLX62fpxoRi8GOsZu6K5aynGH1bY,1711
41
- ngio-0.1.5.dist-info/METADATA,sha256=foHqb5q_WPlk8-fJ2fnwBcirrAY_rbcT0NYPATqy7us,5705
42
- ngio-0.1.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
43
- ngio-0.1.5.dist-info/licenses/LICENSE,sha256=UgN_a1QCeNh9rZWfz-wORQFxE3elQzLWPQaoK6N6fxQ,1502
44
- ngio-0.1.5.dist-info/RECORD,,
41
+ ngio-0.1.6.dist-info/METADATA,sha256=w4iV12bvnoiCfP6AAWMpqH0ORoh0kZxA8WeqQjKzhBI,5756
42
+ ngio-0.1.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
43
+ ngio-0.1.6.dist-info/licenses/LICENSE,sha256=UgN_a1QCeNh9rZWfz-wORQFxE3elQzLWPQaoK6N6fxQ,1502
44
+ ngio-0.1.6.dist-info/RECORD,,
File without changes