ngio 0.2.0a1__py3-none-any.whl → 0.2.0a2__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 +1 -0
- ngio/images/image.py +8 -2
- ngio/images/label.py +145 -5
- ngio/images/omezarr_container.py +27 -4
- ngio/utils/_datasets.py +1 -1
- {ngio-0.2.0a1.dist-info → ngio-0.2.0a2.dist-info}/METADATA +1 -1
- {ngio-0.2.0a1.dist-info → ngio-0.2.0a2.dist-info}/RECORD +9 -9
- {ngio-0.2.0a1.dist-info → ngio-0.2.0a2.dist-info}/WHEEL +0 -0
- {ngio-0.2.0a1.dist-info → ngio-0.2.0a2.dist-info}/licenses/LICENSE +0 -0
ngio/common/_pyramid.py
CHANGED
ngio/images/image.py
CHANGED
|
@@ -236,6 +236,8 @@ class ImagesContainer:
|
|
|
236
236
|
ref_path: str | None = None,
|
|
237
237
|
shape: Collection[int] | None = None,
|
|
238
238
|
chunks: Collection[int] | None = None,
|
|
239
|
+
xy_scaling_factor: float = 2.0,
|
|
240
|
+
z_scaling_factor: float = 1.0,
|
|
239
241
|
overwrite: bool = False,
|
|
240
242
|
) -> "ImagesContainer":
|
|
241
243
|
"""Create an OME-Zarr image from a numpy array."""
|
|
@@ -245,6 +247,8 @@ class ImagesContainer:
|
|
|
245
247
|
ref_path=ref_path,
|
|
246
248
|
shape=shape,
|
|
247
249
|
chunks=chunks,
|
|
250
|
+
xy_scaling_factor=xy_scaling_factor,
|
|
251
|
+
z_scaling_factor=z_scaling_factor,
|
|
248
252
|
overwrite=overwrite,
|
|
249
253
|
)
|
|
250
254
|
|
|
@@ -314,6 +318,8 @@ def derive_image_container(
|
|
|
314
318
|
ref_path: str | None = None,
|
|
315
319
|
shape: Collection[int] | None = None,
|
|
316
320
|
chunks: Collection[int] | None = None,
|
|
321
|
+
xy_scaling_factor: float = 2.0,
|
|
322
|
+
z_scaling_factor: float = 1.0,
|
|
317
323
|
overwrite: bool = False,
|
|
318
324
|
) -> ImagesContainer:
|
|
319
325
|
"""Create an OME-Zarr image from a numpy array."""
|
|
@@ -347,8 +353,8 @@ def derive_image_container(
|
|
|
347
353
|
z_spacing=ref_image.pixel_size.z,
|
|
348
354
|
time_spacing=ref_image.pixel_size.t,
|
|
349
355
|
levels=ref_meta.levels,
|
|
350
|
-
xy_scaling_factor=
|
|
351
|
-
z_scaling_factor=
|
|
356
|
+
xy_scaling_factor=xy_scaling_factor,
|
|
357
|
+
z_scaling_factor=z_scaling_factor,
|
|
352
358
|
time_unit=ref_image.pixel_size.time_unit,
|
|
353
359
|
space_unit=ref_image.pixel_size.space_unit,
|
|
354
360
|
axes_names=ref_image.dataset.axes_mapper.on_disk_axes_names,
|
ngio/images/label.py
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
"""A module for handling label images in OME-NGFF files."""
|
|
2
2
|
|
|
3
|
+
from collections.abc import Collection
|
|
3
4
|
from typing import Literal
|
|
4
5
|
|
|
5
6
|
from ngio.images.abstract_image import AbstractImage, consolidate_image
|
|
7
|
+
from ngio.images.create import _create_empty_label
|
|
8
|
+
from ngio.images.image import Image
|
|
6
9
|
from ngio.ome_zarr_meta import (
|
|
7
10
|
ImplementedLabelMetaHandlers,
|
|
8
11
|
LabelMetaHandler,
|
|
9
12
|
NgioLabelMeta,
|
|
10
13
|
)
|
|
14
|
+
from ngio.ome_zarr_meta.ngio_specs import SpaceUnits, TimeUnits
|
|
11
15
|
from ngio.utils import (
|
|
12
16
|
NgioValidationError,
|
|
17
|
+
NgioValueError,
|
|
18
|
+
StoreOrGroup,
|
|
13
19
|
ZarrGroupHandler,
|
|
14
20
|
)
|
|
15
21
|
|
|
@@ -88,9 +94,143 @@ class LabelsContainer:
|
|
|
88
94
|
def derive(
|
|
89
95
|
self,
|
|
90
96
|
name: str,
|
|
91
|
-
|
|
97
|
+
ref_image: Image,
|
|
98
|
+
shape: Collection[int] | None = None,
|
|
99
|
+
chunks: Collection[int] | None = None,
|
|
100
|
+
dtype: str = "uint16",
|
|
101
|
+
xy_scaling_factor=2.0,
|
|
102
|
+
z_scaling_factor=1.0,
|
|
92
103
|
overwrite: bool = False,
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
104
|
+
) -> None:
|
|
105
|
+
"""Add a label to the group."""
|
|
106
|
+
existing_labels = self.list()
|
|
107
|
+
if name in existing_labels and not overwrite:
|
|
108
|
+
raise NgioValueError(
|
|
109
|
+
f"Table '{name}' already exists in the group. "
|
|
110
|
+
"Use overwrite=True to replace it."
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
label_group = self._group_handler.get_group(name, create_mode=True)
|
|
114
|
+
|
|
115
|
+
_derive_label(
|
|
116
|
+
ref_image=ref_image,
|
|
117
|
+
store=label_group,
|
|
118
|
+
shape=shape,
|
|
119
|
+
chunks=chunks,
|
|
120
|
+
dtype=dtype,
|
|
121
|
+
xy_scaling_factor=xy_scaling_factor,
|
|
122
|
+
z_scaling_factor=z_scaling_factor,
|
|
123
|
+
overwrite=overwrite,
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
if name not in existing_labels:
|
|
127
|
+
existing_labels.append(name)
|
|
128
|
+
self._group_handler.write_attrs({"labels": existing_labels})
|
|
129
|
+
|
|
130
|
+
def new(
|
|
131
|
+
self,
|
|
132
|
+
name: str,
|
|
133
|
+
shape: Collection[int],
|
|
134
|
+
xy_pixelsize: float,
|
|
135
|
+
z_spacing: float = 1.0,
|
|
136
|
+
time_spacing: float = 1.0,
|
|
137
|
+
levels: "int | list[str]" = 5,
|
|
138
|
+
xy_scaling_factor: float = 2.0,
|
|
139
|
+
z_scaling_factor: float = 1.0,
|
|
140
|
+
space_unit: SpaceUnits | str | None = None,
|
|
141
|
+
time_unit: TimeUnits | str | None = None,
|
|
142
|
+
axes_names: Collection[str] | None = None,
|
|
143
|
+
chunks: Collection[int] | None = None,
|
|
144
|
+
dtype: str = "uint16",
|
|
145
|
+
overwrite: bool = False,
|
|
146
|
+
version: str = "0.4",
|
|
147
|
+
) -> None:
|
|
148
|
+
"""Add a label to the group."""
|
|
149
|
+
existing_labels = self.list()
|
|
150
|
+
if name in existing_labels and not overwrite:
|
|
151
|
+
raise NgioValueError(
|
|
152
|
+
f"Table '{name}' already exists in the group. "
|
|
153
|
+
"Use overwrite=True to replace it."
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
label_group = self._group_handler.get_group(name, create_mode=True)
|
|
157
|
+
|
|
158
|
+
_create_empty_label(
|
|
159
|
+
store=label_group,
|
|
160
|
+
shape=shape,
|
|
161
|
+
xy_pixelsize=xy_pixelsize,
|
|
162
|
+
z_spacing=z_spacing,
|
|
163
|
+
time_spacing=time_spacing,
|
|
164
|
+
levels=levels,
|
|
165
|
+
xy_scaling_factor=xy_scaling_factor,
|
|
166
|
+
z_scaling_factor=z_scaling_factor,
|
|
167
|
+
space_unit=space_unit,
|
|
168
|
+
time_unit=time_unit,
|
|
169
|
+
axes_names=axes_names,
|
|
170
|
+
chunks=chunks,
|
|
171
|
+
dtype=dtype,
|
|
172
|
+
overwrite=overwrite,
|
|
173
|
+
version=version,
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
if name not in existing_labels:
|
|
177
|
+
existing_labels.append(name)
|
|
178
|
+
self._group_handler.write_attrs({"labels": existing_labels})
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def _derive_label(
|
|
182
|
+
ref_image: Image,
|
|
183
|
+
store: StoreOrGroup,
|
|
184
|
+
shape: Collection[int] | None = None,
|
|
185
|
+
chunks: Collection[int] | None = None,
|
|
186
|
+
dtype: str = "uint16",
|
|
187
|
+
xy_scaling_factor=2.0,
|
|
188
|
+
z_scaling_factor=1.0,
|
|
189
|
+
overwrite: bool = False,
|
|
190
|
+
) -> None:
|
|
191
|
+
"""Create an OME-Zarr image from a numpy array."""
|
|
192
|
+
ref_meta = ref_image.meta
|
|
193
|
+
# remove channls if present
|
|
194
|
+
shape_ref = ref_image.shape
|
|
195
|
+
chunks_ref = ref_image.chunks
|
|
196
|
+
axes_names_ref = ref_image.dataset.axes_mapper.on_disk_axes_names
|
|
197
|
+
c_axis = ref_image.dataset.axes_mapper.get_index("c")
|
|
198
|
+
if c_axis is not None:
|
|
199
|
+
shape_ref = shape_ref[:c_axis] + shape_ref[c_axis + 1 :]
|
|
200
|
+
chunks_ref = chunks_ref[:c_axis] + chunks_ref[c_axis + 1 :]
|
|
201
|
+
axes_names_ref = axes_names_ref[:c_axis] + axes_names_ref[c_axis + 1 :]
|
|
202
|
+
|
|
203
|
+
if shape is None:
|
|
204
|
+
shape = shape_ref
|
|
205
|
+
|
|
206
|
+
if chunks is None:
|
|
207
|
+
chunks = chunks_ref
|
|
208
|
+
|
|
209
|
+
if len(shape) != len(shape_ref):
|
|
210
|
+
raise NgioValidationError(
|
|
211
|
+
"The shape of the new image does not match the reference image."
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
if len(chunks) != len(chunks_ref):
|
|
215
|
+
raise NgioValidationError(
|
|
216
|
+
"The chunks of the new image does not match the reference image."
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
_ = _create_empty_label(
|
|
220
|
+
store=store,
|
|
221
|
+
shape=shape,
|
|
222
|
+
xy_pixelsize=ref_image.pixel_size.x,
|
|
223
|
+
z_spacing=ref_image.pixel_size.z,
|
|
224
|
+
time_spacing=ref_image.pixel_size.t,
|
|
225
|
+
levels=ref_meta.levels,
|
|
226
|
+
xy_scaling_factor=xy_scaling_factor,
|
|
227
|
+
z_scaling_factor=z_scaling_factor,
|
|
228
|
+
time_unit=ref_image.pixel_size.time_unit,
|
|
229
|
+
space_unit=ref_image.pixel_size.space_unit,
|
|
230
|
+
axes_names=axes_names_ref,
|
|
231
|
+
chunks=chunks,
|
|
232
|
+
dtype=dtype,
|
|
233
|
+
overwrite=overwrite,
|
|
234
|
+
version=ref_meta.version,
|
|
235
|
+
)
|
|
236
|
+
return None
|
ngio/images/omezarr_container.py
CHANGED
|
@@ -175,6 +175,8 @@ class OmeZarrContainer:
|
|
|
175
175
|
ref_path: str | None = None,
|
|
176
176
|
shape: Collection[int] | None = None,
|
|
177
177
|
chunks: Collection[int] | None = None,
|
|
178
|
+
xy_scaling_factor: float = 2.0,
|
|
179
|
+
z_scaling_factor: float = 1.0,
|
|
178
180
|
copy_tables: bool = False,
|
|
179
181
|
copy_labels: bool = False,
|
|
180
182
|
overwrite: bool = False,
|
|
@@ -191,6 +193,8 @@ class OmeZarrContainer:
|
|
|
191
193
|
ref_path=ref_path,
|
|
192
194
|
shape=shape,
|
|
193
195
|
chunks=chunks,
|
|
196
|
+
xy_scaling_factor=xy_scaling_factor,
|
|
197
|
+
z_scaling_factor=z_scaling_factor,
|
|
194
198
|
overwrite=overwrite,
|
|
195
199
|
)
|
|
196
200
|
return OmeZarrContainer(
|
|
@@ -281,15 +285,34 @@ class OmeZarrContainer:
|
|
|
281
285
|
raise NgioValidationError("No labels found in the image.")
|
|
282
286
|
return self._labels_container.get(name=name, path=path)
|
|
283
287
|
|
|
284
|
-
def derive_label(
|
|
288
|
+
def derive_label(
|
|
289
|
+
self,
|
|
290
|
+
name: str,
|
|
291
|
+
ref_image: Image | None = None,
|
|
292
|
+
shape: Collection[int] | None = None,
|
|
293
|
+
chunks: Collection[int] | None = None,
|
|
294
|
+
dtype: str = "uint16",
|
|
295
|
+
xy_scaling_factor=2.0,
|
|
296
|
+
z_scaling_factor=1.0,
|
|
297
|
+
overwrite: bool = False,
|
|
298
|
+
) -> Label:
|
|
285
299
|
"""Derive a label from an image."""
|
|
286
300
|
if self._labels_container is None:
|
|
287
301
|
raise NgioValidationError("No labels found in the image.")
|
|
288
302
|
|
|
289
|
-
ref_image
|
|
290
|
-
|
|
291
|
-
|
|
303
|
+
if ref_image is None:
|
|
304
|
+
ref_image = self.get_image()
|
|
305
|
+
self._labels_container.derive(
|
|
306
|
+
name=name,
|
|
307
|
+
ref_image=ref_image,
|
|
308
|
+
shape=shape,
|
|
309
|
+
chunks=chunks,
|
|
310
|
+
dtype=dtype,
|
|
311
|
+
xy_scaling_factor=xy_scaling_factor,
|
|
312
|
+
z_scaling_factor=z_scaling_factor,
|
|
313
|
+
overwrite=overwrite,
|
|
292
314
|
)
|
|
315
|
+
return self.get_label(name, path="0")
|
|
293
316
|
|
|
294
317
|
|
|
295
318
|
def open_omezarr_container(
|
ngio/utils/_datasets.py
CHANGED
|
@@ -4,7 +4,7 @@ ngio/common/_array_pipe.py,sha256=DyYjGTy2L74zBtD6S2jGPsFG4zj7KaY39TwPGWsSf8g,48
|
|
|
4
4
|
ngio/common/_axes_transforms.py,sha256=Dmrta3ZT1IgZAWomdUeTZVje8TBF_oU3RMKBv1r4EvM,1989
|
|
5
5
|
ngio/common/_common_types.py,sha256=OkAYNSNjZkixL1MI-HPBVuXamheFBr862uJ4PvTxmhk,129
|
|
6
6
|
ngio/common/_dimensions.py,sha256=t3X2wzqCl3-UeocqIpQgKRdcWYagijtKsaHTQz5bfT4,3680
|
|
7
|
-
ngio/common/_pyramid.py,sha256=
|
|
7
|
+
ngio/common/_pyramid.py,sha256=aBxRBjW7y6D-Rj8f9B3dtqIErxk2eq20O58C33NBU0Q,7231
|
|
8
8
|
ngio/common/_roi.py,sha256=q7HZg2lPbnJ6flKRgK9e4nfOIgkGpDjDcdz-tE8F0Ys,2869
|
|
9
9
|
ngio/common/_slicer.py,sha256=Qk7XXmd4W9T3w55LvFTjAyloyIcS9tt9NTXiDZNwOx8,3076
|
|
10
10
|
ngio/common/_zoom.py,sha256=z2UjgotoDw7pvpeZVrxiGx4PXx65nk1vwQH3osTFACI,5422
|
|
@@ -12,9 +12,9 @@ ngio/hcs/__init__.py,sha256=ugnRl22hM9dic5XRsqQr-HCyyyY1qXTqYOAOzyOZm4M,1624
|
|
|
12
12
|
ngio/images/__init__.py,sha256=aijqG14eyqVgHtnlcKVNx37FRfT6QvKt8V6bwBpX_r8,526
|
|
13
13
|
ngio/images/abstract_image.py,sha256=n4akBHWQul7vmo4OlYtKWZwpsYl8IYg82AThJrvDrxc,7113
|
|
14
14
|
ngio/images/create.py,sha256=DMyiNVmj3uaJmJQqsL9ftzZNvXxeqgZ0-Pjo63WqWoM,8991
|
|
15
|
-
ngio/images/image.py,sha256=
|
|
16
|
-
ngio/images/label.py,sha256=
|
|
17
|
-
ngio/images/omezarr_container.py,sha256=
|
|
15
|
+
ngio/images/image.py,sha256=QiSdOaZSLWtAweecMj69hXXAdVnPIkO3Qfjvs8QII3o,12586
|
|
16
|
+
ngio/images/label.py,sha256=wzpIsIFuKdTOcTU57PHpIf_U4Fh6TwRhM-tLpEt4GbI,7520
|
|
17
|
+
ngio/images/omezarr_container.py,sha256=E0uDyBM1vZ8kCwXI6tIyPDl7QEdi5e91hI5AIWf8kFY,19161
|
|
18
18
|
ngio/ome_zarr_meta/__init__.py,sha256=9kYdyuCc3ouQCLDyUCB_lCVXUJ69Ls0fYwtodk3GtYI,798
|
|
19
19
|
ngio/ome_zarr_meta/_generic_handlers.py,sha256=4zRm3P1CRKgUQgD5Z2C9j8VVv659DZIifrmzkQ7o31I,10987
|
|
20
20
|
ngio/ome_zarr_meta/_meta_handlers.py,sha256=b6r1zX3SBBTKoQdKfEqvJaSnTOen5t1EPO3rh0I9VH4,4925
|
|
@@ -43,11 +43,11 @@ ngio/tables/v1/_generic_table.py,sha256=KOVzbeUs8AwVvI83Os5gBZky948ucEKjxXl2CGzS
|
|
|
43
43
|
ngio/tables/v1/_masking_roi_table.py,sha256=vPlUWGQalxDJ7G4NcSmzsOFqSEIJFXbuCLD_ucBj7ew,5492
|
|
44
44
|
ngio/tables/v1/_roi_table.py,sha256=UMwJEMkOAgDf-80z0qPfIiB6fsQInjzjDlR4OkBYH4o,7147
|
|
45
45
|
ngio/utils/__init__.py,sha256=fhT4CUTk3obQHzjfTcZYOwjZrSuuI1uXQ8qJmyH17iY,1021
|
|
46
|
-
ngio/utils/_datasets.py,sha256=
|
|
46
|
+
ngio/utils/_datasets.py,sha256=Ir5-DUaplJoWXIsFCVp6yaJNfEKXKygj6RbGsy275uE,1669
|
|
47
47
|
ngio/utils/_errors.py,sha256=pKQ12LUjQLYE1nUawemA5h7HsgznjaSvV1n2PQU33N0,759
|
|
48
48
|
ngio/utils/_logger.py,sha256=zvFG-Ta3ZIJxTyY93zYoPGp2A6TTUf7mSO0zr_uFy4A,837
|
|
49
49
|
ngio/utils/_zarr_utils.py,sha256=5Mo8Nfb7oww7rGVqEWUH29VvOkhD3-Despb3c1SlENM,12172
|
|
50
|
-
ngio-0.2.
|
|
51
|
-
ngio-0.2.
|
|
52
|
-
ngio-0.2.
|
|
53
|
-
ngio-0.2.
|
|
50
|
+
ngio-0.2.0a2.dist-info/METADATA,sha256=-NUZl0xeZ-rFEqPilWo_hFfbQ-uuyCFa2cv2bLxkABo,4804
|
|
51
|
+
ngio-0.2.0a2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
52
|
+
ngio-0.2.0a2.dist-info/licenses/LICENSE,sha256=UgN_a1QCeNh9rZWfz-wORQFxE3elQzLWPQaoK6N6fxQ,1502
|
|
53
|
+
ngio-0.2.0a2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|