ngio 0.2.0a2__py3-none-any.whl → 0.2.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.
- ngio/__init__.py +4 -4
- ngio/common/__init__.py +12 -2
- ngio/common/_array_pipe.py +106 -0
- ngio/common/_axes_transforms.py +3 -2
- ngio/common/_dimensions.py +7 -0
- ngio/common/_masking_roi.py +158 -0
- ngio/common/_pyramid.py +16 -11
- ngio/common/_roi.py +74 -0
- ngio/common/_slicer.py +1 -2
- ngio/common/_zoom.py +5 -3
- ngio/hcs/__init__.py +2 -57
- ngio/hcs/plate.py +399 -0
- ngio/images/abstract_image.py +97 -28
- ngio/images/create.py +48 -29
- ngio/images/image.py +121 -57
- ngio/images/label.py +131 -86
- ngio/images/masked_image.py +259 -0
- ngio/images/omezarr_container.py +250 -77
- ngio/ome_zarr_meta/__init__.py +25 -13
- ngio/ome_zarr_meta/_meta_handlers.py +718 -69
- ngio/ome_zarr_meta/ngio_specs/__init__.py +8 -0
- ngio/ome_zarr_meta/ngio_specs/_channels.py +11 -0
- ngio/ome_zarr_meta/ngio_specs/_ngio_hcs.py +374 -2
- ngio/ome_zarr_meta/ngio_specs/_ngio_image.py +174 -113
- ngio/ome_zarr_meta/ngio_specs/_pixel_size.py +35 -3
- ngio/ome_zarr_meta/v04/__init__.py +17 -5
- ngio/ome_zarr_meta/v04/_v04_spec_utils.py +85 -12
- ngio/tables/__init__.py +2 -0
- ngio/tables/_validators.py +2 -4
- ngio/tables/backends/_anndata_utils.py +2 -1
- ngio/tables/backends/_anndata_v1.py +2 -1
- ngio/tables/backends/_json_v1.py +1 -1
- ngio/tables/tables_container.py +12 -2
- ngio/tables/v1/__init__.py +1 -2
- ngio/tables/v1/_feature_table.py +7 -5
- ngio/tables/v1/_generic_table.py +65 -11
- ngio/tables/v1/_roi_table.py +145 -27
- ngio/utils/__init__.py +3 -0
- ngio/utils/_datasets.py +4 -2
- ngio/utils/_fractal_fsspec_store.py +13 -0
- ngio/utils/_logger.py +3 -1
- ngio/utils/_zarr_utils.py +25 -2
- {ngio-0.2.0a2.dist-info → ngio-0.2.0b1.dist-info}/METADATA +4 -1
- ngio-0.2.0b1.dist-info/RECORD +54 -0
- ngio/ome_zarr_meta/_generic_handlers.py +0 -320
- ngio/ome_zarr_meta/v04/_meta_handlers.py +0 -54
- ngio/tables/v1/_masking_roi_table.py +0 -175
- ngio-0.2.0a2.dist-info/RECORD +0 -53
- {ngio-0.2.0a2.dist-info → ngio-0.2.0b1.dist-info}/WHEEL +0 -0
- {ngio-0.2.0a2.dist-info → ngio-0.2.0b1.dist-info}/licenses/LICENSE +0 -0
ngio/images/omezarr_container.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"""Abstract class for handling OME-NGFF images."""
|
|
2
2
|
|
|
3
|
-
# %%
|
|
4
3
|
from collections.abc import Collection
|
|
5
4
|
from typing import Literal, overload
|
|
6
5
|
|
|
@@ -9,6 +8,7 @@ import numpy as np
|
|
|
9
8
|
from ngio.images.create import _create_empty_image
|
|
10
9
|
from ngio.images.image import Image, ImagesContainer
|
|
11
10
|
from ngio.images.label import Label, LabelsContainer
|
|
11
|
+
from ngio.images.masked_image import MaskedImage, MaskedLabel
|
|
12
12
|
from ngio.ome_zarr_meta import (
|
|
13
13
|
NgioImageMeta,
|
|
14
14
|
PixelSize,
|
|
@@ -19,6 +19,7 @@ from ngio.ome_zarr_meta.ngio_specs import (
|
|
|
19
19
|
)
|
|
20
20
|
from ngio.tables import (
|
|
21
21
|
FeatureTable,
|
|
22
|
+
GenericRoiTable,
|
|
22
23
|
MaskingROITable,
|
|
23
24
|
RoiTable,
|
|
24
25
|
Table,
|
|
@@ -57,23 +58,16 @@ class OmeZarrContainer:
|
|
|
57
58
|
|
|
58
59
|
def __init__(
|
|
59
60
|
self,
|
|
60
|
-
|
|
61
|
-
cache: bool = False,
|
|
62
|
-
mode: AccessModeLiteral = "r+",
|
|
61
|
+
group_handler: ZarrGroupHandler,
|
|
63
62
|
table_container: TablesContainer | None = None,
|
|
64
63
|
label_container: LabelsContainer | None = None,
|
|
65
64
|
validate_arrays: bool = True,
|
|
66
65
|
) -> None:
|
|
67
66
|
"""Initialize the OmeZarrContainer."""
|
|
68
|
-
self._group_handler =
|
|
67
|
+
self._group_handler = group_handler
|
|
69
68
|
self._images_container = ImagesContainer(self._group_handler)
|
|
70
69
|
|
|
71
|
-
if label_container is None:
|
|
72
|
-
label_container = _default_label_container(self._group_handler)
|
|
73
70
|
self._labels_container = label_container
|
|
74
|
-
|
|
75
|
-
if table_container is None:
|
|
76
|
-
table_container = _default_table_container(self._group_handler)
|
|
77
71
|
self._tables_container = table_container
|
|
78
72
|
|
|
79
73
|
def __repr__(self) -> str:
|
|
@@ -102,14 +96,18 @@ class OmeZarrContainer:
|
|
|
102
96
|
def labels_container(self) -> LabelsContainer:
|
|
103
97
|
"""Return the labels container."""
|
|
104
98
|
if self._labels_container is None:
|
|
105
|
-
|
|
99
|
+
self._labels_container = _default_label_container(self._group_handler)
|
|
100
|
+
if self._labels_container is None:
|
|
101
|
+
raise NgioValidationError("No labels found in the image.")
|
|
106
102
|
return self._labels_container
|
|
107
103
|
|
|
108
104
|
@property
|
|
109
105
|
def tables_container(self) -> TablesContainer:
|
|
110
106
|
"""Return the tables container."""
|
|
111
107
|
if self._tables_container is None:
|
|
112
|
-
|
|
108
|
+
self._tables_container = _default_table_container(self._group_handler)
|
|
109
|
+
if self._tables_container is None:
|
|
110
|
+
raise NgioValidationError("No tables found in the image.")
|
|
113
111
|
return self._tables_container
|
|
114
112
|
|
|
115
113
|
@property
|
|
@@ -160,13 +158,58 @@ class OmeZarrContainer:
|
|
|
160
158
|
self,
|
|
161
159
|
path: str | None = None,
|
|
162
160
|
pixel_size: PixelSize | None = None,
|
|
163
|
-
|
|
161
|
+
strict: bool = False,
|
|
164
162
|
) -> Image:
|
|
165
|
-
"""Get an image at a specific level.
|
|
163
|
+
"""Get an image at a specific level.
|
|
164
|
+
|
|
165
|
+
Args:
|
|
166
|
+
path (str | None): The path to the image in the omezarr file.
|
|
167
|
+
pixel_size (PixelSize | None): The pixel size of the image.
|
|
168
|
+
strict (bool): Only used if the pixel size is provided. If True, the
|
|
169
|
+
pixel size must match the image pixel size exactly. If False, the
|
|
170
|
+
closest pixel size level will be returned.
|
|
171
|
+
|
|
172
|
+
"""
|
|
166
173
|
return self._images_container.get(
|
|
167
|
-
path=path,
|
|
168
|
-
|
|
169
|
-
|
|
174
|
+
path=path, pixel_size=pixel_size, strict=strict
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
def get_masked_image(
|
|
178
|
+
self,
|
|
179
|
+
masking_label_name: str,
|
|
180
|
+
masking_table_name: str | None = None,
|
|
181
|
+
path: str | None = None,
|
|
182
|
+
pixel_size: PixelSize | None = None,
|
|
183
|
+
strict: bool = False,
|
|
184
|
+
) -> MaskedImage:
|
|
185
|
+
"""Get a masked image at a specific level.
|
|
186
|
+
|
|
187
|
+
Args:
|
|
188
|
+
masking_label_name (str): The name of the label.
|
|
189
|
+
masking_table_name (str | None): The name of the masking table.
|
|
190
|
+
path (str | None): The path to the image in the omezarr file.
|
|
191
|
+
pixel_size (PixelSize | None): The pixel size of the image.
|
|
192
|
+
strict (bool): Only used if the pixel size is provided. If True, the
|
|
193
|
+
pixel size must match the image pixel size exactly. If False, the
|
|
194
|
+
closest pixel size level will be returned.
|
|
195
|
+
"""
|
|
196
|
+
image = self.get_image(path=path, pixel_size=pixel_size, strict=strict)
|
|
197
|
+
masking_label = self.get_label(
|
|
198
|
+
name=masking_label_name, path=path, pixel_size=pixel_size, strict=strict
|
|
199
|
+
)
|
|
200
|
+
if masking_table_name is None:
|
|
201
|
+
masking_table = masking_label.build_masking_roi_table()
|
|
202
|
+
else:
|
|
203
|
+
masking_table = self.get_table(
|
|
204
|
+
masking_table_name, check_type="masking_roi_table"
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
return MaskedImage(
|
|
208
|
+
group_handler=image._group_handler,
|
|
209
|
+
path=masking_label.path,
|
|
210
|
+
meta_handler=image.meta_handler,
|
|
211
|
+
label=masking_label,
|
|
212
|
+
masking_roi_table=masking_table,
|
|
170
213
|
)
|
|
171
214
|
|
|
172
215
|
def derive_image(
|
|
@@ -174,42 +217,74 @@ class OmeZarrContainer:
|
|
|
174
217
|
store: StoreOrGroup,
|
|
175
218
|
ref_path: str | None = None,
|
|
176
219
|
shape: Collection[int] | None = None,
|
|
220
|
+
labels: Collection[str] | None = None,
|
|
221
|
+
pixel_size: PixelSize | None = None,
|
|
222
|
+
axes_names: Collection[str] | None = None,
|
|
177
223
|
chunks: Collection[int] | None = None,
|
|
178
|
-
|
|
179
|
-
z_scaling_factor: float = 1.0,
|
|
180
|
-
copy_tables: bool = False,
|
|
224
|
+
dtype: str | None = None,
|
|
181
225
|
copy_labels: bool = False,
|
|
226
|
+
copy_tables: bool = False,
|
|
182
227
|
overwrite: bool = False,
|
|
183
228
|
) -> "OmeZarrContainer":
|
|
184
|
-
"""
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
229
|
+
"""Create an empty OME-Zarr container from an existing image.
|
|
230
|
+
|
|
231
|
+
Args:
|
|
232
|
+
store (StoreOrGroup): The Zarr store or group to create the image in.
|
|
233
|
+
ref_path (str | None): The path to the reference image in
|
|
234
|
+
the image container.
|
|
235
|
+
shape (Collection[int] | None): The shape of the new image.
|
|
236
|
+
labels (Collection[str] | None): The labels of the new image.
|
|
237
|
+
pixel_size (PixelSize | None): The pixel size of the new image.
|
|
238
|
+
axes_names (Collection[str] | None): The axes names of the new image.
|
|
239
|
+
chunks (Collection[int] | None): The chunk shape of the new image.
|
|
240
|
+
dtype (str | None): The data type of the new image.
|
|
241
|
+
copy_labels (bool): Whether to copy the labels from the reference image.
|
|
242
|
+
copy_tables (bool): Whether to copy the tables from the reference image.
|
|
243
|
+
overwrite (bool): Whether to overwrite an existing image.
|
|
244
|
+
|
|
245
|
+
Returns:
|
|
246
|
+
OmeZarrContainer: The new image container.
|
|
247
|
+
|
|
248
|
+
"""
|
|
191
249
|
_ = self._images_container.derive(
|
|
192
250
|
store=store,
|
|
193
251
|
ref_path=ref_path,
|
|
194
252
|
shape=shape,
|
|
253
|
+
labels=labels,
|
|
254
|
+
pixel_size=pixel_size,
|
|
255
|
+
axes_names=axes_names,
|
|
195
256
|
chunks=chunks,
|
|
196
|
-
|
|
197
|
-
z_scaling_factor=z_scaling_factor,
|
|
257
|
+
dtype=dtype,
|
|
198
258
|
overwrite=overwrite,
|
|
199
259
|
)
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
cache=
|
|
203
|
-
mode="r+",
|
|
204
|
-
table_container=None,
|
|
205
|
-
label_container=None,
|
|
260
|
+
|
|
261
|
+
handler = ZarrGroupHandler(
|
|
262
|
+
store, cache=self._group_handler.use_cache, mode=self._group_handler.mode
|
|
206
263
|
)
|
|
207
264
|
|
|
265
|
+
new_omezarr = OmeZarrContainer(
|
|
266
|
+
group_handler=handler,
|
|
267
|
+
validate_arrays=False,
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
if copy_labels:
|
|
271
|
+
self.labels_container._group_handler.copy_handler(
|
|
272
|
+
new_omezarr.labels_container._group_handler
|
|
273
|
+
)
|
|
274
|
+
|
|
275
|
+
if copy_tables:
|
|
276
|
+
self.tables_container._group_handler.copy_handler(
|
|
277
|
+
new_omezarr.tables_container._group_handler
|
|
278
|
+
)
|
|
279
|
+
return new_omezarr
|
|
280
|
+
|
|
208
281
|
def list_tables(self) -> list[str]:
|
|
209
282
|
"""List all tables in the image."""
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
283
|
+
return self.tables_container.list()
|
|
284
|
+
|
|
285
|
+
def list_roi_tables(self) -> list[str]:
|
|
286
|
+
"""List all ROI tables in the image."""
|
|
287
|
+
return self.tables_container.list_roi_tables()
|
|
213
288
|
|
|
214
289
|
@overload
|
|
215
290
|
def get_table(self, name: str, check_type: None) -> Table: ...
|
|
@@ -227,12 +302,14 @@ class OmeZarrContainer:
|
|
|
227
302
|
self, name: str, check_type: Literal["feature_table"]
|
|
228
303
|
) -> FeatureTable: ...
|
|
229
304
|
|
|
305
|
+
@overload
|
|
306
|
+
def get_table(
|
|
307
|
+
self, name: str, check_type: Literal["generic_roi_table"]
|
|
308
|
+
) -> GenericRoiTable: ...
|
|
309
|
+
|
|
230
310
|
def get_table(self, name: str, check_type: TypedTable | None = None) -> Table:
|
|
231
311
|
"""Get a table from the image."""
|
|
232
|
-
|
|
233
|
-
raise NgioValidationError("No tables found in the image.")
|
|
234
|
-
|
|
235
|
-
table = self._tables_container.get(name)
|
|
312
|
+
table = self.tables_container.get(name)
|
|
236
313
|
match check_type:
|
|
237
314
|
case "roi_table":
|
|
238
315
|
if not isinstance(table, RoiTable):
|
|
@@ -247,6 +324,15 @@ class OmeZarrContainer:
|
|
|
247
324
|
f"Found type: {table.type()}"
|
|
248
325
|
)
|
|
249
326
|
return table
|
|
327
|
+
|
|
328
|
+
case "generic_roi_table":
|
|
329
|
+
if not isinstance(table, GenericRoiTable):
|
|
330
|
+
raise NgioValueError(
|
|
331
|
+
f"Table '{name}' is not a generic ROI table. "
|
|
332
|
+
f"Found type: {table.type()}"
|
|
333
|
+
)
|
|
334
|
+
return table
|
|
335
|
+
|
|
250
336
|
case "feature_table":
|
|
251
337
|
if not isinstance(table, FeatureTable):
|
|
252
338
|
raise NgioValueError(
|
|
@@ -259,6 +345,14 @@ class OmeZarrContainer:
|
|
|
259
345
|
case _:
|
|
260
346
|
raise NgioValueError(f"Unknown check_type: {check_type}")
|
|
261
347
|
|
|
348
|
+
def build_image_roi_table(self, name: str = "image") -> RoiTable:
|
|
349
|
+
"""Compute the ROI table for an image."""
|
|
350
|
+
return self.get_image().build_image_roi_table(name=name)
|
|
351
|
+
|
|
352
|
+
def build_masking_roi_table(self, label: str) -> MaskingROITable:
|
|
353
|
+
"""Compute the masking ROI table for a label."""
|
|
354
|
+
return self.get_label(label).build_masking_roi_table()
|
|
355
|
+
|
|
262
356
|
def add_table(
|
|
263
357
|
self,
|
|
264
358
|
name: str,
|
|
@@ -267,52 +361,120 @@ class OmeZarrContainer:
|
|
|
267
361
|
overwrite: bool = False,
|
|
268
362
|
) -> None:
|
|
269
363
|
"""Add a table to the image."""
|
|
270
|
-
|
|
271
|
-
raise NgioValidationError("No tables found in the image.")
|
|
272
|
-
self._tables_container.add(
|
|
364
|
+
self.tables_container.add(
|
|
273
365
|
name=name, table=table, backend=backend, overwrite=overwrite
|
|
274
366
|
)
|
|
275
367
|
|
|
276
368
|
def list_labels(self) -> list[str]:
|
|
277
369
|
"""List all labels in the image."""
|
|
278
|
-
|
|
279
|
-
return []
|
|
280
|
-
return self._labels_container.list()
|
|
370
|
+
return self.labels_container.list()
|
|
281
371
|
|
|
282
|
-
def get_label(
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
372
|
+
def get_label(
|
|
373
|
+
self,
|
|
374
|
+
name: str,
|
|
375
|
+
path: str | None = None,
|
|
376
|
+
pixel_size: PixelSize | None = None,
|
|
377
|
+
strict: bool = False,
|
|
378
|
+
) -> Label:
|
|
379
|
+
"""Get a label from the group.
|
|
380
|
+
|
|
381
|
+
Args:
|
|
382
|
+
name (str): The name of the label.
|
|
383
|
+
path (str | None): The path to the image in the omezarr file.
|
|
384
|
+
pixel_size (PixelSize | None): The pixel size of the image.
|
|
385
|
+
strict (bool): Only used if the pixel size is provided. If True, the
|
|
386
|
+
pixel size must match the image pixel size exactly. If False, the
|
|
387
|
+
closest pixel size level will be returned.
|
|
388
|
+
"""
|
|
389
|
+
return self.labels_container.get(
|
|
390
|
+
name=name, path=path, pixel_size=pixel_size, strict=strict
|
|
391
|
+
)
|
|
392
|
+
|
|
393
|
+
def get_masked_label(
|
|
394
|
+
self,
|
|
395
|
+
label_name: str,
|
|
396
|
+
masking_label_name: str,
|
|
397
|
+
masking_table_name: str | None = None,
|
|
398
|
+
path: str | None = None,
|
|
399
|
+
pixel_size: PixelSize | None = None,
|
|
400
|
+
strict: bool = False,
|
|
401
|
+
) -> MaskedLabel:
|
|
402
|
+
"""Get a masked image at a specific level.
|
|
403
|
+
|
|
404
|
+
Args:
|
|
405
|
+
label_name (str): The name of the label.
|
|
406
|
+
masking_label_name (str): The name of the masking label.
|
|
407
|
+
masking_table_name (str | None): The name of the masking table.
|
|
408
|
+
path (str | None): The path to the image in the omezarr file.
|
|
409
|
+
pixel_size (PixelSize | None): The pixel size of the image.
|
|
410
|
+
strict (bool): Only used if the pixel size is provided. If True, the
|
|
411
|
+
pixel size must match the image pixel size exactly. If False, the
|
|
412
|
+
closest pixel size level will be returned.
|
|
413
|
+
"""
|
|
414
|
+
label = self.get_label(
|
|
415
|
+
name=label_name, path=path, pixel_size=pixel_size, strict=strict
|
|
416
|
+
)
|
|
417
|
+
masking_label = self.get_label(
|
|
418
|
+
name=masking_label_name, path=path, pixel_size=pixel_size, strict=strict
|
|
419
|
+
)
|
|
420
|
+
if masking_table_name is None:
|
|
421
|
+
masking_table = masking_label.build_masking_roi_table()
|
|
422
|
+
else:
|
|
423
|
+
masking_table = self.get_table(
|
|
424
|
+
masking_table_name, check_type="masking_roi_table"
|
|
425
|
+
)
|
|
426
|
+
|
|
427
|
+
return MaskedLabel(
|
|
428
|
+
group_handler=label._group_handler,
|
|
429
|
+
path=label.path,
|
|
430
|
+
meta_handler=label.meta_handler,
|
|
431
|
+
label=masking_label,
|
|
432
|
+
masking_roi_table=masking_table,
|
|
433
|
+
)
|
|
287
434
|
|
|
288
435
|
def derive_label(
|
|
289
436
|
self,
|
|
290
437
|
name: str,
|
|
291
438
|
ref_image: Image | None = None,
|
|
292
439
|
shape: Collection[int] | None = None,
|
|
440
|
+
pixel_size: PixelSize | None = None,
|
|
441
|
+
axes_names: Collection[str] | None = None,
|
|
293
442
|
chunks: Collection[int] | None = None,
|
|
294
|
-
dtype: str =
|
|
295
|
-
xy_scaling_factor=2.0,
|
|
296
|
-
z_scaling_factor=1.0,
|
|
443
|
+
dtype: str | None = None,
|
|
297
444
|
overwrite: bool = False,
|
|
298
|
-
) -> Label:
|
|
299
|
-
"""
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
445
|
+
) -> "Label":
|
|
446
|
+
"""Create an empty OME-Zarr label from a reference image.
|
|
447
|
+
|
|
448
|
+
And add the label to the /labels group.
|
|
449
|
+
|
|
450
|
+
Args:
|
|
451
|
+
store (StoreOrGroup): The Zarr store or group to create the image in.
|
|
452
|
+
ref_image (Image): The reference image.
|
|
453
|
+
name (str): The name of the new image.
|
|
454
|
+
shape (Collection[int] | None): The shape of the new image.
|
|
455
|
+
pixel_size (PixelSize | None): The pixel size of the new image.
|
|
456
|
+
axes_names (Collection[str] | None): The axes names of the new image.
|
|
457
|
+
For labels, the channel axis is not allowed.
|
|
458
|
+
chunks (Collection[int] | None): The chunk shape of the new image.
|
|
459
|
+
dtype (str | None): The data type of the new image.
|
|
460
|
+
overwrite (bool): Whether to overwrite an existing image.
|
|
461
|
+
|
|
462
|
+
Returns:
|
|
463
|
+
Label: The new label.
|
|
464
|
+
|
|
465
|
+
"""
|
|
303
466
|
if ref_image is None:
|
|
304
467
|
ref_image = self.get_image()
|
|
305
|
-
self.
|
|
468
|
+
return self.labels_container.derive(
|
|
306
469
|
name=name,
|
|
307
470
|
ref_image=ref_image,
|
|
308
471
|
shape=shape,
|
|
472
|
+
pixel_size=pixel_size,
|
|
473
|
+
axes_names=axes_names,
|
|
309
474
|
chunks=chunks,
|
|
310
475
|
dtype=dtype,
|
|
311
|
-
xy_scaling_factor=xy_scaling_factor,
|
|
312
|
-
z_scaling_factor=z_scaling_factor,
|
|
313
476
|
overwrite=overwrite,
|
|
314
477
|
)
|
|
315
|
-
return self.get_label(name, path="0")
|
|
316
478
|
|
|
317
479
|
|
|
318
480
|
def open_omezarr_container(
|
|
@@ -322,10 +484,9 @@ def open_omezarr_container(
|
|
|
322
484
|
validate_arrays: bool = True,
|
|
323
485
|
) -> OmeZarrContainer:
|
|
324
486
|
"""Open an OME-Zarr image."""
|
|
487
|
+
handler = ZarrGroupHandler(store=store, cache=cache, mode=mode)
|
|
325
488
|
return OmeZarrContainer(
|
|
326
|
-
|
|
327
|
-
cache=cache,
|
|
328
|
-
mode=mode,
|
|
489
|
+
group_handler=handler,
|
|
329
490
|
validate_arrays=validate_arrays,
|
|
330
491
|
)
|
|
331
492
|
|
|
@@ -334,17 +495,29 @@ def open_image(
|
|
|
334
495
|
store: StoreOrGroup,
|
|
335
496
|
path: str | None = None,
|
|
336
497
|
pixel_size: PixelSize | None = None,
|
|
337
|
-
|
|
498
|
+
strict: bool = True,
|
|
338
499
|
cache: bool = False,
|
|
339
500
|
mode: AccessModeLiteral = "r+",
|
|
340
501
|
) -> Image:
|
|
341
|
-
"""Open a single level image from an OME-Zarr image.
|
|
502
|
+
"""Open a single level image from an OME-Zarr image.
|
|
503
|
+
|
|
504
|
+
Args:
|
|
505
|
+
store (StoreOrGroup): The Zarr store or group to create the image in.
|
|
506
|
+
path (str | None): The path to the image in the omezarr file.
|
|
507
|
+
pixel_size (PixelSize | None): The pixel size of the image.
|
|
508
|
+
strict (bool): Only used if the pixel size is provided. If True, the
|
|
509
|
+
pixel size must match the image pixel size exactly. If False, the
|
|
510
|
+
closest pixel size level will be returned.
|
|
511
|
+
cache (bool): Whether to use a cache for the zarr group metadata.
|
|
512
|
+
mode (AccessModeLiteral): The
|
|
513
|
+
access mode for the image. Defaults to "r+".
|
|
514
|
+
"""
|
|
342
515
|
group_handler = ZarrGroupHandler(store, cache, mode)
|
|
343
516
|
images_container = ImagesContainer(group_handler)
|
|
344
517
|
return images_container.get(
|
|
345
518
|
path=path,
|
|
346
519
|
pixel_size=pixel_size,
|
|
347
|
-
|
|
520
|
+
strict=strict,
|
|
348
521
|
)
|
|
349
522
|
|
|
350
523
|
|
|
@@ -414,11 +587,11 @@ def create_empty_omezarr(
|
|
|
414
587
|
handler = _create_empty_image(
|
|
415
588
|
store=store,
|
|
416
589
|
shape=shape,
|
|
417
|
-
|
|
590
|
+
pixelsize=xy_pixelsize,
|
|
418
591
|
z_spacing=z_spacing,
|
|
419
592
|
time_spacing=time_spacing,
|
|
420
593
|
levels=levels,
|
|
421
|
-
|
|
594
|
+
yx_scaling_factor=xy_scaling_factor,
|
|
422
595
|
z_scaling_factor=z_scaling_factor,
|
|
423
596
|
space_unit=space_unit,
|
|
424
597
|
time_unit=time_unit,
|
|
@@ -430,7 +603,7 @@ def create_empty_omezarr(
|
|
|
430
603
|
version=version,
|
|
431
604
|
)
|
|
432
605
|
|
|
433
|
-
omezarr = OmeZarrContainer(
|
|
606
|
+
omezarr = OmeZarrContainer(group_handler=handler)
|
|
434
607
|
omezarr.initialize_channel_meta(
|
|
435
608
|
labels=channel_labels,
|
|
436
609
|
wavelength_id=channel_wavelengths,
|
|
@@ -505,11 +678,11 @@ def create_omezarr_from_array(
|
|
|
505
678
|
handler = _create_empty_image(
|
|
506
679
|
store=store,
|
|
507
680
|
shape=array.shape,
|
|
508
|
-
|
|
681
|
+
pixelsize=xy_pixelsize,
|
|
509
682
|
z_spacing=z_spacing,
|
|
510
683
|
time_spacing=time_spacing,
|
|
511
684
|
levels=levels,
|
|
512
|
-
|
|
685
|
+
yx_scaling_factor=xy_scaling_factor,
|
|
513
686
|
z_scaling_factor=z_scaling_factor,
|
|
514
687
|
space_unit=space_unit,
|
|
515
688
|
time_unit=time_unit,
|
|
@@ -521,7 +694,7 @@ def create_omezarr_from_array(
|
|
|
521
694
|
version=version,
|
|
522
695
|
)
|
|
523
696
|
|
|
524
|
-
omezarr = OmeZarrContainer(
|
|
697
|
+
omezarr = OmeZarrContainer(group_handler=handler)
|
|
525
698
|
image = omezarr.get_image()
|
|
526
699
|
image.set_array(array)
|
|
527
700
|
image.consolidate()
|
ngio/ome_zarr_meta/__init__.py
CHANGED
|
@@ -1,35 +1,47 @@
|
|
|
1
1
|
"""Utilities for reading and writing OME-Zarr metadata."""
|
|
2
2
|
|
|
3
|
-
from ngio.ome_zarr_meta.
|
|
4
|
-
BaseImageMetaHandler,
|
|
5
|
-
BaseLabelMetaHandler,
|
|
3
|
+
from ngio.ome_zarr_meta._meta_handlers import (
|
|
6
4
|
ImageMetaHandler,
|
|
7
5
|
LabelMetaHandler,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
find_image_meta_handler,
|
|
7
|
+
find_label_meta_handler,
|
|
8
|
+
find_plate_meta_handler,
|
|
9
|
+
find_well_meta_handler,
|
|
10
|
+
get_image_meta_handler,
|
|
11
|
+
get_label_meta_handler,
|
|
12
|
+
get_plate_meta_handler,
|
|
13
|
+
get_well_meta_handler,
|
|
13
14
|
)
|
|
14
15
|
from ngio.ome_zarr_meta.ngio_specs import (
|
|
15
16
|
AxesMapper,
|
|
16
17
|
Dataset,
|
|
18
|
+
ImageInWellPath,
|
|
17
19
|
NgioImageMeta,
|
|
18
20
|
NgioLabelMeta,
|
|
21
|
+
NgioPlateMeta,
|
|
22
|
+
NgioWellMeta,
|
|
19
23
|
PixelSize,
|
|
20
24
|
)
|
|
21
25
|
|
|
22
26
|
__all__ = [
|
|
23
27
|
"AxesMapper",
|
|
24
|
-
"BaseImageMetaHandler",
|
|
25
|
-
"BaseLabelMetaHandler",
|
|
26
28
|
"Dataset",
|
|
29
|
+
"ImageInWellPath",
|
|
27
30
|
"ImageMetaHandler",
|
|
28
|
-
"
|
|
29
|
-
"
|
|
31
|
+
"ImageMetaHandler",
|
|
32
|
+
"LabelMetaHandler",
|
|
30
33
|
"LabelMetaHandler",
|
|
31
34
|
"NgioImageMeta",
|
|
32
35
|
"NgioLabelMeta",
|
|
36
|
+
"NgioPlateMeta",
|
|
37
|
+
"NgioWellMeta",
|
|
33
38
|
"PixelSize",
|
|
34
|
-
"
|
|
39
|
+
"find_image_meta_handler",
|
|
40
|
+
"find_label_meta_handler",
|
|
41
|
+
"find_plate_meta_handler",
|
|
42
|
+
"find_well_meta_handler",
|
|
43
|
+
"get_image_meta_handler",
|
|
44
|
+
"get_label_meta_handler",
|
|
45
|
+
"get_plate_meta_handler",
|
|
46
|
+
"get_well_meta_handler",
|
|
35
47
|
]
|