ngio 0.5.0b6__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 +69 -0
- ngio/common/__init__.py +28 -0
- ngio/common/_dimensions.py +335 -0
- ngio/common/_masking_roi.py +153 -0
- ngio/common/_pyramid.py +408 -0
- ngio/common/_roi.py +315 -0
- ngio/common/_synt_images_utils.py +101 -0
- ngio/common/_zoom.py +188 -0
- 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 +19 -0
- ngio/hcs/_plate.py +1354 -0
- ngio/images/__init__.py +44 -0
- ngio/images/_abstract_image.py +967 -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 +411 -0
- ngio/images/_masked_image.py +531 -0
- ngio/images/_ome_zarr_container.py +1237 -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 +65 -0
- ngio/ome_zarr_meta/_meta_handlers.py +536 -0
- ngio/ome_zarr_meta/ngio_specs/__init__.py +77 -0
- ngio/ome_zarr_meta/ngio_specs/_axes.py +515 -0
- ngio/ome_zarr_meta/ngio_specs/_channels.py +462 -0
- ngio/ome_zarr_meta/ngio_specs/_dataset.py +89 -0
- ngio/ome_zarr_meta/ngio_specs/_ngio_hcs.py +539 -0
- ngio/ome_zarr_meta/ngio_specs/_ngio_image.py +438 -0
- ngio/ome_zarr_meta/ngio_specs/_pixel_size.py +122 -0
- ngio/ome_zarr_meta/v04/__init__.py +27 -0
- ngio/ome_zarr_meta/v04/_custom_models.py +18 -0
- ngio/ome_zarr_meta/v04/_v04_spec.py +473 -0
- 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 +43 -0
- ngio/tables/_abstract_table.py +270 -0
- ngio/tables/_tables_container.py +449 -0
- ngio/tables/backends/__init__.py +57 -0
- ngio/tables/backends/_abstract_backend.py +240 -0
- ngio/tables/backends/_anndata.py +139 -0
- ngio/tables/backends/_anndata_utils.py +90 -0
- 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 +226 -0
- ngio/tables/backends/_utils.py +608 -0
- ngio/tables/v1/__init__.py +23 -0
- ngio/tables/v1/_condition_table.py +71 -0
- ngio/tables/v1/_feature_table.py +125 -0
- ngio/tables/v1/_generic_table.py +49 -0
- ngio/tables/v1/_roi_table.py +575 -0
- ngio/transforms/__init__.py +5 -0
- ngio/transforms/_zoom.py +19 -0
- ngio/utils/__init__.py +45 -0
- ngio/utils/_cache.py +48 -0
- ngio/utils/_datasets.py +165 -0
- ngio/utils/_errors.py +37 -0
- ngio/utils/_fractal_fsspec_store.py +42 -0
- ngio/utils/_zarr_utils.py +534 -0
- ngio-0.5.0b6.dist-info/METADATA +148 -0
- ngio-0.5.0b6.dist-info/RECORD +88 -0
- ngio-0.5.0b6.dist-info/WHEEL +4 -0
- ngio-0.5.0b6.dist-info/licenses/LICENSE +28 -0
|
@@ -0,0 +1,473 @@
|
|
|
1
|
+
"""Utilities for OME-Zarr v04 specs.
|
|
2
|
+
|
|
3
|
+
This module provides a set of classes to internally handle the metadata
|
|
4
|
+
of the OME-Zarr v04 specification.
|
|
5
|
+
|
|
6
|
+
For Images and Labels implements the following functionalities:
|
|
7
|
+
- A function to find if a dict view of the metadata is a valid OME-Zarr v04 metadata.
|
|
8
|
+
- A function to convert a v04 image metadata to a ngio image metadata.
|
|
9
|
+
- A function to convert a ngio image metadata to a v04 image metadata.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from ome_zarr_models.v04.axes import Axis as AxisV04
|
|
13
|
+
from ome_zarr_models.v04.coordinate_transformations import VectorScale as VectorScaleV04
|
|
14
|
+
from ome_zarr_models.v04.coordinate_transformations import (
|
|
15
|
+
VectorTranslation as VectorTranslationV04,
|
|
16
|
+
)
|
|
17
|
+
from ome_zarr_models.v04.hcs import HCSAttrs as HCSAttrsV04
|
|
18
|
+
from ome_zarr_models.v04.image import ImageAttrs as ImageAttrsV04
|
|
19
|
+
from ome_zarr_models.v04.image_label import ImageLabelAttrs as ImageLabelAttrsV04
|
|
20
|
+
from ome_zarr_models.v04.labels import LabelsAttrs as LabelsAttrsV04
|
|
21
|
+
from ome_zarr_models.v04.multiscales import Dataset as DatasetV04
|
|
22
|
+
from ome_zarr_models.v04.multiscales import Multiscale as MultiscaleV04
|
|
23
|
+
from ome_zarr_models.v04.multiscales import ValidTransform as ValidTransformV04
|
|
24
|
+
from ome_zarr_models.v04.omero import Channel as ChannelV04
|
|
25
|
+
from ome_zarr_models.v04.omero import Omero as OmeroV04
|
|
26
|
+
from ome_zarr_models.v04.omero import Window as WindowV04
|
|
27
|
+
|
|
28
|
+
from ngio.ome_zarr_meta.ngio_specs import (
|
|
29
|
+
AxesHandler,
|
|
30
|
+
AxesSetup,
|
|
31
|
+
Axis,
|
|
32
|
+
AxisType,
|
|
33
|
+
Channel,
|
|
34
|
+
ChannelsMeta,
|
|
35
|
+
ChannelVisualisation,
|
|
36
|
+
Dataset,
|
|
37
|
+
ImageLabelSource,
|
|
38
|
+
NgioImageMeta,
|
|
39
|
+
NgioLabelMeta,
|
|
40
|
+
NgioLabelsGroupMeta,
|
|
41
|
+
NgioPlateMeta,
|
|
42
|
+
NgioWellMeta,
|
|
43
|
+
default_channel_name,
|
|
44
|
+
)
|
|
45
|
+
from ngio.ome_zarr_meta.v04._custom_models import CustomWellAttrs as WellAttrsV04
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _v04_omero_to_channels(v04_omero: OmeroV04 | None) -> ChannelsMeta | None:
|
|
49
|
+
if v04_omero is None:
|
|
50
|
+
return None
|
|
51
|
+
|
|
52
|
+
ngio_channels = []
|
|
53
|
+
for idx, v04_channel in enumerate(v04_omero.channels):
|
|
54
|
+
channel_extra = v04_channel.model_extra
|
|
55
|
+
|
|
56
|
+
if channel_extra is None:
|
|
57
|
+
channel_extra = {}
|
|
58
|
+
|
|
59
|
+
if "label" in channel_extra:
|
|
60
|
+
label = channel_extra.pop("label")
|
|
61
|
+
else:
|
|
62
|
+
label = default_channel_name(idx)
|
|
63
|
+
|
|
64
|
+
if "wavelength_id" in channel_extra:
|
|
65
|
+
wavelength_id = channel_extra.pop("wavelength_id")
|
|
66
|
+
else:
|
|
67
|
+
wavelength_id = label
|
|
68
|
+
|
|
69
|
+
if "active" in channel_extra:
|
|
70
|
+
active = channel_extra.pop("active")
|
|
71
|
+
else:
|
|
72
|
+
active = True
|
|
73
|
+
|
|
74
|
+
channel_visualisation = ChannelVisualisation(
|
|
75
|
+
color=v04_channel.color,
|
|
76
|
+
start=v04_channel.window.start,
|
|
77
|
+
end=v04_channel.window.end,
|
|
78
|
+
min=v04_channel.window.min,
|
|
79
|
+
max=v04_channel.window.max,
|
|
80
|
+
active=active,
|
|
81
|
+
**channel_extra,
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
ngio_channels.append(
|
|
85
|
+
Channel(
|
|
86
|
+
label=label,
|
|
87
|
+
wavelength_id=wavelength_id,
|
|
88
|
+
channel_visualisation=channel_visualisation,
|
|
89
|
+
)
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
v04_omero_extra = v04_omero.model_extra if v04_omero.model_extra is not None else {}
|
|
93
|
+
return ChannelsMeta(channels=ngio_channels, **v04_omero_extra)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _compute_scale_translation(
|
|
97
|
+
v04_transforms: ValidTransformV04,
|
|
98
|
+
scale: list[float],
|
|
99
|
+
translation: list[float],
|
|
100
|
+
) -> tuple[list[float], list[float]]:
|
|
101
|
+
for v04_transform in v04_transforms:
|
|
102
|
+
if isinstance(v04_transform, VectorScaleV04):
|
|
103
|
+
scale = [t1 * t2 for t1, t2 in zip(scale, v04_transform.scale, strict=True)]
|
|
104
|
+
|
|
105
|
+
elif isinstance(v04_transform, VectorTranslationV04):
|
|
106
|
+
translation = [
|
|
107
|
+
t1 + t2
|
|
108
|
+
for t1, t2 in zip(translation, v04_transform.translation, strict=True)
|
|
109
|
+
]
|
|
110
|
+
else:
|
|
111
|
+
raise NotImplementedError(
|
|
112
|
+
f"Coordinate transformation {v04_transform} is not supported."
|
|
113
|
+
)
|
|
114
|
+
return scale, translation
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def _v04_to_ngio_datasets(
|
|
118
|
+
v04_multiscale: MultiscaleV04,
|
|
119
|
+
axes_setup: AxesSetup,
|
|
120
|
+
allow_non_canonical_axes: bool = False,
|
|
121
|
+
strict_canonical_order: bool = True,
|
|
122
|
+
) -> list[Dataset]:
|
|
123
|
+
"""Convert a v04 multiscale to a list of ngio datasets."""
|
|
124
|
+
datasets = []
|
|
125
|
+
|
|
126
|
+
global_scale = [1.0] * len(v04_multiscale.axes)
|
|
127
|
+
global_translation = [0.0] * len(v04_multiscale.axes)
|
|
128
|
+
|
|
129
|
+
if v04_multiscale.coordinateTransformations is not None:
|
|
130
|
+
global_scale, global_translation = _compute_scale_translation(
|
|
131
|
+
v04_multiscale.coordinateTransformations, global_scale, global_translation
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
# Prepare axes handler
|
|
135
|
+
axes = []
|
|
136
|
+
for v04_axis in v04_multiscale.axes:
|
|
137
|
+
unit = v04_axis.unit
|
|
138
|
+
if unit is not None and not isinstance(unit, str):
|
|
139
|
+
unit = str(unit)
|
|
140
|
+
axes.append(
|
|
141
|
+
Axis(
|
|
142
|
+
name=str(v04_axis.name),
|
|
143
|
+
axis_type=AxisType(v04_axis.type),
|
|
144
|
+
# (for some reason the type is a generic JsonValue,
|
|
145
|
+
# but it should be a string or None)
|
|
146
|
+
unit=v04_axis.unit, # type: ignore
|
|
147
|
+
)
|
|
148
|
+
)
|
|
149
|
+
axes_handler = AxesHandler(
|
|
150
|
+
axes=axes,
|
|
151
|
+
axes_setup=axes_setup,
|
|
152
|
+
allow_non_canonical_axes=allow_non_canonical_axes,
|
|
153
|
+
strict_canonical_order=strict_canonical_order,
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
for v04_dataset in v04_multiscale.datasets:
|
|
157
|
+
_scale, _translation = _compute_scale_translation(
|
|
158
|
+
v04_dataset.coordinateTransformations, global_scale, global_translation
|
|
159
|
+
)
|
|
160
|
+
datasets.append(
|
|
161
|
+
Dataset(
|
|
162
|
+
path=v04_dataset.path,
|
|
163
|
+
axes_handler=axes_handler,
|
|
164
|
+
scale=_scale,
|
|
165
|
+
translation=_translation,
|
|
166
|
+
)
|
|
167
|
+
)
|
|
168
|
+
return datasets
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def v04_to_ngio_image_meta(
|
|
172
|
+
metadata: dict,
|
|
173
|
+
axes_setup: AxesSetup | None = None,
|
|
174
|
+
allow_non_canonical_axes: bool = False,
|
|
175
|
+
strict_canonical_order: bool = True,
|
|
176
|
+
) -> NgioImageMeta:
|
|
177
|
+
"""Convert a v04 image metadata to a ngio image metadata.
|
|
178
|
+
|
|
179
|
+
Args:
|
|
180
|
+
metadata (dict): The v04 image metadata.
|
|
181
|
+
axes_setup (AxesSetup, optional): The axes setup. This is
|
|
182
|
+
required to convert image with non-canonical axes names.
|
|
183
|
+
allow_non_canonical_axes (bool, optional): Allow non-canonical axes.
|
|
184
|
+
strict_canonical_order (bool, optional): Strict canonical order.
|
|
185
|
+
|
|
186
|
+
Returns:
|
|
187
|
+
NgioImageMeta: The ngio image metadata.
|
|
188
|
+
"""
|
|
189
|
+
v04_image = ImageAttrsV04(**metadata)
|
|
190
|
+
|
|
191
|
+
if len(v04_image.multiscales) > 1:
|
|
192
|
+
raise NotImplementedError(
|
|
193
|
+
"Multiple multiscales in a single image are not supported in ngio."
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
v04_muliscale = v04_image.multiscales[0]
|
|
197
|
+
|
|
198
|
+
channels_meta = _v04_omero_to_channels(v04_image.omero)
|
|
199
|
+
axes_setup = axes_setup if axes_setup is not None else AxesSetup()
|
|
200
|
+
datasets = _v04_to_ngio_datasets(
|
|
201
|
+
v04_muliscale,
|
|
202
|
+
axes_setup=axes_setup,
|
|
203
|
+
allow_non_canonical_axes=allow_non_canonical_axes,
|
|
204
|
+
strict_canonical_order=strict_canonical_order,
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
name = v04_muliscale.name
|
|
208
|
+
if name is not None and not isinstance(name, str):
|
|
209
|
+
name = str(name)
|
|
210
|
+
return NgioImageMeta(
|
|
211
|
+
version="0.4",
|
|
212
|
+
name=name,
|
|
213
|
+
datasets=datasets,
|
|
214
|
+
channels=channels_meta,
|
|
215
|
+
)
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def v04_to_ngio_label_meta(
|
|
219
|
+
metadata: dict,
|
|
220
|
+
axes_setup: AxesSetup | None = None,
|
|
221
|
+
allow_non_canonical_axes: bool = False,
|
|
222
|
+
strict_canonical_order: bool = True,
|
|
223
|
+
) -> NgioLabelMeta:
|
|
224
|
+
"""Convert a v04 image metadata to a ngio image metadata.
|
|
225
|
+
|
|
226
|
+
Args:
|
|
227
|
+
metadata (dict): The v04 image metadata.
|
|
228
|
+
axes_setup (AxesSetup, optional): The axes setup. This is
|
|
229
|
+
required to convert image with non-canonical axes names.
|
|
230
|
+
allow_non_canonical_axes (bool, optional): Allow non-canonical axes.
|
|
231
|
+
strict_canonical_order (bool, optional): Strict canonical order.
|
|
232
|
+
|
|
233
|
+
Returns:
|
|
234
|
+
NgioImageMeta: The ngio image metadata.
|
|
235
|
+
"""
|
|
236
|
+
v04_label = ImageLabelAttrsV04(**metadata)
|
|
237
|
+
|
|
238
|
+
if len(v04_label.multiscales) > 1:
|
|
239
|
+
raise NotImplementedError(
|
|
240
|
+
"Multiple multiscales in a single image are not supported in ngio."
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
v04_muliscale = v04_label.multiscales[0]
|
|
244
|
+
|
|
245
|
+
axes_setup = axes_setup if axes_setup is not None else AxesSetup()
|
|
246
|
+
datasets = _v04_to_ngio_datasets(
|
|
247
|
+
v04_muliscale,
|
|
248
|
+
axes_setup=axes_setup,
|
|
249
|
+
allow_non_canonical_axes=allow_non_canonical_axes,
|
|
250
|
+
strict_canonical_order=strict_canonical_order,
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
source = v04_label.image_label.source
|
|
254
|
+
if source is None:
|
|
255
|
+
image_label_source = None
|
|
256
|
+
else:
|
|
257
|
+
source = v04_label.image_label.source
|
|
258
|
+
if source is None:
|
|
259
|
+
image_label_source = None
|
|
260
|
+
else:
|
|
261
|
+
image_label_source = source.image
|
|
262
|
+
image_label_source = ImageLabelSource(
|
|
263
|
+
version="0.4",
|
|
264
|
+
source={"image": image_label_source},
|
|
265
|
+
)
|
|
266
|
+
name = v04_muliscale.name
|
|
267
|
+
if name is not None and not isinstance(name, str):
|
|
268
|
+
name = str(name)
|
|
269
|
+
|
|
270
|
+
return NgioLabelMeta(
|
|
271
|
+
version="0.4",
|
|
272
|
+
name=name,
|
|
273
|
+
datasets=datasets,
|
|
274
|
+
image_label=image_label_source,
|
|
275
|
+
)
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
def _ngio_to_v04_multiscale(name: str | None, datasets: list[Dataset]) -> MultiscaleV04:
|
|
279
|
+
"""Convert a ngio multiscale to a v04 multiscale.
|
|
280
|
+
|
|
281
|
+
Args:
|
|
282
|
+
name (str | None): The name of the multiscale.
|
|
283
|
+
datasets (list[Dataset]): The ngio datasets.
|
|
284
|
+
|
|
285
|
+
Returns:
|
|
286
|
+
MultiscaleV04: The v04 multiscale.
|
|
287
|
+
"""
|
|
288
|
+
ax_mapper = datasets[0].axes_handler
|
|
289
|
+
v04_axes = []
|
|
290
|
+
for axis in ax_mapper.axes:
|
|
291
|
+
v04_axes.append(
|
|
292
|
+
AxisV04(
|
|
293
|
+
name=axis.name,
|
|
294
|
+
type=axis.axis_type.value if axis.axis_type is not None else None,
|
|
295
|
+
unit=axis.unit if axis.unit is not None else None,
|
|
296
|
+
)
|
|
297
|
+
)
|
|
298
|
+
|
|
299
|
+
v04_datasets = []
|
|
300
|
+
for dataset in datasets:
|
|
301
|
+
transform = [VectorScaleV04(type="scale", scale=list(dataset._scale))]
|
|
302
|
+
if sum(dataset._translation) > 0:
|
|
303
|
+
transform = (
|
|
304
|
+
VectorScaleV04(type="scale", scale=list(dataset._scale)),
|
|
305
|
+
VectorTranslationV04(
|
|
306
|
+
type="translation", translation=list(dataset._translation)
|
|
307
|
+
),
|
|
308
|
+
)
|
|
309
|
+
else:
|
|
310
|
+
transform = (VectorScaleV04(type="scale", scale=list(dataset._scale)),)
|
|
311
|
+
|
|
312
|
+
v04_datasets.append(
|
|
313
|
+
DatasetV04(path=dataset.path, coordinateTransformations=transform)
|
|
314
|
+
)
|
|
315
|
+
return MultiscaleV04(
|
|
316
|
+
axes=v04_axes, datasets=tuple(v04_datasets), version="0.4", name=name
|
|
317
|
+
)
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
def _ngio_to_v04_omero(channels: ChannelsMeta | None) -> OmeroV04 | None:
|
|
321
|
+
"""Convert a ngio channels to a v04 omero."""
|
|
322
|
+
if channels is None:
|
|
323
|
+
return None
|
|
324
|
+
|
|
325
|
+
v04_channels = []
|
|
326
|
+
for channel in channels.channels:
|
|
327
|
+
_model_extra = {
|
|
328
|
+
"label": channel.label,
|
|
329
|
+
"wavelength_id": channel.wavelength_id,
|
|
330
|
+
"active": channel.channel_visualisation.active,
|
|
331
|
+
}
|
|
332
|
+
if channel.channel_visualisation.model_extra is not None:
|
|
333
|
+
_model_extra.update(channel.channel_visualisation.model_extra)
|
|
334
|
+
|
|
335
|
+
v04_channels.append(
|
|
336
|
+
ChannelV04(
|
|
337
|
+
color=channel.channel_visualisation.valid_color,
|
|
338
|
+
window=WindowV04(
|
|
339
|
+
start=channel.channel_visualisation.start,
|
|
340
|
+
end=channel.channel_visualisation.end,
|
|
341
|
+
min=channel.channel_visualisation.min,
|
|
342
|
+
max=channel.channel_visualisation.max,
|
|
343
|
+
),
|
|
344
|
+
**_model_extra,
|
|
345
|
+
)
|
|
346
|
+
)
|
|
347
|
+
|
|
348
|
+
_model_extra = channels.model_extra if channels.model_extra is not None else {}
|
|
349
|
+
return OmeroV04(channels=v04_channels, **_model_extra)
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
def ngio_to_v04_image_meta(metadata: NgioImageMeta) -> dict:
|
|
353
|
+
"""Convert a ngio image metadata to a v04 image metadata.
|
|
354
|
+
|
|
355
|
+
Args:
|
|
356
|
+
metadata (NgioImageMeta): The ngio image metadata.
|
|
357
|
+
|
|
358
|
+
Returns:
|
|
359
|
+
dict: The v04 image metadata.
|
|
360
|
+
"""
|
|
361
|
+
v04_muliscale = _ngio_to_v04_multiscale(
|
|
362
|
+
name=metadata.name, datasets=metadata.datasets
|
|
363
|
+
)
|
|
364
|
+
v04_omero = _ngio_to_v04_omero(metadata._channels_meta)
|
|
365
|
+
|
|
366
|
+
v04_image = ImageAttrsV04(multiscales=[v04_muliscale], omero=v04_omero)
|
|
367
|
+
return v04_image.model_dump(exclude_none=True, by_alias=True)
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
def ngio_to_v04_label_meta(metadata: NgioLabelMeta) -> dict:
|
|
371
|
+
"""Convert a ngio image metadata to a v04 image metadata.
|
|
372
|
+
|
|
373
|
+
Args:
|
|
374
|
+
metadata (NgioImageMeta): The ngio image metadata.
|
|
375
|
+
|
|
376
|
+
Returns:
|
|
377
|
+
dict: The v04 image metadata.
|
|
378
|
+
"""
|
|
379
|
+
v04_muliscale = _ngio_to_v04_multiscale(
|
|
380
|
+
name=metadata.name, datasets=metadata.datasets
|
|
381
|
+
)
|
|
382
|
+
labels_meta = {
|
|
383
|
+
"multiscales": [v04_muliscale],
|
|
384
|
+
"image-label": metadata.image_label.model_dump(),
|
|
385
|
+
}
|
|
386
|
+
v04_label = ImageLabelAttrsV04(**labels_meta)
|
|
387
|
+
return v04_label.model_dump(exclude_none=True, by_alias=True)
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
def v04_to_ngio_labels_group_meta(
|
|
391
|
+
metadata: dict,
|
|
392
|
+
) -> NgioLabelsGroupMeta:
|
|
393
|
+
"""Convert a v04 label group metadata to a ngio label group metadata.
|
|
394
|
+
|
|
395
|
+
Args:
|
|
396
|
+
metadata (dict): The v04 label group metadata.
|
|
397
|
+
|
|
398
|
+
Returns:
|
|
399
|
+
NgioLabelGroupMeta: The ngio label group metadata.
|
|
400
|
+
"""
|
|
401
|
+
v04_label_group = LabelsAttrsV04(**metadata).model_dump()
|
|
402
|
+
labels = v04_label_group.get("labels", [])
|
|
403
|
+
return NgioLabelsGroupMeta(labels=labels, version="0.4")
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
def v04_to_ngio_well_meta(
|
|
407
|
+
metadata: dict,
|
|
408
|
+
) -> NgioWellMeta:
|
|
409
|
+
"""Convert a v04 well metadata to a ngio well metadata.
|
|
410
|
+
|
|
411
|
+
Args:
|
|
412
|
+
metadata (dict): The v04 well metadata.
|
|
413
|
+
|
|
414
|
+
Returns:
|
|
415
|
+
NgioWellMeta: The ngio well metadata.
|
|
416
|
+
"""
|
|
417
|
+
v04_well = WellAttrsV04(**metadata).well.model_dump()
|
|
418
|
+
images = v04_well.get("images", [])
|
|
419
|
+
return NgioWellMeta(images=images, version="0.4")
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
def v04_to_ngio_plate_meta(
|
|
423
|
+
metadata: dict,
|
|
424
|
+
) -> NgioPlateMeta:
|
|
425
|
+
"""Convert a v04 plate metadata to a ngio plate metadata.
|
|
426
|
+
|
|
427
|
+
Args:
|
|
428
|
+
metadata (dict): The v04 plate metadata.
|
|
429
|
+
|
|
430
|
+
Returns:
|
|
431
|
+
NgioPlateMeta: The ngio plate metadata.
|
|
432
|
+
"""
|
|
433
|
+
v04_plate = HCSAttrsV04(**metadata).plate.model_dump()
|
|
434
|
+
return NgioPlateMeta(plate=v04_plate, version="0.4") # type: ignore
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
def ngio_to_v04_well_meta(metadata: NgioWellMeta) -> dict:
|
|
438
|
+
"""Convert a ngio well metadata to a v04 well metadata.
|
|
439
|
+
|
|
440
|
+
Args:
|
|
441
|
+
metadata (NgioWellMeta): The ngio well metadata.
|
|
442
|
+
|
|
443
|
+
Returns:
|
|
444
|
+
dict: The v04 well metadata.
|
|
445
|
+
"""
|
|
446
|
+
v04_well = WellAttrsV04(well=metadata.model_dump()) # type: ignore
|
|
447
|
+
return v04_well.model_dump(exclude_none=True, by_alias=True)
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
def ngio_to_v04_plate_meta(metadata: NgioPlateMeta) -> dict:
|
|
451
|
+
"""Convert a ngio plate metadata to a v04 plate metadata.
|
|
452
|
+
|
|
453
|
+
Args:
|
|
454
|
+
metadata (NgioPlateMeta): The ngio plate metadata.
|
|
455
|
+
|
|
456
|
+
Returns:
|
|
457
|
+
dict: The v04 plate metadata.
|
|
458
|
+
"""
|
|
459
|
+
v04_plate = HCSAttrsV04(**metadata.model_dump())
|
|
460
|
+
return v04_plate.model_dump(exclude_none=True, by_alias=True)
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
def ngio_to_v04_labels_group_meta(metadata: NgioLabelsGroupMeta) -> dict:
|
|
464
|
+
"""Convert a ngio label group metadata to a v04 label group metadata.
|
|
465
|
+
|
|
466
|
+
Args:
|
|
467
|
+
metadata (NgioLabelsGroupMeta): The ngio label group metadata.
|
|
468
|
+
|
|
469
|
+
Returns:
|
|
470
|
+
dict: The v04 label group metadata.
|
|
471
|
+
"""
|
|
472
|
+
v04_label_group = LabelsAttrsV04(labels=metadata.labels)
|
|
473
|
+
return v04_label_group.model_dump(exclude_none=True, by_alias=True)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""Utility to read/write OME-Zarr metadata v0.4."""
|
|
2
|
+
|
|
3
|
+
from ngio.ome_zarr_meta.v05._v05_spec import (
|
|
4
|
+
ngio_to_v05_image_meta,
|
|
5
|
+
ngio_to_v05_label_meta,
|
|
6
|
+
ngio_to_v05_labels_group_meta,
|
|
7
|
+
ngio_to_v05_plate_meta,
|
|
8
|
+
ngio_to_v05_well_meta,
|
|
9
|
+
v05_to_ngio_image_meta,
|
|
10
|
+
v05_to_ngio_label_meta,
|
|
11
|
+
v05_to_ngio_labels_group_meta,
|
|
12
|
+
v05_to_ngio_plate_meta,
|
|
13
|
+
v05_to_ngio_well_meta,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
"ngio_to_v05_image_meta",
|
|
18
|
+
"ngio_to_v05_label_meta",
|
|
19
|
+
"ngio_to_v05_labels_group_meta",
|
|
20
|
+
"ngio_to_v05_plate_meta",
|
|
21
|
+
"ngio_to_v05_well_meta",
|
|
22
|
+
"v05_to_ngio_image_meta",
|
|
23
|
+
"v05_to_ngio_label_meta",
|
|
24
|
+
"v05_to_ngio_labels_group_meta",
|
|
25
|
+
"v05_to_ngio_plate_meta",
|
|
26
|
+
"v05_to_ngio_well_meta",
|
|
27
|
+
]
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from typing import Annotated
|
|
2
|
+
|
|
3
|
+
from ome_zarr_models.v05.well import WellAttrs as WellAttrs05
|
|
4
|
+
from ome_zarr_models.v05.well_types import WellImage as WellImage05
|
|
5
|
+
from ome_zarr_models.v05.well_types import WellMeta as WellMeta05
|
|
6
|
+
from pydantic import SkipValidation
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class CustomWellImage(WellImage05):
|
|
10
|
+
path: Annotated[str, SkipValidation]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class CustomWellMeta(WellMeta05):
|
|
14
|
+
images: list[CustomWellImage] # type: ignore[valid-type]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class CustomWellAttrs(WellAttrs05):
|
|
18
|
+
well: CustomWellMeta # type: ignore[valid-type]
|