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.
Files changed (106) hide show
  1. ngio/__init__.py +40 -12
  2. ngio/common/__init__.py +16 -32
  3. ngio/common/_dimensions.py +270 -48
  4. ngio/common/_masking_roi.py +153 -0
  5. ngio/common/_pyramid.py +267 -73
  6. ngio/common/_roi.py +290 -66
  7. ngio/common/_synt_images_utils.py +101 -0
  8. ngio/common/_zoom.py +54 -22
  9. ngio/experimental/__init__.py +5 -0
  10. ngio/experimental/iterators/__init__.py +15 -0
  11. ngio/experimental/iterators/_abstract_iterator.py +390 -0
  12. ngio/experimental/iterators/_feature.py +189 -0
  13. ngio/experimental/iterators/_image_processing.py +130 -0
  14. ngio/experimental/iterators/_mappers.py +48 -0
  15. ngio/experimental/iterators/_rois_utils.py +126 -0
  16. ngio/experimental/iterators/_segmentation.py +235 -0
  17. ngio/hcs/__init__.py +17 -58
  18. ngio/hcs/_plate.py +1354 -0
  19. ngio/images/__init__.py +30 -9
  20. ngio/images/_abstract_image.py +968 -0
  21. ngio/images/_create_synt_container.py +132 -0
  22. ngio/images/_create_utils.py +423 -0
  23. ngio/images/_image.py +926 -0
  24. ngio/images/_label.py +417 -0
  25. ngio/images/_masked_image.py +531 -0
  26. ngio/images/_ome_zarr_container.py +1235 -0
  27. ngio/images/_table_ops.py +471 -0
  28. ngio/io_pipes/__init__.py +75 -0
  29. ngio/io_pipes/_io_pipes.py +361 -0
  30. ngio/io_pipes/_io_pipes_masked.py +488 -0
  31. ngio/io_pipes/_io_pipes_roi.py +146 -0
  32. ngio/io_pipes/_io_pipes_types.py +56 -0
  33. ngio/io_pipes/_match_shape.py +377 -0
  34. ngio/io_pipes/_ops_axes.py +344 -0
  35. ngio/io_pipes/_ops_slices.py +411 -0
  36. ngio/io_pipes/_ops_slices_utils.py +199 -0
  37. ngio/io_pipes/_ops_transforms.py +104 -0
  38. ngio/io_pipes/_zoom_transform.py +180 -0
  39. ngio/ome_zarr_meta/__init__.py +39 -15
  40. ngio/ome_zarr_meta/_meta_handlers.py +490 -96
  41. ngio/ome_zarr_meta/ngio_specs/__init__.py +24 -10
  42. ngio/ome_zarr_meta/ngio_specs/_axes.py +268 -234
  43. ngio/ome_zarr_meta/ngio_specs/_channels.py +125 -41
  44. ngio/ome_zarr_meta/ngio_specs/_dataset.py +42 -87
  45. ngio/ome_zarr_meta/ngio_specs/_ngio_hcs.py +536 -2
  46. ngio/ome_zarr_meta/ngio_specs/_ngio_image.py +202 -198
  47. ngio/ome_zarr_meta/ngio_specs/_pixel_size.py +72 -34
  48. ngio/ome_zarr_meta/v04/__init__.py +21 -5
  49. ngio/ome_zarr_meta/v04/_custom_models.py +18 -0
  50. ngio/ome_zarr_meta/v04/{_v04_spec_utils.py → _v04_spec.py} +151 -90
  51. ngio/ome_zarr_meta/v05/__init__.py +27 -0
  52. ngio/ome_zarr_meta/v05/_custom_models.py +18 -0
  53. ngio/ome_zarr_meta/v05/_v05_spec.py +511 -0
  54. ngio/resources/20200812-CardiomyocyteDifferentiation14-Cycle1_B03/mask.png +0 -0
  55. ngio/resources/20200812-CardiomyocyteDifferentiation14-Cycle1_B03/nuclei.png +0 -0
  56. ngio/resources/20200812-CardiomyocyteDifferentiation14-Cycle1_B03/raw.jpg +0 -0
  57. ngio/resources/__init__.py +55 -0
  58. ngio/resources/resource_model.py +36 -0
  59. ngio/tables/__init__.py +20 -4
  60. ngio/tables/_abstract_table.py +270 -0
  61. ngio/tables/_tables_container.py +449 -0
  62. ngio/tables/backends/__init__.py +50 -1
  63. ngio/tables/backends/_abstract_backend.py +200 -31
  64. ngio/tables/backends/_anndata.py +139 -0
  65. ngio/tables/backends/_anndata_utils.py +10 -114
  66. ngio/tables/backends/_csv.py +19 -0
  67. ngio/tables/backends/_json.py +92 -0
  68. ngio/tables/backends/_parquet.py +19 -0
  69. ngio/tables/backends/_py_arrow_backends.py +222 -0
  70. ngio/tables/backends/_table_backends.py +162 -38
  71. ngio/tables/backends/_utils.py +608 -0
  72. ngio/tables/v1/__init__.py +19 -4
  73. ngio/tables/v1/_condition_table.py +71 -0
  74. ngio/tables/v1/_feature_table.py +79 -115
  75. ngio/tables/v1/_generic_table.py +21 -90
  76. ngio/tables/v1/_roi_table.py +486 -137
  77. ngio/transforms/__init__.py +5 -0
  78. ngio/transforms/_zoom.py +19 -0
  79. ngio/utils/__init__.py +16 -14
  80. ngio/utils/_cache.py +48 -0
  81. ngio/utils/_datasets.py +121 -13
  82. ngio/utils/_fractal_fsspec_store.py +42 -0
  83. ngio/utils/_zarr_utils.py +374 -218
  84. ngio-0.5.0b4.dist-info/METADATA +147 -0
  85. ngio-0.5.0b4.dist-info/RECORD +88 -0
  86. {ngio-0.2.0a2.dist-info → ngio-0.5.0b4.dist-info}/WHEEL +1 -1
  87. ngio/common/_array_pipe.py +0 -160
  88. ngio/common/_axes_transforms.py +0 -63
  89. ngio/common/_common_types.py +0 -5
  90. ngio/common/_slicer.py +0 -97
  91. ngio/images/abstract_image.py +0 -240
  92. ngio/images/create.py +0 -251
  93. ngio/images/image.py +0 -389
  94. ngio/images/label.py +0 -236
  95. ngio/images/omezarr_container.py +0 -535
  96. ngio/ome_zarr_meta/_generic_handlers.py +0 -320
  97. ngio/ome_zarr_meta/v04/_meta_handlers.py +0 -54
  98. ngio/tables/_validators.py +0 -192
  99. ngio/tables/backends/_anndata_v1.py +0 -75
  100. ngio/tables/backends/_json_v1.py +0 -56
  101. ngio/tables/tables_container.py +0 -300
  102. ngio/tables/v1/_masking_roi_table.py +0 -175
  103. ngio/utils/_logger.py +0 -29
  104. ngio-0.2.0a2.dist-info/METADATA +0 -95
  105. ngio-0.2.0a2.dist-info/RECORD +0 -53
  106. {ngio-0.2.0a2.dist-info → ngio-0.5.0b4.dist-info}/licenses/LICENSE +0 -0
@@ -1,11 +1,27 @@
1
1
  """Utility to read/write OME-Zarr metadata v0.4."""
2
2
 
3
- from ngio.ome_zarr_meta.v04._meta_handlers import (
4
- V04ImageMetaHandler,
5
- V04LabelMetaHandler,
3
+ from ngio.ome_zarr_meta.v04._v04_spec import (
4
+ ngio_to_v04_image_meta,
5
+ ngio_to_v04_label_meta,
6
+ ngio_to_v04_labels_group_meta,
7
+ ngio_to_v04_plate_meta,
8
+ ngio_to_v04_well_meta,
9
+ v04_to_ngio_image_meta,
10
+ v04_to_ngio_label_meta,
11
+ v04_to_ngio_labels_group_meta,
12
+ v04_to_ngio_plate_meta,
13
+ v04_to_ngio_well_meta,
6
14
  )
7
15
 
8
16
  __all__ = [
9
- "V04ImageMetaHandler",
10
- "V04LabelMetaHandler",
17
+ "ngio_to_v04_image_meta",
18
+ "ngio_to_v04_label_meta",
19
+ "ngio_to_v04_labels_group_meta",
20
+ "ngio_to_v04_plate_meta",
21
+ "ngio_to_v04_well_meta",
22
+ "v04_to_ngio_image_meta",
23
+ "v04_to_ngio_label_meta",
24
+ "v04_to_ngio_labels_group_meta",
25
+ "v04_to_ngio_plate_meta",
26
+ "v04_to_ngio_well_meta",
11
27
  ]
@@ -0,0 +1,18 @@
1
+ from typing import Annotated
2
+
3
+ from ome_zarr_models.v04.well import WellAttrs as WellAttrs04
4
+ from ome_zarr_models.v04.well_types import WellImage as WellImage04
5
+ from ome_zarr_models.v04.well_types import WellMeta as WellMeta04
6
+ from pydantic import SkipValidation
7
+
8
+
9
+ class CustomWellImage(WellImage04):
10
+ path: Annotated[str, SkipValidation]
11
+
12
+
13
+ class CustomWellMeta(WellMeta04):
14
+ images: list[CustomWellImage] # type: ignore[valid-type]
15
+
16
+
17
+ class CustomWellAttrs(WellAttrs04):
18
+ well: CustomWellMeta # type: ignore[valid-type]
@@ -9,22 +9,24 @@ For Images and Labels implements the following functionalities:
9
9
  - A function to convert a ngio image metadata to a v04 image metadata.
10
10
  """
11
11
 
12
- from ome_zarr_models.common.multiscales import ValidTransform as ValidTransformV04
13
12
  from ome_zarr_models.v04.axes import Axis as AxisV04
14
13
  from ome_zarr_models.v04.coordinate_transformations import VectorScale as VectorScaleV04
15
14
  from ome_zarr_models.v04.coordinate_transformations import (
16
15
  VectorTranslation as VectorTranslationV04,
17
16
  )
17
+ from ome_zarr_models.v04.hcs import HCSAttrs as HCSAttrsV04
18
18
  from ome_zarr_models.v04.image import ImageAttrs as ImageAttrsV04
19
- from ome_zarr_models.v04.image_label import ImageLabelAttrs as LabelAttrsV04
19
+ from ome_zarr_models.v04.image_label import ImageLabelAttrs as ImageLabelAttrsV04
20
+ from ome_zarr_models.v04.labels import LabelsAttrs as LabelsAttrsV04
20
21
  from ome_zarr_models.v04.multiscales import Dataset as DatasetV04
21
22
  from ome_zarr_models.v04.multiscales import Multiscale as MultiscaleV04
23
+ from ome_zarr_models.v04.multiscales import ValidTransform as ValidTransformV04
22
24
  from ome_zarr_models.v04.omero import Channel as ChannelV04
23
25
  from ome_zarr_models.v04.omero import Omero as OmeroV04
24
26
  from ome_zarr_models.v04.omero import Window as WindowV04
25
- from pydantic import ValidationError
26
27
 
27
28
  from ngio.ome_zarr_meta.ngio_specs import (
29
+ AxesHandler,
28
30
  AxesSetup,
29
31
  Axis,
30
32
  AxisType,
@@ -35,40 +37,12 @@ from ngio.ome_zarr_meta.ngio_specs import (
35
37
  ImageLabelSource,
36
38
  NgioImageMeta,
37
39
  NgioLabelMeta,
40
+ NgioLabelsGroupMeta,
41
+ NgioPlateMeta,
42
+ NgioWellMeta,
38
43
  default_channel_name,
39
44
  )
40
- from ngio.ome_zarr_meta.ngio_specs._ngio_image import NgffVersion
41
-
42
-
43
- def _is_v04_image_meta(metadata: dict) -> ImageAttrsV04 | ValidationError:
44
- """Check if the metadata is a valid OME-Zarr v04 metadata.
45
-
46
- Args:
47
- metadata (dict): The metadata to check.
48
-
49
- Returns:
50
- bool: True if the metadata is a valid OME-Zarr v04 metadata, False otherwise.
51
- """
52
- try:
53
- return ImageAttrsV04(**metadata)
54
- except ValidationError as e:
55
- return e
56
-
57
-
58
- def _is_v04_label_meta(metadata: dict) -> LabelAttrsV04 | ValidationError:
59
- """Check if the metadata is a valid OME-Zarr v04 metadata.
60
-
61
- Args:
62
- metadata (dict): The metadata to check.
63
-
64
- Returns:
65
- bool: True if the metadata is a valid OME-Zarr v04 metadata, False otherwise.
66
- """
67
- try:
68
- return LabelAttrsV04(**metadata)
69
- except ValidationError as e:
70
- return e
71
- raise RuntimeError("Unreachable code")
45
+ from ngio.ome_zarr_meta.v04._custom_models import CustomWellAttrs as WellAttrsV04
72
46
 
73
47
 
74
48
  def _v04_omero_to_channels(v04_omero: OmeroV04 | None) -> ChannelsMeta | None:
@@ -157,34 +131,38 @@ def _v04_to_ngio_datasets(
157
131
  v04_multiscale.coordinateTransformations, global_scale, global_translation
158
132
  )
159
133
 
160
- for v04_dataset in v04_multiscale.datasets:
161
- axes = []
162
- for v04_axis in v04_multiscale.axes:
163
- unit = v04_axis.unit
164
- if unit is not None and not isinstance(unit, str):
165
- unit = str(unit)
166
- axes.append(
167
- Axis(
168
- on_disk_name=v04_axis.name,
169
- axis_type=AxisType(v04_axis.type),
170
- # (for some reason the type is a generic JsonValue,
171
- # but it should be a string or None)
172
- unit=v04_axis.unit, # type: ignore
173
- )
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
174
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
+ )
175
155
 
176
- _on_disk_scale, _on_disk_translation = _compute_scale_translation(
156
+ for v04_dataset in v04_multiscale.datasets:
157
+ _scale, _translation = _compute_scale_translation(
177
158
  v04_dataset.coordinateTransformations, global_scale, global_translation
178
159
  )
179
160
  datasets.append(
180
161
  Dataset(
181
162
  path=v04_dataset.path,
182
- on_disk_axes=axes,
183
- on_disk_scale=_on_disk_scale,
184
- on_disk_translation=_on_disk_translation,
185
- axes_setup=axes_setup,
186
- allow_non_canonical_axes=allow_non_canonical_axes,
187
- strict_canonical_order=strict_canonical_order,
163
+ axes_handler=axes_handler,
164
+ scale=_scale,
165
+ translation=_translation,
188
166
  )
189
167
  )
190
168
  return datasets
@@ -195,7 +173,7 @@ def v04_to_ngio_image_meta(
195
173
  axes_setup: AxesSetup | None = None,
196
174
  allow_non_canonical_axes: bool = False,
197
175
  strict_canonical_order: bool = True,
198
- ) -> tuple[bool, NgioImageMeta | ValidationError]:
176
+ ) -> NgioImageMeta:
199
177
  """Convert a v04 image metadata to a ngio image metadata.
200
178
 
201
179
  Args:
@@ -208,9 +186,7 @@ def v04_to_ngio_image_meta(
208
186
  Returns:
209
187
  NgioImageMeta: The ngio image metadata.
210
188
  """
211
- v04_image = _is_v04_image_meta(metadata)
212
- if isinstance(v04_image, ValidationError):
213
- return False, v04_image
189
+ v04_image = ImageAttrsV04(**metadata)
214
190
 
215
191
  if len(v04_image.multiscales) > 1:
216
192
  raise NotImplementedError(
@@ -231,7 +207,7 @@ def v04_to_ngio_image_meta(
231
207
  name = v04_muliscale.name
232
208
  if name is not None and not isinstance(name, str):
233
209
  name = str(name)
234
- return True, NgioImageMeta(
210
+ return NgioImageMeta(
235
211
  version="0.4",
236
212
  name=name,
237
213
  datasets=datasets,
@@ -244,7 +220,7 @@ def v04_to_ngio_label_meta(
244
220
  axes_setup: AxesSetup | None = None,
245
221
  allow_non_canonical_axes: bool = False,
246
222
  strict_canonical_order: bool = True,
247
- ) -> tuple[bool, NgioLabelMeta | ValidationError]:
223
+ ) -> NgioLabelMeta:
248
224
  """Convert a v04 image metadata to a ngio image metadata.
249
225
 
250
226
  Args:
@@ -257,9 +233,7 @@ def v04_to_ngio_label_meta(
257
233
  Returns:
258
234
  NgioImageMeta: The ngio image metadata.
259
235
  """
260
- v04_label = _is_v04_label_meta(metadata)
261
- if isinstance(v04_label, ValidationError):
262
- return False, v04_label
236
+ v04_label = ImageLabelAttrsV04(**metadata)
263
237
 
264
238
  if len(v04_label.multiscales) > 1:
265
239
  raise NotImplementedError(
@@ -286,14 +260,14 @@ def v04_to_ngio_label_meta(
286
260
  else:
287
261
  image_label_source = source.image
288
262
  image_label_source = ImageLabelSource(
289
- version=NgffVersion.v04,
263
+ version="0.4",
290
264
  source={"image": image_label_source},
291
265
  )
292
266
  name = v04_muliscale.name
293
267
  if name is not None and not isinstance(name, str):
294
268
  name = str(name)
295
269
 
296
- return True, NgioLabelMeta(
270
+ return NgioLabelMeta(
297
271
  version="0.4",
298
272
  name=name,
299
273
  datasets=datasets,
@@ -301,48 +275,45 @@ def v04_to_ngio_label_meta(
301
275
  )
302
276
 
303
277
 
304
- def _ngio_to_v04_multiscale(datasets: list[Dataset]) -> MultiscaleV04:
278
+ def _ngio_to_v04_multiscale(name: str | None, datasets: list[Dataset]) -> MultiscaleV04:
305
279
  """Convert a ngio multiscale to a v04 multiscale.
306
280
 
307
281
  Args:
282
+ name (str | None): The name of the multiscale.
308
283
  datasets (list[Dataset]): The ngio datasets.
309
284
 
310
285
  Returns:
311
286
  MultiscaleV04: The v04 multiscale.
312
287
  """
313
- ax_mapper = datasets[0].axes_mapper
288
+ ax_mapper = datasets[0].axes_handler
314
289
  v04_axes = []
315
- for axis in ax_mapper.on_disk_axes:
290
+ for axis in ax_mapper.axes:
316
291
  v04_axes.append(
317
292
  AxisV04(
318
- name=axis.on_disk_name,
293
+ name=axis.name,
319
294
  type=axis.axis_type.value if axis.axis_type is not None else None,
320
- unit=axis.unit.value if axis.unit is not None else None,
295
+ unit=axis.unit if axis.unit is not None else None,
321
296
  )
322
297
  )
323
298
 
324
299
  v04_datasets = []
325
300
  for dataset in datasets:
326
- transform = [VectorScaleV04(type="scale", scale=list(dataset._on_disk_scale))]
327
- if sum(dataset._on_disk_translation) > 0:
301
+ transform = [VectorScaleV04(type="scale", scale=list(dataset._scale))]
302
+ if sum(dataset._translation) > 0:
328
303
  transform = (
329
- VectorScaleV04(type="scale", scale=list(dataset._on_disk_scale)),
304
+ VectorScaleV04(type="scale", scale=list(dataset._scale)),
330
305
  VectorTranslationV04(
331
- type="translation", translation=list(dataset._on_disk_translation)
306
+ type="translation", translation=list(dataset._translation)
332
307
  ),
333
308
  )
334
309
  else:
335
- transform = (
336
- VectorScaleV04(type="scale", scale=list(dataset._on_disk_scale)),
337
- )
310
+ transform = (VectorScaleV04(type="scale", scale=list(dataset._scale)),)
338
311
 
339
312
  v04_datasets.append(
340
313
  DatasetV04(path=dataset.path, coordinateTransformations=transform)
341
314
  )
342
315
  return MultiscaleV04(
343
- axes=v04_axes,
344
- datasets=tuple(v04_datasets),
345
- version="0.4",
316
+ axes=v04_axes, datasets=tuple(v04_datasets), version="0.4", name=name
346
317
  )
347
318
 
348
319
 
@@ -387,11 +358,13 @@ def ngio_to_v04_image_meta(metadata: NgioImageMeta) -> dict:
387
358
  Returns:
388
359
  dict: The v04 image metadata.
389
360
  """
390
- v04_muliscale = _ngio_to_v04_multiscale(metadata.datasets)
361
+ v04_muliscale = _ngio_to_v04_multiscale(
362
+ name=metadata.name, datasets=metadata.datasets
363
+ )
391
364
  v04_omero = _ngio_to_v04_omero(metadata._channels_meta)
392
365
 
393
366
  v04_image = ImageAttrsV04(multiscales=[v04_muliscale], omero=v04_omero)
394
- return v04_image.model_dump(exclude_none=True)
367
+ return v04_image.model_dump(exclude_none=True, by_alias=True)
395
368
 
396
369
 
397
370
  def ngio_to_v04_label_meta(metadata: NgioLabelMeta) -> dict:
@@ -403,10 +376,98 @@ def ngio_to_v04_label_meta(metadata: NgioLabelMeta) -> dict:
403
376
  Returns:
404
377
  dict: The v04 image metadata.
405
378
  """
406
- v04_muliscale = _ngio_to_v04_multiscale(metadata.datasets)
407
- v04_label = LabelAttrsV04(
408
- multiscales=[v04_muliscale],
409
- # image_label is aliased as 'imae-label'
410
- image_label=metadata.image_label.model_dump(), # type: ignore
379
+ v04_muliscale = _ngio_to_v04_multiscale(
380
+ name=metadata.name, datasets=metadata.datasets
411
381
  )
412
- return v04_label.model_dump(exclude_none=True)
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]