ngio 0.2.0a2__py3-none-any.whl → 0.5.0b4__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 +40 -12
- ngio/common/__init__.py +16 -32
- ngio/common/_dimensions.py +270 -48
- ngio/common/_masking_roi.py +153 -0
- ngio/common/_pyramid.py +267 -73
- ngio/common/_roi.py +290 -66
- ngio/common/_synt_images_utils.py +101 -0
- ngio/common/_zoom.py +54 -22
- ngio/experimental/__init__.py +5 -0
- ngio/experimental/iterators/__init__.py +15 -0
- ngio/experimental/iterators/_abstract_iterator.py +390 -0
- ngio/experimental/iterators/_feature.py +189 -0
- ngio/experimental/iterators/_image_processing.py +130 -0
- ngio/experimental/iterators/_mappers.py +48 -0
- ngio/experimental/iterators/_rois_utils.py +126 -0
- ngio/experimental/iterators/_segmentation.py +235 -0
- ngio/hcs/__init__.py +17 -58
- ngio/hcs/_plate.py +1354 -0
- ngio/images/__init__.py +30 -9
- ngio/images/_abstract_image.py +968 -0
- ngio/images/_create_synt_container.py +132 -0
- ngio/images/_create_utils.py +423 -0
- ngio/images/_image.py +926 -0
- ngio/images/_label.py +417 -0
- ngio/images/_masked_image.py +531 -0
- ngio/images/_ome_zarr_container.py +1235 -0
- ngio/images/_table_ops.py +471 -0
- ngio/io_pipes/__init__.py +75 -0
- ngio/io_pipes/_io_pipes.py +361 -0
- ngio/io_pipes/_io_pipes_masked.py +488 -0
- ngio/io_pipes/_io_pipes_roi.py +146 -0
- ngio/io_pipes/_io_pipes_types.py +56 -0
- ngio/io_pipes/_match_shape.py +377 -0
- ngio/io_pipes/_ops_axes.py +344 -0
- ngio/io_pipes/_ops_slices.py +411 -0
- ngio/io_pipes/_ops_slices_utils.py +199 -0
- ngio/io_pipes/_ops_transforms.py +104 -0
- ngio/io_pipes/_zoom_transform.py +180 -0
- ngio/ome_zarr_meta/__init__.py +39 -15
- ngio/ome_zarr_meta/_meta_handlers.py +490 -96
- ngio/ome_zarr_meta/ngio_specs/__init__.py +24 -10
- ngio/ome_zarr_meta/ngio_specs/_axes.py +268 -234
- ngio/ome_zarr_meta/ngio_specs/_channels.py +125 -41
- ngio/ome_zarr_meta/ngio_specs/_dataset.py +42 -87
- ngio/ome_zarr_meta/ngio_specs/_ngio_hcs.py +536 -2
- ngio/ome_zarr_meta/ngio_specs/_ngio_image.py +202 -198
- ngio/ome_zarr_meta/ngio_specs/_pixel_size.py +72 -34
- ngio/ome_zarr_meta/v04/__init__.py +21 -5
- ngio/ome_zarr_meta/v04/_custom_models.py +18 -0
- ngio/ome_zarr_meta/v04/{_v04_spec_utils.py → _v04_spec.py} +151 -90
- ngio/ome_zarr_meta/v05/__init__.py +27 -0
- ngio/ome_zarr_meta/v05/_custom_models.py +18 -0
- ngio/ome_zarr_meta/v05/_v05_spec.py +511 -0
- ngio/resources/20200812-CardiomyocyteDifferentiation14-Cycle1_B03/mask.png +0 -0
- ngio/resources/20200812-CardiomyocyteDifferentiation14-Cycle1_B03/nuclei.png +0 -0
- ngio/resources/20200812-CardiomyocyteDifferentiation14-Cycle1_B03/raw.jpg +0 -0
- ngio/resources/__init__.py +55 -0
- ngio/resources/resource_model.py +36 -0
- ngio/tables/__init__.py +20 -4
- ngio/tables/_abstract_table.py +270 -0
- ngio/tables/_tables_container.py +449 -0
- ngio/tables/backends/__init__.py +50 -1
- ngio/tables/backends/_abstract_backend.py +200 -31
- ngio/tables/backends/_anndata.py +139 -0
- ngio/tables/backends/_anndata_utils.py +10 -114
- ngio/tables/backends/_csv.py +19 -0
- ngio/tables/backends/_json.py +92 -0
- ngio/tables/backends/_parquet.py +19 -0
- ngio/tables/backends/_py_arrow_backends.py +222 -0
- ngio/tables/backends/_table_backends.py +162 -38
- ngio/tables/backends/_utils.py +608 -0
- ngio/tables/v1/__init__.py +19 -4
- ngio/tables/v1/_condition_table.py +71 -0
- ngio/tables/v1/_feature_table.py +79 -115
- ngio/tables/v1/_generic_table.py +21 -90
- ngio/tables/v1/_roi_table.py +486 -137
- ngio/transforms/__init__.py +5 -0
- ngio/transforms/_zoom.py +19 -0
- ngio/utils/__init__.py +16 -14
- ngio/utils/_cache.py +48 -0
- ngio/utils/_datasets.py +121 -13
- ngio/utils/_fractal_fsspec_store.py +42 -0
- ngio/utils/_zarr_utils.py +374 -218
- ngio-0.5.0b4.dist-info/METADATA +147 -0
- ngio-0.5.0b4.dist-info/RECORD +88 -0
- {ngio-0.2.0a2.dist-info → ngio-0.5.0b4.dist-info}/WHEEL +1 -1
- ngio/common/_array_pipe.py +0 -160
- ngio/common/_axes_transforms.py +0 -63
- ngio/common/_common_types.py +0 -5
- ngio/common/_slicer.py +0 -97
- ngio/images/abstract_image.py +0 -240
- ngio/images/create.py +0 -251
- ngio/images/image.py +0 -389
- ngio/images/label.py +0 -236
- ngio/images/omezarr_container.py +0 -535
- ngio/ome_zarr_meta/_generic_handlers.py +0 -320
- ngio/ome_zarr_meta/v04/_meta_handlers.py +0 -54
- ngio/tables/_validators.py +0 -192
- ngio/tables/backends/_anndata_v1.py +0 -75
- ngio/tables/backends/_json_v1.py +0 -56
- ngio/tables/tables_container.py +0 -300
- ngio/tables/v1/_masking_roi_table.py +0 -175
- ngio/utils/_logger.py +0 -29
- ngio-0.2.0a2.dist-info/METADATA +0 -95
- ngio-0.2.0a2.dist-info/RECORD +0 -53
- {ngio-0.2.0a2.dist-info → ngio-0.5.0b4.dist-info}/licenses/LICENSE +0 -0
ngio/images/omezarr_container.py
DELETED
|
@@ -1,535 +0,0 @@
|
|
|
1
|
-
"""Abstract class for handling OME-NGFF images."""
|
|
2
|
-
|
|
3
|
-
# %%
|
|
4
|
-
from collections.abc import Collection
|
|
5
|
-
from typing import Literal, overload
|
|
6
|
-
|
|
7
|
-
import numpy as np
|
|
8
|
-
|
|
9
|
-
from ngio.images.create import _create_empty_image
|
|
10
|
-
from ngio.images.image import Image, ImagesContainer
|
|
11
|
-
from ngio.images.label import Label, LabelsContainer
|
|
12
|
-
from ngio.ome_zarr_meta import (
|
|
13
|
-
NgioImageMeta,
|
|
14
|
-
PixelSize,
|
|
15
|
-
)
|
|
16
|
-
from ngio.ome_zarr_meta.ngio_specs import (
|
|
17
|
-
SpaceUnits,
|
|
18
|
-
TimeUnits,
|
|
19
|
-
)
|
|
20
|
-
from ngio.tables import (
|
|
21
|
-
FeatureTable,
|
|
22
|
-
MaskingROITable,
|
|
23
|
-
RoiTable,
|
|
24
|
-
Table,
|
|
25
|
-
TablesContainer,
|
|
26
|
-
TypedTable,
|
|
27
|
-
)
|
|
28
|
-
from ngio.utils import (
|
|
29
|
-
AccessModeLiteral,
|
|
30
|
-
NgioValidationError,
|
|
31
|
-
NgioValueError,
|
|
32
|
-
StoreOrGroup,
|
|
33
|
-
ZarrGroupHandler,
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
def _default_table_container(handler: ZarrGroupHandler) -> TablesContainer | None:
|
|
38
|
-
"""Return a default table container."""
|
|
39
|
-
success, table_handler = handler.safe_derive_handler("tables")
|
|
40
|
-
if success and isinstance(table_handler, ZarrGroupHandler):
|
|
41
|
-
return TablesContainer(table_handler)
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
def _default_label_container(handler: ZarrGroupHandler) -> LabelsContainer | None:
|
|
45
|
-
"""Return a default label container."""
|
|
46
|
-
success, label_handler = handler.safe_derive_handler("labels")
|
|
47
|
-
if success and isinstance(label_handler, ZarrGroupHandler):
|
|
48
|
-
return LabelsContainer(label_handler)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
class OmeZarrContainer:
|
|
52
|
-
"""This class contains an OME-Zarr image and its associated tables and labels."""
|
|
53
|
-
|
|
54
|
-
_images_container: ImagesContainer
|
|
55
|
-
_labels_container: LabelsContainer | None
|
|
56
|
-
_tables_container: TablesContainer | None
|
|
57
|
-
|
|
58
|
-
def __init__(
|
|
59
|
-
self,
|
|
60
|
-
store: StoreOrGroup,
|
|
61
|
-
cache: bool = False,
|
|
62
|
-
mode: AccessModeLiteral = "r+",
|
|
63
|
-
table_container: TablesContainer | None = None,
|
|
64
|
-
label_container: LabelsContainer | None = None,
|
|
65
|
-
validate_arrays: bool = True,
|
|
66
|
-
) -> None:
|
|
67
|
-
"""Initialize the OmeZarrContainer."""
|
|
68
|
-
self._group_handler = ZarrGroupHandler(store, cache, mode)
|
|
69
|
-
self._images_container = ImagesContainer(self._group_handler)
|
|
70
|
-
|
|
71
|
-
if label_container is None:
|
|
72
|
-
label_container = _default_label_container(self._group_handler)
|
|
73
|
-
self._labels_container = label_container
|
|
74
|
-
|
|
75
|
-
if table_container is None:
|
|
76
|
-
table_container = _default_table_container(self._group_handler)
|
|
77
|
-
self._tables_container = table_container
|
|
78
|
-
|
|
79
|
-
def __repr__(self) -> str:
|
|
80
|
-
"""Return a string representation of the image."""
|
|
81
|
-
num_labels = len(self.list_labels())
|
|
82
|
-
num_tables = len(self.list_tables())
|
|
83
|
-
|
|
84
|
-
base_str = f"OmeZarrContainer(levels={self.levels}"
|
|
85
|
-
if num_labels > 0 and num_labels < 3:
|
|
86
|
-
base_str += f", labels={self.list_labels()}"
|
|
87
|
-
elif num_labels >= 3:
|
|
88
|
-
base_str += f", #labels={num_labels}"
|
|
89
|
-
if num_tables > 0 and num_tables < 3:
|
|
90
|
-
base_str += f", tables={self.list_tables()}"
|
|
91
|
-
elif num_tables >= 3:
|
|
92
|
-
base_str += f", #tables={num_tables}"
|
|
93
|
-
base_str += ")"
|
|
94
|
-
return base_str
|
|
95
|
-
|
|
96
|
-
@property
|
|
97
|
-
def images_container(self) -> ImagesContainer:
|
|
98
|
-
"""Return the image container."""
|
|
99
|
-
return self._images_container
|
|
100
|
-
|
|
101
|
-
@property
|
|
102
|
-
def labels_container(self) -> LabelsContainer:
|
|
103
|
-
"""Return the labels container."""
|
|
104
|
-
if self._labels_container is None:
|
|
105
|
-
raise NgioValidationError("No labels found in the image.")
|
|
106
|
-
return self._labels_container
|
|
107
|
-
|
|
108
|
-
@property
|
|
109
|
-
def tables_container(self) -> TablesContainer:
|
|
110
|
-
"""Return the tables container."""
|
|
111
|
-
if self._tables_container is None:
|
|
112
|
-
raise NgioValidationError("No tables found in the image.")
|
|
113
|
-
return self._tables_container
|
|
114
|
-
|
|
115
|
-
@property
|
|
116
|
-
def image_meta(self) -> NgioImageMeta:
|
|
117
|
-
"""Return the image metadata."""
|
|
118
|
-
return self._images_container.meta
|
|
119
|
-
|
|
120
|
-
@property
|
|
121
|
-
def levels(self) -> int:
|
|
122
|
-
"""Return the number of levels in the image."""
|
|
123
|
-
return self._images_container.levels
|
|
124
|
-
|
|
125
|
-
@property
|
|
126
|
-
def levels_paths(self) -> list[str]:
|
|
127
|
-
"""Return the paths of the levels in the image."""
|
|
128
|
-
return self._images_container.levels_paths
|
|
129
|
-
|
|
130
|
-
def initialize_channel_meta(
|
|
131
|
-
self,
|
|
132
|
-
labels: Collection[str] | int | None = None,
|
|
133
|
-
wavelength_id: Collection[str] | None = None,
|
|
134
|
-
percentiles: tuple[float, float] | None = None,
|
|
135
|
-
colors: Collection[str] | None = None,
|
|
136
|
-
active: Collection[bool] | None = None,
|
|
137
|
-
**omero_kwargs: dict,
|
|
138
|
-
) -> None:
|
|
139
|
-
"""Create a ChannelsMeta object with the default unit."""
|
|
140
|
-
self._images_container.initialize_channel_meta(
|
|
141
|
-
labels=labels,
|
|
142
|
-
wavelength_id=wavelength_id,
|
|
143
|
-
percentiles=percentiles,
|
|
144
|
-
colors=colors,
|
|
145
|
-
active=active,
|
|
146
|
-
**omero_kwargs,
|
|
147
|
-
)
|
|
148
|
-
|
|
149
|
-
def update_percentiles(
|
|
150
|
-
self,
|
|
151
|
-
start_percentile: float = 0.1,
|
|
152
|
-
end_percentile: float = 99.9,
|
|
153
|
-
) -> None:
|
|
154
|
-
"""Update the percentiles of the image."""
|
|
155
|
-
self._images_container.update_percentiles(
|
|
156
|
-
start_percentile=start_percentile, end_percentile=end_percentile
|
|
157
|
-
)
|
|
158
|
-
|
|
159
|
-
def get_image(
|
|
160
|
-
self,
|
|
161
|
-
path: str | None = None,
|
|
162
|
-
pixel_size: PixelSize | None = None,
|
|
163
|
-
highest_resolution: bool = True,
|
|
164
|
-
) -> Image:
|
|
165
|
-
"""Get an image at a specific level."""
|
|
166
|
-
return self._images_container.get(
|
|
167
|
-
path=path,
|
|
168
|
-
pixel_size=pixel_size,
|
|
169
|
-
highest_resolution=highest_resolution,
|
|
170
|
-
)
|
|
171
|
-
|
|
172
|
-
def derive_image(
|
|
173
|
-
self,
|
|
174
|
-
store: StoreOrGroup,
|
|
175
|
-
ref_path: str | None = None,
|
|
176
|
-
shape: Collection[int] | None = None,
|
|
177
|
-
chunks: Collection[int] | None = None,
|
|
178
|
-
xy_scaling_factor: float = 2.0,
|
|
179
|
-
z_scaling_factor: float = 1.0,
|
|
180
|
-
copy_tables: bool = False,
|
|
181
|
-
copy_labels: bool = False,
|
|
182
|
-
overwrite: bool = False,
|
|
183
|
-
) -> "OmeZarrContainer":
|
|
184
|
-
"""Derive a new image from the current image."""
|
|
185
|
-
if copy_labels:
|
|
186
|
-
raise NotImplementedError("Copying labels is not yet implemented.")
|
|
187
|
-
|
|
188
|
-
if copy_tables:
|
|
189
|
-
raise NotImplementedError("Copying tables is not yet implemented.")
|
|
190
|
-
|
|
191
|
-
_ = self._images_container.derive(
|
|
192
|
-
store=store,
|
|
193
|
-
ref_path=ref_path,
|
|
194
|
-
shape=shape,
|
|
195
|
-
chunks=chunks,
|
|
196
|
-
xy_scaling_factor=xy_scaling_factor,
|
|
197
|
-
z_scaling_factor=z_scaling_factor,
|
|
198
|
-
overwrite=overwrite,
|
|
199
|
-
)
|
|
200
|
-
return OmeZarrContainer(
|
|
201
|
-
store=store,
|
|
202
|
-
cache=False,
|
|
203
|
-
mode="r+",
|
|
204
|
-
table_container=None,
|
|
205
|
-
label_container=None,
|
|
206
|
-
)
|
|
207
|
-
|
|
208
|
-
def list_tables(self) -> list[str]:
|
|
209
|
-
"""List all tables in the image."""
|
|
210
|
-
if self._tables_container is None:
|
|
211
|
-
return []
|
|
212
|
-
return self._tables_container.list()
|
|
213
|
-
|
|
214
|
-
@overload
|
|
215
|
-
def get_table(self, name: str, check_type: None) -> Table: ...
|
|
216
|
-
|
|
217
|
-
@overload
|
|
218
|
-
def get_table(self, name: str, check_type: Literal["roi_table"]) -> RoiTable: ...
|
|
219
|
-
|
|
220
|
-
@overload
|
|
221
|
-
def get_table(
|
|
222
|
-
self, name: str, check_type: Literal["masking_roi_table"]
|
|
223
|
-
) -> MaskingROITable: ...
|
|
224
|
-
|
|
225
|
-
@overload
|
|
226
|
-
def get_table(
|
|
227
|
-
self, name: str, check_type: Literal["feature_table"]
|
|
228
|
-
) -> FeatureTable: ...
|
|
229
|
-
|
|
230
|
-
def get_table(self, name: str, check_type: TypedTable | None = None) -> Table:
|
|
231
|
-
"""Get a table from the image."""
|
|
232
|
-
if self._tables_container is None:
|
|
233
|
-
raise NgioValidationError("No tables found in the image.")
|
|
234
|
-
|
|
235
|
-
table = self._tables_container.get(name)
|
|
236
|
-
match check_type:
|
|
237
|
-
case "roi_table":
|
|
238
|
-
if not isinstance(table, RoiTable):
|
|
239
|
-
raise NgioValueError(
|
|
240
|
-
f"Table '{name}' is not a ROI table. Found type: {table.type()}"
|
|
241
|
-
)
|
|
242
|
-
return table
|
|
243
|
-
case "masking_roi_table":
|
|
244
|
-
if not isinstance(table, MaskingROITable):
|
|
245
|
-
raise NgioValueError(
|
|
246
|
-
f"Table '{name}' is not a masking ROI table. "
|
|
247
|
-
f"Found type: {table.type()}"
|
|
248
|
-
)
|
|
249
|
-
return table
|
|
250
|
-
case "feature_table":
|
|
251
|
-
if not isinstance(table, FeatureTable):
|
|
252
|
-
raise NgioValueError(
|
|
253
|
-
f"Table '{name}' is not a feature table. "
|
|
254
|
-
f"Found type: {table.type()}"
|
|
255
|
-
)
|
|
256
|
-
return table
|
|
257
|
-
case None:
|
|
258
|
-
return table
|
|
259
|
-
case _:
|
|
260
|
-
raise NgioValueError(f"Unknown check_type: {check_type}")
|
|
261
|
-
|
|
262
|
-
def add_table(
|
|
263
|
-
self,
|
|
264
|
-
name: str,
|
|
265
|
-
table: Table,
|
|
266
|
-
backend: str | None = None,
|
|
267
|
-
overwrite: bool = False,
|
|
268
|
-
) -> None:
|
|
269
|
-
"""Add a table to the image."""
|
|
270
|
-
if self._tables_container is None:
|
|
271
|
-
raise NgioValidationError("No tables found in the image.")
|
|
272
|
-
self._tables_container.add(
|
|
273
|
-
name=name, table=table, backend=backend, overwrite=overwrite
|
|
274
|
-
)
|
|
275
|
-
|
|
276
|
-
def list_labels(self) -> list[str]:
|
|
277
|
-
"""List all labels in the image."""
|
|
278
|
-
if self._labels_container is None:
|
|
279
|
-
return []
|
|
280
|
-
return self._labels_container.list()
|
|
281
|
-
|
|
282
|
-
def get_label(self, name: str, path: str) -> Label:
|
|
283
|
-
"""Get a label from the image."""
|
|
284
|
-
if self._labels_container is None:
|
|
285
|
-
raise NgioValidationError("No labels found in the image.")
|
|
286
|
-
return self._labels_container.get(name=name, path=path)
|
|
287
|
-
|
|
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:
|
|
299
|
-
"""Derive a label from an image."""
|
|
300
|
-
if self._labels_container is None:
|
|
301
|
-
raise NgioValidationError("No labels found in the image.")
|
|
302
|
-
|
|
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,
|
|
314
|
-
)
|
|
315
|
-
return self.get_label(name, path="0")
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
def open_omezarr_container(
|
|
319
|
-
store: StoreOrGroup,
|
|
320
|
-
cache: bool = False,
|
|
321
|
-
mode: AccessModeLiteral = "r+",
|
|
322
|
-
validate_arrays: bool = True,
|
|
323
|
-
) -> OmeZarrContainer:
|
|
324
|
-
"""Open an OME-Zarr image."""
|
|
325
|
-
return OmeZarrContainer(
|
|
326
|
-
store=store,
|
|
327
|
-
cache=cache,
|
|
328
|
-
mode=mode,
|
|
329
|
-
validate_arrays=validate_arrays,
|
|
330
|
-
)
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
def open_image(
|
|
334
|
-
store: StoreOrGroup,
|
|
335
|
-
path: str | None = None,
|
|
336
|
-
pixel_size: PixelSize | None = None,
|
|
337
|
-
highest_resolution: bool = False,
|
|
338
|
-
cache: bool = False,
|
|
339
|
-
mode: AccessModeLiteral = "r+",
|
|
340
|
-
) -> Image:
|
|
341
|
-
"""Open a single level image from an OME-Zarr image."""
|
|
342
|
-
group_handler = ZarrGroupHandler(store, cache, mode)
|
|
343
|
-
images_container = ImagesContainer(group_handler)
|
|
344
|
-
return images_container.get(
|
|
345
|
-
path=path,
|
|
346
|
-
pixel_size=pixel_size,
|
|
347
|
-
highest_resolution=highest_resolution,
|
|
348
|
-
)
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
def create_empty_omezarr(
|
|
352
|
-
store: StoreOrGroup,
|
|
353
|
-
shape: Collection[int],
|
|
354
|
-
xy_pixelsize: float,
|
|
355
|
-
z_spacing: float = 1.0,
|
|
356
|
-
time_spacing: float = 1.0,
|
|
357
|
-
levels: int | list[str] = 5,
|
|
358
|
-
xy_scaling_factor: float = 2,
|
|
359
|
-
z_scaling_factor: float = 1.0,
|
|
360
|
-
space_unit: SpaceUnits | str | None = None,
|
|
361
|
-
time_unit: TimeUnits | str | None = None,
|
|
362
|
-
axes_names: Collection[str] | None = None,
|
|
363
|
-
name: str | None = None,
|
|
364
|
-
chunks: Collection[int] | None = None,
|
|
365
|
-
dtype: str = "uint16",
|
|
366
|
-
channel_labels: list[str] | None = None,
|
|
367
|
-
channel_wavelengths: list[str] | None = None,
|
|
368
|
-
percentiles: tuple[float, float] | None = None,
|
|
369
|
-
channel_colors: Collection[str] | None = None,
|
|
370
|
-
channel_active: Collection[bool] | None = None,
|
|
371
|
-
overwrite: bool = False,
|
|
372
|
-
version: str = "0.4",
|
|
373
|
-
) -> OmeZarrContainer:
|
|
374
|
-
"""Create an empty OME-Zarr image with the given shape and metadata.
|
|
375
|
-
|
|
376
|
-
Args:
|
|
377
|
-
store (StoreOrGroup): The Zarr store or group to create the image in.
|
|
378
|
-
shape (Collection[int]): The shape of the image.
|
|
379
|
-
xy_pixelsize (float): The pixel size in x and y dimensions.
|
|
380
|
-
z_spacing (float, optional): The spacing between z slices. Defaults to 1.0.
|
|
381
|
-
time_spacing (float, optional): The spacing between time points.
|
|
382
|
-
Defaults to 1.0.
|
|
383
|
-
levels (int | list[str], optional): The number of levels in the pyramid or a
|
|
384
|
-
list of level names. Defaults to 5.
|
|
385
|
-
xy_scaling_factor (float, optional): The down-scaling factor in x and y
|
|
386
|
-
dimensions. Defaults to 2.0.
|
|
387
|
-
z_scaling_factor (float, optional): The down-scaling factor in z dimension.
|
|
388
|
-
Defaults to 1.0.
|
|
389
|
-
space_unit (SpaceUnits | str | None, optional): The unit of space. Defaults to
|
|
390
|
-
None.
|
|
391
|
-
time_unit (TimeUnits | str | None, optional): The unit of time. Defaults to
|
|
392
|
-
None.
|
|
393
|
-
axes_names (Collection[str] | None, optional): The names of the axes.
|
|
394
|
-
If None the canonical names are used. Defaults to None.
|
|
395
|
-
name (str | None, optional): The name of the image. Defaults to None.
|
|
396
|
-
chunks (Collection[int] | None, optional): The chunk shape. If None the shape
|
|
397
|
-
is used. Defaults to None.
|
|
398
|
-
dtype (str, optional): The data type of the image. Defaults to "uint16".
|
|
399
|
-
channel_labels (list[str] | None, optional): The labels of the channels.
|
|
400
|
-
Defaults to None.
|
|
401
|
-
channel_wavelengths (list[str] | None, optional): The wavelengths of the
|
|
402
|
-
channels. Defaults to None.
|
|
403
|
-
percentiles (tuple[float, float] | None, optional): The percentiles of the
|
|
404
|
-
channels. Defaults to None.
|
|
405
|
-
channel_colors (Collection[str] | None, optional): The colors of the channels.
|
|
406
|
-
Defaults to None.
|
|
407
|
-
channel_active (Collection[bool] | None, optional): Whether the channels are
|
|
408
|
-
active. Defaults to None.
|
|
409
|
-
overwrite (bool, optional): Whether to overwrite an existing image.
|
|
410
|
-
Defaults to True.
|
|
411
|
-
version (str, optional): The version of the OME-Zarr specification.
|
|
412
|
-
Defaults to "0.4".
|
|
413
|
-
"""
|
|
414
|
-
handler = _create_empty_image(
|
|
415
|
-
store=store,
|
|
416
|
-
shape=shape,
|
|
417
|
-
xy_pixelsize=xy_pixelsize,
|
|
418
|
-
z_spacing=z_spacing,
|
|
419
|
-
time_spacing=time_spacing,
|
|
420
|
-
levels=levels,
|
|
421
|
-
xy_scaling_factor=xy_scaling_factor,
|
|
422
|
-
z_scaling_factor=z_scaling_factor,
|
|
423
|
-
space_unit=space_unit,
|
|
424
|
-
time_unit=time_unit,
|
|
425
|
-
axes_names=axes_names,
|
|
426
|
-
name=name,
|
|
427
|
-
chunks=chunks,
|
|
428
|
-
dtype=dtype,
|
|
429
|
-
overwrite=overwrite,
|
|
430
|
-
version=version,
|
|
431
|
-
)
|
|
432
|
-
|
|
433
|
-
omezarr = OmeZarrContainer(store=handler.store, mode="r+")
|
|
434
|
-
omezarr.initialize_channel_meta(
|
|
435
|
-
labels=channel_labels,
|
|
436
|
-
wavelength_id=channel_wavelengths,
|
|
437
|
-
percentiles=percentiles,
|
|
438
|
-
colors=channel_colors,
|
|
439
|
-
active=channel_active,
|
|
440
|
-
)
|
|
441
|
-
return omezarr
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
def create_omezarr_from_array(
|
|
445
|
-
store: StoreOrGroup,
|
|
446
|
-
array: np.ndarray,
|
|
447
|
-
xy_pixelsize: float,
|
|
448
|
-
z_spacing: float = 1.0,
|
|
449
|
-
time_spacing: float = 1.0,
|
|
450
|
-
levels: int | list[str] = 5,
|
|
451
|
-
xy_scaling_factor: float = 2.0,
|
|
452
|
-
z_scaling_factor: float = 1.0,
|
|
453
|
-
space_unit: SpaceUnits | str | None = None,
|
|
454
|
-
time_unit: TimeUnits | str | None = None,
|
|
455
|
-
axes_names: Collection[str] | None = None,
|
|
456
|
-
channel_labels: list[str] | None = None,
|
|
457
|
-
channel_wavelengths: list[str] | None = None,
|
|
458
|
-
percentiles: tuple[float, float] | None = (0.1, 99.9),
|
|
459
|
-
channel_colors: Collection[str] | None = None,
|
|
460
|
-
channel_active: Collection[bool] | None = None,
|
|
461
|
-
name: str | None = None,
|
|
462
|
-
chunks: Collection[int] | None = None,
|
|
463
|
-
overwrite: bool = False,
|
|
464
|
-
version: str = "0.4",
|
|
465
|
-
) -> OmeZarrContainer:
|
|
466
|
-
"""Create an OME-Zarr image from a numpy array.
|
|
467
|
-
|
|
468
|
-
Args:
|
|
469
|
-
store (StoreOrGroup): The Zarr store or group to create the image in.
|
|
470
|
-
array (np.ndarray): The image data.
|
|
471
|
-
xy_pixelsize (float): The pixel size in x and y dimensions.
|
|
472
|
-
z_spacing (float, optional): The spacing between z slices. Defaults to 1.0.
|
|
473
|
-
time_spacing (float, optional): The spacing between time points.
|
|
474
|
-
Defaults to 1.0.
|
|
475
|
-
levels (int | list[str], optional): The number of levels in the pyramid or a
|
|
476
|
-
list of level names. Defaults to 5.
|
|
477
|
-
xy_scaling_factor (float, optional): The down-scaling factor in x and y
|
|
478
|
-
dimensions. Defaults to 2.0.
|
|
479
|
-
z_scaling_factor (float, optional): The down-scaling factor in z dimension.
|
|
480
|
-
Defaults to 1.0.
|
|
481
|
-
space_unit (SpaceUnits | str | None, optional): The unit of space. Defaults to
|
|
482
|
-
None.
|
|
483
|
-
time_unit (TimeUnits | str | None, optional): The unit of time. Defaults to
|
|
484
|
-
None.
|
|
485
|
-
axes_names (Collection[str] | None, optional): The names of the axes.
|
|
486
|
-
If None the canonical names are used. Defaults to None.
|
|
487
|
-
name (str | None, optional): The name of the image. Defaults to None.
|
|
488
|
-
chunks (Collection[int] | None, optional): The chunk shape. If None the shape
|
|
489
|
-
is used. Defaults to None.
|
|
490
|
-
channel_labels (list[str] | None, optional): The labels of the channels.
|
|
491
|
-
Defaults to None.
|
|
492
|
-
channel_wavelengths (list[str] | None, optional): The wavelengths of the
|
|
493
|
-
channels. Defaults to None.
|
|
494
|
-
percentiles (tuple[float, float] | None, optional): The percentiles of the
|
|
495
|
-
channels. Defaults to None.
|
|
496
|
-
channel_colors (Collection[str] | None, optional): The colors of the channels.
|
|
497
|
-
Defaults to None.
|
|
498
|
-
channel_active (Collection[bool] | None, optional): Whether the channels are
|
|
499
|
-
active. Defaults to None.
|
|
500
|
-
overwrite (bool, optional): Whether to overwrite an existing image.
|
|
501
|
-
Defaults to True.
|
|
502
|
-
version (str, optional): The version of the OME-Zarr specification.
|
|
503
|
-
Defaults to "0.4".
|
|
504
|
-
"""
|
|
505
|
-
handler = _create_empty_image(
|
|
506
|
-
store=store,
|
|
507
|
-
shape=array.shape,
|
|
508
|
-
xy_pixelsize=xy_pixelsize,
|
|
509
|
-
z_spacing=z_spacing,
|
|
510
|
-
time_spacing=time_spacing,
|
|
511
|
-
levels=levels,
|
|
512
|
-
xy_scaling_factor=xy_scaling_factor,
|
|
513
|
-
z_scaling_factor=z_scaling_factor,
|
|
514
|
-
space_unit=space_unit,
|
|
515
|
-
time_unit=time_unit,
|
|
516
|
-
axes_names=axes_names,
|
|
517
|
-
name=name,
|
|
518
|
-
chunks=chunks,
|
|
519
|
-
dtype=array.dtype,
|
|
520
|
-
overwrite=overwrite,
|
|
521
|
-
version=version,
|
|
522
|
-
)
|
|
523
|
-
|
|
524
|
-
omezarr = OmeZarrContainer(store=handler.store, mode="r+")
|
|
525
|
-
image = omezarr.get_image()
|
|
526
|
-
image.set_array(array)
|
|
527
|
-
image.consolidate()
|
|
528
|
-
omezarr.initialize_channel_meta(
|
|
529
|
-
labels=channel_labels,
|
|
530
|
-
wavelength_id=channel_wavelengths,
|
|
531
|
-
percentiles=percentiles,
|
|
532
|
-
colors=channel_colors,
|
|
533
|
-
active=channel_active,
|
|
534
|
-
)
|
|
535
|
-
return omezarr
|