ngio 0.4.8__py3-none-any.whl → 0.5.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/common/_pyramid.py +41 -28
- ngio/images/_create.py +23 -16
- ngio/images/_create_synt_container.py +9 -8
- ngio/images/_image.py +26 -16
- ngio/images/_label.py +15 -15
- ngio/images/_ome_zarr_container.py +29 -29
- ngio/ome_zarr_meta/_meta_handlers.py +29 -0
- ngio/ome_zarr_meta/ngio_specs/_ngio_image.py +12 -1
- ngio/ome_zarr_meta/v04/_v04_spec_utils.py +2 -2
- ngio/ome_zarr_meta/v05/__init__.py +23 -0
- ngio/ome_zarr_meta/v05/_custom_models.py +18 -0
- ngio/ome_zarr_meta/v05/_v05_spec_utils.py +518 -0
- ngio/tables/_tables_container.py +3 -3
- ngio/tables/backends/_abstract_backend.py +7 -0
- ngio/tables/backends/_anndata.py +4 -1
- ngio/tables/backends/_anndata_utils.py +4 -1
- ngio/tables/backends/_non_zarr_backends.py +6 -6
- ngio/tables/backends/_utils.py +1 -1
- ngio/tables/v1/_roi_table.py +3 -3
- ngio/utils/_datasets.py +0 -6
- ngio/utils/_zarr_utils.py +108 -32
- {ngio-0.4.8.dist-info → ngio-0.5.0a1.dist-info}/METADATA +6 -6
- {ngio-0.4.8.dist-info → ngio-0.5.0a1.dist-info}/RECORD +25 -22
- {ngio-0.4.8.dist-info → ngio-0.5.0a1.dist-info}/WHEEL +1 -1
- {ngio-0.4.8.dist-info → ngio-0.5.0a1.dist-info}/licenses/LICENSE +0 -0
ngio/common/_pyramid.py
CHANGED
|
@@ -2,12 +2,12 @@ import math
|
|
|
2
2
|
from collections.abc import Callable, Sequence
|
|
3
3
|
from typing import Literal
|
|
4
4
|
|
|
5
|
-
import dask
|
|
6
5
|
import dask.array as da
|
|
7
6
|
import numpy as np
|
|
8
7
|
import zarr
|
|
9
|
-
from zarr.
|
|
8
|
+
from zarr.core.array import CompressorLike
|
|
10
9
|
|
|
10
|
+
# from zarr.types import DIMENSION_SEPARATOR
|
|
11
11
|
from ngio.common._zoom import (
|
|
12
12
|
InterpolationOrder,
|
|
13
13
|
_zoom_inputs_check,
|
|
@@ -27,7 +27,10 @@ def _on_disk_numpy_zoom(
|
|
|
27
27
|
target: zarr.Array,
|
|
28
28
|
order: InterpolationOrder,
|
|
29
29
|
) -> None:
|
|
30
|
-
|
|
30
|
+
source_array = source[...]
|
|
31
|
+
if not isinstance(source_array, np.ndarray):
|
|
32
|
+
raise NgioValueError("source zarr array could not be read as a numpy array")
|
|
33
|
+
target[...] = numpy_zoom(source_array, target_shape=target.shape, order=order)
|
|
31
34
|
|
|
32
35
|
|
|
33
36
|
def _on_disk_dask_zoom(
|
|
@@ -37,17 +40,9 @@ def _on_disk_dask_zoom(
|
|
|
37
40
|
) -> None:
|
|
38
41
|
source_array = da.from_zarr(source)
|
|
39
42
|
target_array = dask_zoom(source_array, target_shape=target.shape, order=order)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
#
|
|
44
|
-
#if current_chunk_size < chunk_size_bytes:
|
|
45
|
-
# # Increase the chunk size to avoid dask potentially creating
|
|
46
|
-
# # corrupted chunks when writing chunks that are not multiple of the
|
|
47
|
-
# # target chunk size
|
|
48
|
-
# dask.config.set({"array.chunk-size": f"{chunk_size_bytes}B"})
|
|
49
|
-
target_array = target_array.rechunk(target.chunks)
|
|
50
|
-
target_array = target_array.compute_chunk_sizes()
|
|
43
|
+
|
|
44
|
+
target_array = target_array.rechunk(target.chunks) # type: ignore
|
|
45
|
+
target_array.compute_chunk_sizes()
|
|
51
46
|
target_array.to_zarr(target)
|
|
52
47
|
|
|
53
48
|
|
|
@@ -208,20 +203,24 @@ def init_empty_pyramid(
|
|
|
208
203
|
paths: list[str],
|
|
209
204
|
ref_shape: Sequence[int],
|
|
210
205
|
scaling_factors: Sequence[float],
|
|
211
|
-
|
|
206
|
+
axes: Sequence[str],
|
|
207
|
+
chunks: Sequence[int] | Literal["auto"] = "auto",
|
|
212
208
|
dtype: str = "uint16",
|
|
213
209
|
mode: AccessModeLiteral = "a",
|
|
214
|
-
dimension_separator:
|
|
215
|
-
|
|
210
|
+
dimension_separator: Literal[".", "/"] = "/",
|
|
211
|
+
compressors: CompressorLike = "auto",
|
|
212
|
+
zarr_format: Literal[2, 3] = 2,
|
|
216
213
|
) -> None:
|
|
217
214
|
# Return the an Image object
|
|
218
|
-
if chunks
|
|
215
|
+
if chunks != "auto" and len(chunks) != len(ref_shape):
|
|
219
216
|
raise NgioValueError(
|
|
220
217
|
"The shape and chunks must have the same number of dimensions."
|
|
221
218
|
)
|
|
222
219
|
|
|
223
|
-
if chunks
|
|
224
|
-
chunks =
|
|
220
|
+
if chunks != "auto":
|
|
221
|
+
chunks = tuple(min(c, s) for c, s in zip(chunks, ref_shape, strict=True))
|
|
222
|
+
else:
|
|
223
|
+
chunks = "auto"
|
|
225
224
|
|
|
226
225
|
if len(ref_shape) != len(scaling_factors):
|
|
227
226
|
raise NgioValueError(
|
|
@@ -232,7 +231,25 @@ def init_empty_pyramid(
|
|
|
232
231
|
# To reduce the risk of floating point issues
|
|
233
232
|
scaling_factors = [_maybe_int(s) for s in scaling_factors]
|
|
234
233
|
|
|
235
|
-
root_group = open_group_wrapper(store, mode=mode)
|
|
234
|
+
root_group = open_group_wrapper(store, mode=mode, zarr_format=zarr_format)
|
|
235
|
+
|
|
236
|
+
array_static_kwargs = {
|
|
237
|
+
"dtype": dtype,
|
|
238
|
+
"overwrite": True,
|
|
239
|
+
"compressors": compressors,
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if zarr_format == 2:
|
|
243
|
+
array_static_kwargs["chunk_key_encoding"] = {
|
|
244
|
+
"name": "v2",
|
|
245
|
+
"separator": dimension_separator,
|
|
246
|
+
}
|
|
247
|
+
else:
|
|
248
|
+
array_static_kwargs["chunk_key_encoding"] = {
|
|
249
|
+
"name": "default",
|
|
250
|
+
"separator": dimension_separator,
|
|
251
|
+
}
|
|
252
|
+
array_static_kwargs["dimension_names"] = axes
|
|
236
253
|
|
|
237
254
|
for path in paths:
|
|
238
255
|
if any(s < 1 for s in ref_shape):
|
|
@@ -240,14 +257,11 @@ def init_empty_pyramid(
|
|
|
240
257
|
"Level shape must be at least 1 on all dimensions. "
|
|
241
258
|
f"Calculated shape: {ref_shape} at level {path}."
|
|
242
259
|
)
|
|
243
|
-
new_arr = root_group.
|
|
260
|
+
new_arr = root_group.create_array(
|
|
244
261
|
name=path,
|
|
245
|
-
shape=ref_shape,
|
|
246
|
-
dtype=dtype,
|
|
262
|
+
shape=tuple(ref_shape),
|
|
247
263
|
chunks=chunks,
|
|
248
|
-
|
|
249
|
-
overwrite=True,
|
|
250
|
-
compressor=compressor,
|
|
264
|
+
**array_static_kwargs,
|
|
251
265
|
)
|
|
252
266
|
|
|
253
267
|
ref_shape = [
|
|
@@ -256,5 +270,4 @@ def init_empty_pyramid(
|
|
|
256
270
|
chunks = tuple(
|
|
257
271
|
min(c, s) for c, s in zip(new_arr.chunks, ref_shape, strict=True)
|
|
258
272
|
)
|
|
259
|
-
|
|
260
273
|
return None
|
ngio/images/_create.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"""Utility functions for working with OME-Zarr images."""
|
|
2
2
|
|
|
3
3
|
from collections.abc import Sequence
|
|
4
|
-
from typing import TypeVar
|
|
4
|
+
from typing import Literal, TypeVar
|
|
5
5
|
|
|
6
|
-
from zarr.
|
|
6
|
+
from zarr.core.array import CompressorLike
|
|
7
7
|
|
|
8
8
|
from ngio.common._pyramid import init_empty_pyramid
|
|
9
9
|
from ngio.ome_zarr_meta import (
|
|
@@ -93,10 +93,10 @@ def create_empty_label_container(
|
|
|
93
93
|
time_unit: TimeUnits | str | None = DefaultTimeUnit,
|
|
94
94
|
axes_names: Sequence[str] | None = None,
|
|
95
95
|
name: str | None = None,
|
|
96
|
-
chunks: Sequence[int] |
|
|
96
|
+
chunks: Sequence[int] | Literal["auto"] = "auto",
|
|
97
97
|
dtype: str = "uint32",
|
|
98
|
-
dimension_separator:
|
|
99
|
-
|
|
98
|
+
dimension_separator: Literal[".", "/"] = "/",
|
|
99
|
+
compressors: CompressorLike = "auto",
|
|
100
100
|
overwrite: bool = False,
|
|
101
101
|
version: NgffVersions = DefaultNgffVersion,
|
|
102
102
|
) -> ZarrGroupHandler:
|
|
@@ -122,11 +122,11 @@ def create_empty_label_container(
|
|
|
122
122
|
axes_names (Sequence[str] | None, optional): The names of the axes.
|
|
123
123
|
If None the canonical names are used. Defaults to None.
|
|
124
124
|
name (str | None, optional): The name of the image. Defaults to None.
|
|
125
|
-
chunks (Sequence[int] |
|
|
125
|
+
chunks (Sequence[int] | Literal["auto"]): The chunk shape. If None the shape
|
|
126
126
|
is used. Defaults to None.
|
|
127
127
|
dimension_separator (DIMENSION_SEPARATOR): The separator to use for
|
|
128
128
|
dimensions. Defaults to "/".
|
|
129
|
-
|
|
129
|
+
compressors (CompressorLike): The compressors to use. Defaults to "auto".
|
|
130
130
|
dtype (str, optional): The data type of the image. Defaults to "uint16".
|
|
131
131
|
overwrite (bool, optional): Whether to overwrite an existing image.
|
|
132
132
|
Defaults to True.
|
|
@@ -159,7 +159,9 @@ def create_empty_label_container(
|
|
|
159
159
|
)
|
|
160
160
|
|
|
161
161
|
mode = "w" if overwrite else "w-"
|
|
162
|
-
group_handler = ZarrGroupHandler(
|
|
162
|
+
group_handler = ZarrGroupHandler(
|
|
163
|
+
store=store, mode=mode, cache=False, zarr_format=meta.zarr_format
|
|
164
|
+
)
|
|
163
165
|
image_handler = get_label_meta_handler(version=version, group_handler=group_handler)
|
|
164
166
|
image_handler.write_meta(meta)
|
|
165
167
|
|
|
@@ -169,10 +171,11 @@ def create_empty_label_container(
|
|
|
169
171
|
scaling_factors=scaling_factors,
|
|
170
172
|
ref_shape=shape,
|
|
171
173
|
chunks=chunks,
|
|
174
|
+
axes=axes_names,
|
|
172
175
|
dtype=dtype,
|
|
173
176
|
mode="a",
|
|
174
177
|
dimension_separator=dimension_separator,
|
|
175
|
-
|
|
178
|
+
compressors=compressors,
|
|
176
179
|
)
|
|
177
180
|
group_handler._mode = "r+"
|
|
178
181
|
return group_handler
|
|
@@ -191,10 +194,10 @@ def create_empty_image_container(
|
|
|
191
194
|
time_unit: TimeUnits | str | None = DefaultTimeUnit,
|
|
192
195
|
axes_names: Sequence[str] | None = None,
|
|
193
196
|
name: str | None = None,
|
|
194
|
-
chunks: Sequence[int] |
|
|
197
|
+
chunks: Sequence[int] | Literal["auto"] = "auto",
|
|
195
198
|
dtype: str = "uint16",
|
|
196
|
-
dimension_separator:
|
|
197
|
-
|
|
199
|
+
dimension_separator: Literal[".", "/"] = "/",
|
|
200
|
+
compressors: CompressorLike = "auto",
|
|
198
201
|
overwrite: bool = False,
|
|
199
202
|
version: NgffVersions = DefaultNgffVersion,
|
|
200
203
|
) -> ZarrGroupHandler:
|
|
@@ -220,12 +223,12 @@ def create_empty_image_container(
|
|
|
220
223
|
axes_names (Sequence[str] | None, optional): The names of the axes.
|
|
221
224
|
If None the canonical names are used. Defaults to None.
|
|
222
225
|
name (str | None, optional): The name of the image. Defaults to None.
|
|
223
|
-
chunks (Sequence[int] |
|
|
226
|
+
chunks (Sequence[int] | Literal["auto"]): The chunk shape. If None the shape
|
|
224
227
|
is used. Defaults to None.
|
|
225
228
|
dtype (str, optional): The data type of the image. Defaults to "uint16".
|
|
226
229
|
dimension_separator (DIMENSION_SEPARATOR): The separator to use for
|
|
227
230
|
dimensions. Defaults to "/".
|
|
228
|
-
|
|
231
|
+
compressors (CompressorLike): The compressors to use. Defaults to "auto".
|
|
229
232
|
overwrite (bool, optional): Whether to overwrite an existing image.
|
|
230
233
|
Defaults to True.
|
|
231
234
|
version (str, optional): The version of the OME-Zarr specification.
|
|
@@ -256,7 +259,9 @@ def create_empty_image_container(
|
|
|
256
259
|
version=version,
|
|
257
260
|
)
|
|
258
261
|
mode = "w" if overwrite else "w-"
|
|
259
|
-
group_handler = ZarrGroupHandler(
|
|
262
|
+
group_handler = ZarrGroupHandler(
|
|
263
|
+
store=store, mode=mode, cache=False, zarr_format=meta.zarr_format
|
|
264
|
+
)
|
|
260
265
|
image_handler = get_image_meta_handler(version=version, group_handler=group_handler)
|
|
261
266
|
image_handler.write_meta(meta)
|
|
262
267
|
|
|
@@ -266,10 +271,12 @@ def create_empty_image_container(
|
|
|
266
271
|
scaling_factors=scaling_factors,
|
|
267
272
|
ref_shape=shape,
|
|
268
273
|
chunks=chunks,
|
|
274
|
+
axes=axes_names,
|
|
269
275
|
dtype=dtype,
|
|
270
276
|
mode="a",
|
|
271
277
|
dimension_separator=dimension_separator,
|
|
272
|
-
|
|
278
|
+
compressors=compressors,
|
|
279
|
+
zarr_format=meta.zarr_format,
|
|
273
280
|
)
|
|
274
281
|
|
|
275
282
|
group_handler._mode = "r+"
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"""Abstract class for handling OME-NGFF images."""
|
|
2
2
|
|
|
3
3
|
from collections.abc import Sequence
|
|
4
|
+
from typing import Literal
|
|
4
5
|
|
|
5
6
|
import numpy as np
|
|
6
7
|
import PIL.Image
|
|
7
|
-
from zarr.
|
|
8
|
+
from zarr.core.array import CompressorLike
|
|
8
9
|
|
|
9
10
|
from ngio.common._synt_images_utils import fit_to_shape
|
|
10
11
|
from ngio.images._ome_zarr_container import OmeZarrContainer, create_ome_zarr_from_array
|
|
@@ -30,14 +31,14 @@ def create_synthetic_ome_zarr(
|
|
|
30
31
|
xy_scaling_factor: float = 2,
|
|
31
32
|
z_scaling_factor: float = 1.0,
|
|
32
33
|
axes_names: Sequence[str] | None = None,
|
|
33
|
-
chunks: Sequence[int] |
|
|
34
|
+
chunks: Sequence[int] | Literal["auto"] = "auto",
|
|
34
35
|
channel_labels: list[str] | None = None,
|
|
35
36
|
channel_wavelengths: list[str] | None = None,
|
|
36
37
|
channel_colors: Sequence[str] | None = None,
|
|
37
38
|
channel_active: Sequence[bool] | None = None,
|
|
38
39
|
table_backend: TableBackend = DefaultTableBackend,
|
|
39
|
-
dimension_separator:
|
|
40
|
-
|
|
40
|
+
dimension_separator: Literal[".", "/"] = "/",
|
|
41
|
+
compressors: CompressorLike = "auto",
|
|
41
42
|
overwrite: bool = False,
|
|
42
43
|
version: NgffVersions = DefaultNgffVersion,
|
|
43
44
|
) -> OmeZarrContainer:
|
|
@@ -55,8 +56,8 @@ def create_synthetic_ome_zarr(
|
|
|
55
56
|
Defaults to 1.0.
|
|
56
57
|
axes_names (Sequence[str] | None, optional): The names of the axes.
|
|
57
58
|
If None the canonical names are used. Defaults to None.
|
|
58
|
-
chunks (Sequence[int] |
|
|
59
|
-
is used. Defaults to
|
|
59
|
+
chunks (Sequence[int] | Literal["auto"]): The chunk shape. If None the shape
|
|
60
|
+
is used. Defaults to "auto".
|
|
60
61
|
channel_labels (list[str] | None, optional): The labels of the channels.
|
|
61
62
|
Defaults to None.
|
|
62
63
|
channel_wavelengths (list[str] | None, optional): The wavelengths of the
|
|
@@ -68,7 +69,7 @@ def create_synthetic_ome_zarr(
|
|
|
68
69
|
table_backend (TableBackend): Table backend to be used to store tables
|
|
69
70
|
dimension_separator (DIMENSION_SEPARATOR): The separator to use for
|
|
70
71
|
dimensions. Defaults to "/".
|
|
71
|
-
|
|
72
|
+
compressors (CompressorLike): The compressors to use. Defaults to "auto".
|
|
72
73
|
overwrite (bool, optional): Whether to overwrite an existing image.
|
|
73
74
|
Defaults to True.
|
|
74
75
|
version (NgffVersion, optional): The version of the OME-Zarr specification.
|
|
@@ -103,7 +104,7 @@ def create_synthetic_ome_zarr(
|
|
|
103
104
|
chunks=chunks,
|
|
104
105
|
overwrite=overwrite,
|
|
105
106
|
dimension_separator=dimension_separator,
|
|
106
|
-
|
|
107
|
+
compressors=compressors,
|
|
107
108
|
version=version,
|
|
108
109
|
)
|
|
109
110
|
|
ngio/images/_image.py
CHANGED
|
@@ -6,7 +6,7 @@ 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.
|
|
9
|
+
from zarr.core.array import CompressorLike
|
|
10
10
|
|
|
11
11
|
from ngio.common import (
|
|
12
12
|
Dimensions,
|
|
@@ -32,6 +32,7 @@ from ngio.ome_zarr_meta.ngio_specs import (
|
|
|
32
32
|
ChannelVisualisation,
|
|
33
33
|
DefaultSpaceUnit,
|
|
34
34
|
DefaultTimeUnit,
|
|
35
|
+
NgffVersions,
|
|
35
36
|
SpaceUnits,
|
|
36
37
|
TimeUnits,
|
|
37
38
|
)
|
|
@@ -40,6 +41,7 @@ from ngio.utils import (
|
|
|
40
41
|
StoreOrGroup,
|
|
41
42
|
ZarrGroupHandler,
|
|
42
43
|
)
|
|
44
|
+
from ngio.utils._zarr_utils import find_dimension_separator
|
|
43
45
|
|
|
44
46
|
|
|
45
47
|
class ChannelSelectionModel(BaseModel):
|
|
@@ -604,8 +606,9 @@ class ImagesContainer:
|
|
|
604
606
|
name: str | None = None,
|
|
605
607
|
chunks: Sequence[int] | None = None,
|
|
606
608
|
dtype: str | None = None,
|
|
607
|
-
dimension_separator:
|
|
608
|
-
|
|
609
|
+
dimension_separator: Literal[".", "/"] | None = None,
|
|
610
|
+
compressors: CompressorLike | None = None,
|
|
611
|
+
ngff_version: NgffVersions | None = None,
|
|
609
612
|
overwrite: bool = False,
|
|
610
613
|
) -> "ImagesContainer":
|
|
611
614
|
"""Create an empty OME-Zarr image from an existing image.
|
|
@@ -619,12 +622,13 @@ class ImagesContainer:
|
|
|
619
622
|
pixel_size (PixelSize | None): The pixel size of the new image.
|
|
620
623
|
axes_names (Sequence[str] | None): The axes names of the new image.
|
|
621
624
|
name (str | None): The name of the new image.
|
|
622
|
-
chunks (Sequence[int] |
|
|
625
|
+
chunks (Sequence[int] | Literal["auto"]): The chunk shape of the new image.
|
|
623
626
|
dimension_separator (DIMENSION_SEPARATOR | None): The separator to use for
|
|
624
627
|
dimensions. If None it will use the same as the reference image.
|
|
625
|
-
|
|
628
|
+
compressors: The compressor to use. If None it will use
|
|
626
629
|
the same as the reference image.
|
|
627
630
|
dtype (str | None): The data type of the new image.
|
|
631
|
+
ngff_version (NgffVersions): The NGFF version to use.
|
|
628
632
|
overwrite (bool): Whether to overwrite an existing image.
|
|
629
633
|
|
|
630
634
|
Returns:
|
|
@@ -642,7 +646,8 @@ class ImagesContainer:
|
|
|
642
646
|
chunks=chunks,
|
|
643
647
|
dtype=dtype,
|
|
644
648
|
dimension_separator=dimension_separator,
|
|
645
|
-
|
|
649
|
+
compressors=compressors,
|
|
650
|
+
ngff_version=ngff_version,
|
|
646
651
|
overwrite=overwrite,
|
|
647
652
|
)
|
|
648
653
|
|
|
@@ -725,8 +730,9 @@ def derive_image_container(
|
|
|
725
730
|
name: str | None = None,
|
|
726
731
|
chunks: Sequence[int] | None = None,
|
|
727
732
|
dtype: str | None = None,
|
|
728
|
-
dimension_separator:
|
|
729
|
-
|
|
733
|
+
dimension_separator: Literal[".", "/"] | None = None,
|
|
734
|
+
compressors: CompressorLike | None = None,
|
|
735
|
+
ngff_version: NgffVersions | None = None,
|
|
730
736
|
overwrite: bool = False,
|
|
731
737
|
) -> ImagesContainer:
|
|
732
738
|
"""Create an empty OME-Zarr image from an existing image.
|
|
@@ -743,8 +749,9 @@ def derive_image_container(
|
|
|
743
749
|
chunks (Sequence[int] | None): The chunk shape of the new image.
|
|
744
750
|
dimension_separator (DIMENSION_SEPARATOR | None): The separator to use for
|
|
745
751
|
dimensions. If None it will use the same as the reference image.
|
|
746
|
-
|
|
752
|
+
compressors (CompressorLike | None): The compressors to use. If None it will use
|
|
747
753
|
the same as the reference image.
|
|
754
|
+
ngff_version (NgffVersions): The NGFF version to use.
|
|
748
755
|
dtype (str | None): The data type of the new image.
|
|
749
756
|
overwrite (bool): Whether to overwrite an existing image.
|
|
750
757
|
|
|
@@ -790,10 +797,13 @@ def derive_image_container(
|
|
|
790
797
|
dtype = ref_image.dtype
|
|
791
798
|
|
|
792
799
|
if dimension_separator is None:
|
|
793
|
-
dimension_separator = ref_image.zarr_array
|
|
800
|
+
dimension_separator = find_dimension_separator(ref_image.zarr_array)
|
|
794
801
|
|
|
795
|
-
if
|
|
796
|
-
|
|
802
|
+
if compressors is None:
|
|
803
|
+
compressors = ref_image.zarr_array.compressors # type: ignore
|
|
804
|
+
|
|
805
|
+
if ngff_version is None:
|
|
806
|
+
ngff_version = ref_meta.version
|
|
797
807
|
|
|
798
808
|
handler = create_empty_image_container(
|
|
799
809
|
store=store,
|
|
@@ -810,10 +820,10 @@ def derive_image_container(
|
|
|
810
820
|
name=name,
|
|
811
821
|
chunks=chunks,
|
|
812
822
|
dtype=dtype,
|
|
813
|
-
dimension_separator=dimension_separator,
|
|
814
|
-
|
|
823
|
+
dimension_separator=dimension_separator,
|
|
824
|
+
compressors=compressors,
|
|
815
825
|
overwrite=overwrite,
|
|
816
|
-
version=
|
|
826
|
+
version=ngff_version,
|
|
817
827
|
)
|
|
818
828
|
image_container = ImagesContainer(handler)
|
|
819
829
|
|
|
@@ -875,7 +885,7 @@ def _parse_str_or_model(
|
|
|
875
885
|
)
|
|
876
886
|
elif channel_selection.mode == "wavelength_id":
|
|
877
887
|
return image.get_channel_idx(
|
|
878
|
-
|
|
888
|
+
channel_label=str(channel_selection.identifier)
|
|
879
889
|
)
|
|
880
890
|
elif channel_selection.mode == "index":
|
|
881
891
|
return int(channel_selection.identifier)
|
ngio/images/_label.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
from collections.abc import Sequence
|
|
4
4
|
from typing import Literal
|
|
5
5
|
|
|
6
|
-
from zarr.
|
|
6
|
+
from zarr.core.array import CompressorLike
|
|
7
7
|
|
|
8
8
|
from ngio.common import compute_masking_roi
|
|
9
9
|
from ngio.images._abstract_image import AbstractImage
|
|
@@ -28,6 +28,7 @@ from ngio.utils import (
|
|
|
28
28
|
StoreOrGroup,
|
|
29
29
|
ZarrGroupHandler,
|
|
30
30
|
)
|
|
31
|
+
from ngio.utils._zarr_utils import find_dimension_separator
|
|
31
32
|
|
|
32
33
|
|
|
33
34
|
class Label(AbstractImage[LabelMetaHandler]):
|
|
@@ -107,7 +108,6 @@ class LabelsContainer:
|
|
|
107
108
|
def __init__(self, group_handler: ZarrGroupHandler) -> None:
|
|
108
109
|
"""Initialize the LabelGroupHandler."""
|
|
109
110
|
self._group_handler = group_handler
|
|
110
|
-
|
|
111
111
|
# Validate the group
|
|
112
112
|
# Either contains a labels attribute or is empty
|
|
113
113
|
attrs = self._group_handler.load_attrs()
|
|
@@ -169,8 +169,8 @@ class LabelsContainer:
|
|
|
169
169
|
axes_names: Sequence[str] | None = None,
|
|
170
170
|
chunks: Sequence[int] | None = None,
|
|
171
171
|
dtype: str = "uint32",
|
|
172
|
-
dimension_separator:
|
|
173
|
-
|
|
172
|
+
dimension_separator: Literal[".", "/"] | None = None,
|
|
173
|
+
compressors: CompressorLike | None = None,
|
|
174
174
|
overwrite: bool = False,
|
|
175
175
|
) -> "Label":
|
|
176
176
|
"""Create an empty OME-Zarr label from a reference image.
|
|
@@ -190,8 +190,8 @@ class LabelsContainer:
|
|
|
190
190
|
dtype (str): The data type of the new label.
|
|
191
191
|
dimension_separator (DIMENSION_SEPARATOR | None): The separator to use for
|
|
192
192
|
dimensions. If None it will use the same as the reference image.
|
|
193
|
-
|
|
194
|
-
the same as the reference image.
|
|
193
|
+
compressors (CompressorLike | None): The compressors to use. If None it will
|
|
194
|
+
use the same as the reference image.
|
|
195
195
|
overwrite (bool): Whether to overwrite an existing image.
|
|
196
196
|
|
|
197
197
|
Returns:
|
|
@@ -217,7 +217,7 @@ class LabelsContainer:
|
|
|
217
217
|
chunks=chunks,
|
|
218
218
|
dtype=dtype,
|
|
219
219
|
dimension_separator=dimension_separator,
|
|
220
|
-
|
|
220
|
+
compressors=compressors,
|
|
221
221
|
overwrite=overwrite,
|
|
222
222
|
)
|
|
223
223
|
|
|
@@ -236,8 +236,8 @@ def derive_label(
|
|
|
236
236
|
pixel_size: PixelSize | None = None,
|
|
237
237
|
axes_names: Sequence[str] | None = None,
|
|
238
238
|
chunks: Sequence[int] | None = None,
|
|
239
|
-
dimension_separator:
|
|
240
|
-
|
|
239
|
+
dimension_separator: Literal[".", "/"] | None = None,
|
|
240
|
+
compressors: CompressorLike | None = None,
|
|
241
241
|
dtype: str = "uint32",
|
|
242
242
|
overwrite: bool = False,
|
|
243
243
|
) -> None:
|
|
@@ -256,7 +256,7 @@ def derive_label(
|
|
|
256
256
|
dtype (str): The data type of the new label.
|
|
257
257
|
dimension_separator (DIMENSION_SEPARATOR | None): The separator to use for
|
|
258
258
|
dimensions. If None it will use the same as the reference image.
|
|
259
|
-
|
|
259
|
+
compressors (CompressorLike | None): The compressor to use. If None it will use
|
|
260
260
|
the same as the reference image.
|
|
261
261
|
overwrite (bool): Whether to overwrite an existing image.
|
|
262
262
|
|
|
@@ -308,9 +308,9 @@ def derive_label(
|
|
|
308
308
|
axes_names = axes_names[:c_axis] + axes_names[c_axis + 1 :]
|
|
309
309
|
|
|
310
310
|
if dimension_separator is None:
|
|
311
|
-
dimension_separator = ref_image.zarr_array
|
|
312
|
-
if
|
|
313
|
-
|
|
311
|
+
dimension_separator = find_dimension_separator(ref_image.zarr_array)
|
|
312
|
+
if compressors is None:
|
|
313
|
+
compressors = ref_image.zarr_array.compressors # type: ignore
|
|
314
314
|
|
|
315
315
|
_ = create_empty_label_container(
|
|
316
316
|
store=store,
|
|
@@ -326,8 +326,8 @@ def derive_label(
|
|
|
326
326
|
axes_names=axes_names,
|
|
327
327
|
chunks=chunks,
|
|
328
328
|
dtype=dtype,
|
|
329
|
-
dimension_separator=dimension_separator,
|
|
330
|
-
|
|
329
|
+
dimension_separator=dimension_separator,
|
|
330
|
+
compressors=compressors,
|
|
331
331
|
overwrite=overwrite,
|
|
332
332
|
version=ref_meta.version,
|
|
333
333
|
name=name,
|