ngio 0.5.0__py3-none-any.whl → 0.5.0a1__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 (54) hide show
  1. ngio/__init__.py +2 -5
  2. ngio/common/__init__.py +6 -11
  3. ngio/common/_masking_roi.py +54 -34
  4. ngio/common/_pyramid.py +87 -321
  5. ngio/common/_roi.py +330 -258
  6. ngio/experimental/iterators/_feature.py +3 -3
  7. ngio/experimental/iterators/_rois_utils.py +11 -10
  8. ngio/hcs/_plate.py +136 -192
  9. ngio/images/_abstract_image.py +35 -539
  10. ngio/images/_create.py +283 -0
  11. ngio/images/_create_synt_container.py +43 -40
  12. ngio/images/_image.py +251 -517
  13. ngio/images/_label.py +172 -249
  14. ngio/images/_masked_image.py +2 -2
  15. ngio/images/_ome_zarr_container.py +241 -644
  16. ngio/io_pipes/_io_pipes.py +9 -9
  17. ngio/io_pipes/_io_pipes_masked.py +7 -7
  18. ngio/io_pipes/_io_pipes_roi.py +6 -6
  19. ngio/io_pipes/_io_pipes_types.py +3 -3
  20. ngio/io_pipes/_match_shape.py +8 -6
  21. ngio/io_pipes/_ops_slices_utils.py +5 -8
  22. ngio/ome_zarr_meta/__init__.py +18 -29
  23. ngio/ome_zarr_meta/_meta_handlers.py +708 -392
  24. ngio/ome_zarr_meta/ngio_specs/__init__.py +0 -4
  25. ngio/ome_zarr_meta/ngio_specs/_axes.py +51 -152
  26. ngio/ome_zarr_meta/ngio_specs/_dataset.py +22 -13
  27. ngio/ome_zarr_meta/ngio_specs/_ngio_hcs.py +91 -129
  28. ngio/ome_zarr_meta/ngio_specs/_ngio_image.py +68 -57
  29. ngio/ome_zarr_meta/v04/__init__.py +1 -5
  30. ngio/ome_zarr_meta/v04/{_v04_spec.py → _v04_spec_utils.py} +85 -54
  31. ngio/ome_zarr_meta/v05/__init__.py +1 -5
  32. ngio/ome_zarr_meta/v05/{_v05_spec.py → _v05_spec_utils.py} +87 -64
  33. ngio/resources/__init__.py +1 -1
  34. ngio/resources/resource_model.py +1 -1
  35. ngio/tables/_tables_container.py +27 -85
  36. ngio/tables/backends/_anndata.py +8 -58
  37. ngio/tables/backends/_anndata_utils.py +6 -1
  38. ngio/tables/backends/_csv.py +19 -3
  39. ngio/tables/backends/_json.py +13 -10
  40. ngio/tables/backends/_non_zarr_backends.py +196 -0
  41. ngio/tables/backends/_parquet.py +31 -3
  42. ngio/tables/v1/_roi_table.py +27 -44
  43. ngio/utils/__init__.py +12 -8
  44. ngio/utils/_datasets.py +0 -6
  45. ngio/utils/_logger.py +50 -0
  46. ngio/utils/_zarr_utils.py +250 -292
  47. {ngio-0.5.0.dist-info → ngio-0.5.0a1.dist-info}/METADATA +6 -13
  48. ngio-0.5.0a1.dist-info/RECORD +88 -0
  49. {ngio-0.5.0.dist-info → ngio-0.5.0a1.dist-info}/WHEEL +1 -1
  50. ngio/images/_create_utils.py +0 -406
  51. ngio/tables/backends/_py_arrow_backends.py +0 -222
  52. ngio/utils/_cache.py +0 -48
  53. ngio-0.5.0.dist-info/RECORD +0 -88
  54. {ngio-0.5.0.dist-info → ngio-0.5.0a1.dist-info}/licenses/LICENSE +0 -0
@@ -9,9 +9,6 @@ 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.coordinate_transformations import (
13
- ValidTransform as ValidTransformV04,
14
- )
15
12
  from ome_zarr_models.v04.axes import Axis as AxisV04
16
13
  from ome_zarr_models.v04.coordinate_transformations import VectorScale as VectorScaleV04
17
14
  from ome_zarr_models.v04.coordinate_transformations import (
@@ -19,13 +16,14 @@ from ome_zarr_models.v04.coordinate_transformations import (
19
16
  )
20
17
  from ome_zarr_models.v04.hcs import HCSAttrs as HCSAttrsV04
21
18
  from ome_zarr_models.v04.image import ImageAttrs as ImageAttrsV04
22
- from ome_zarr_models.v04.image_label import ImageLabelAttrs as ImageLabelAttrsV04
23
- from ome_zarr_models.v04.labels import LabelsAttrs as LabelsAttrsV04
19
+ from ome_zarr_models.v04.image_label import ImageLabelAttrs as LabelAttrsV04
24
20
  from ome_zarr_models.v04.multiscales import Dataset as DatasetV04
25
21
  from ome_zarr_models.v04.multiscales import Multiscale as MultiscaleV04
22
+ from ome_zarr_models.v04.multiscales import ValidTransform as ValidTransformV04
26
23
  from ome_zarr_models.v04.omero import Channel as ChannelV04
27
24
  from ome_zarr_models.v04.omero import Omero as OmeroV04
28
25
  from ome_zarr_models.v04.omero import Window as WindowV04
26
+ from pydantic import ValidationError
29
27
 
30
28
  from ngio.ome_zarr_meta.ngio_specs import (
31
29
  AxesHandler,
@@ -39,7 +37,6 @@ from ngio.ome_zarr_meta.ngio_specs import (
39
37
  ImageLabelSource,
40
38
  NgioImageMeta,
41
39
  NgioLabelMeta,
42
- NgioLabelsGroupMeta,
43
40
  NgioPlateMeta,
44
41
  NgioWellMeta,
45
42
  default_channel_name,
@@ -47,6 +44,37 @@ from ngio.ome_zarr_meta.ngio_specs import (
47
44
  from ngio.ome_zarr_meta.v04._custom_models import CustomWellAttrs as WellAttrsV04
48
45
 
49
46
 
47
+ def _is_v04_image_meta(metadata: dict) -> ImageAttrsV04 | ValidationError:
48
+ """Check if the metadata is a valid OME-Zarr v04 metadata.
49
+
50
+ Args:
51
+ metadata (dict): The metadata to check.
52
+
53
+ Returns:
54
+ bool: True if the metadata is a valid OME-Zarr v04 metadata, False otherwise.
55
+ """
56
+ try:
57
+ return ImageAttrsV04(**metadata)
58
+ except ValidationError as e:
59
+ return e
60
+
61
+
62
+ def _is_v04_label_meta(metadata: dict) -> LabelAttrsV04 | ValidationError:
63
+ """Check if the metadata is a valid OME-Zarr v04 metadata.
64
+
65
+ Args:
66
+ metadata (dict): The metadata to check.
67
+
68
+ Returns:
69
+ bool: True if the metadata is a valid OME-Zarr v04 metadata, False otherwise.
70
+ """
71
+ try:
72
+ return LabelAttrsV04(**metadata)
73
+ except ValidationError as e:
74
+ return e
75
+ raise RuntimeError("Unreachable code")
76
+
77
+
50
78
  def _v04_omero_to_channels(v04_omero: OmeroV04 | None) -> ChannelsMeta | None:
51
79
  if v04_omero is None:
52
80
  return None
@@ -119,6 +147,8 @@ def _compute_scale_translation(
119
147
  def _v04_to_ngio_datasets(
120
148
  v04_multiscale: MultiscaleV04,
121
149
  axes_setup: AxesSetup,
150
+ allow_non_canonical_axes: bool = False,
151
+ strict_canonical_order: bool = True,
122
152
  ) -> list[Dataset]:
123
153
  """Convert a v04 multiscale to a list of ngio datasets."""
124
154
  datasets = []
@@ -149,6 +179,8 @@ def _v04_to_ngio_datasets(
149
179
  axes_handler = AxesHandler(
150
180
  axes=axes,
151
181
  axes_setup=axes_setup,
182
+ allow_non_canonical_axes=allow_non_canonical_axes,
183
+ strict_canonical_order=strict_canonical_order,
152
184
  )
153
185
 
154
186
  for v04_dataset in v04_multiscale.datasets:
@@ -168,19 +200,25 @@ def _v04_to_ngio_datasets(
168
200
 
169
201
  def v04_to_ngio_image_meta(
170
202
  metadata: dict,
171
- axes_setup: AxesSetup,
172
- ) -> NgioImageMeta:
203
+ axes_setup: AxesSetup | None = None,
204
+ allow_non_canonical_axes: bool = False,
205
+ strict_canonical_order: bool = True,
206
+ ) -> tuple[bool, NgioImageMeta | ValidationError]:
173
207
  """Convert a v04 image metadata to a ngio image metadata.
174
208
 
175
209
  Args:
176
210
  metadata (dict): The v04 image metadata.
177
211
  axes_setup (AxesSetup, optional): The axes setup. This is
178
212
  required to convert image with non-canonical axes names.
213
+ allow_non_canonical_axes (bool, optional): Allow non-canonical axes.
214
+ strict_canonical_order (bool, optional): Strict canonical order.
179
215
 
180
216
  Returns:
181
217
  NgioImageMeta: The ngio image metadata.
182
218
  """
183
- v04_image = ImageAttrsV04(**metadata)
219
+ v04_image = _is_v04_image_meta(metadata)
220
+ if isinstance(v04_image, ValidationError):
221
+ return False, v04_image
184
222
 
185
223
  if len(v04_image.multiscales) > 1:
186
224
  raise NotImplementedError(
@@ -190,15 +228,18 @@ def v04_to_ngio_image_meta(
190
228
  v04_muliscale = v04_image.multiscales[0]
191
229
 
192
230
  channels_meta = _v04_omero_to_channels(v04_image.omero)
231
+ axes_setup = axes_setup if axes_setup is not None else AxesSetup()
193
232
  datasets = _v04_to_ngio_datasets(
194
233
  v04_muliscale,
195
234
  axes_setup=axes_setup,
235
+ allow_non_canonical_axes=allow_non_canonical_axes,
236
+ strict_canonical_order=strict_canonical_order,
196
237
  )
197
238
 
198
239
  name = v04_muliscale.name
199
240
  if name is not None and not isinstance(name, str):
200
241
  name = str(name)
201
- return NgioImageMeta(
242
+ return True, NgioImageMeta(
202
243
  version="0.4",
203
244
  name=name,
204
245
  datasets=datasets,
@@ -208,19 +249,25 @@ def v04_to_ngio_image_meta(
208
249
 
209
250
  def v04_to_ngio_label_meta(
210
251
  metadata: dict,
211
- axes_setup: AxesSetup,
212
- ) -> NgioLabelMeta:
252
+ axes_setup: AxesSetup | None = None,
253
+ allow_non_canonical_axes: bool = False,
254
+ strict_canonical_order: bool = True,
255
+ ) -> tuple[bool, NgioLabelMeta | ValidationError]:
213
256
  """Convert a v04 image metadata to a ngio image metadata.
214
257
 
215
258
  Args:
216
259
  metadata (dict): The v04 image metadata.
217
260
  axes_setup (AxesSetup, optional): The axes setup. This is
218
261
  required to convert image with non-canonical axes names.
262
+ allow_non_canonical_axes (bool, optional): Allow non-canonical axes.
263
+ strict_canonical_order (bool, optional): Strict canonical order.
219
264
 
220
265
  Returns:
221
266
  NgioImageMeta: The ngio image metadata.
222
267
  """
223
- v04_label = ImageLabelAttrsV04(**metadata)
268
+ v04_label = _is_v04_label_meta(metadata)
269
+ if isinstance(v04_label, ValidationError):
270
+ return False, v04_label
224
271
 
225
272
  if len(v04_label.multiscales) > 1:
226
273
  raise NotImplementedError(
@@ -228,9 +275,13 @@ def v04_to_ngio_label_meta(
228
275
  )
229
276
 
230
277
  v04_muliscale = v04_label.multiscales[0]
278
+
279
+ axes_setup = axes_setup if axes_setup is not None else AxesSetup()
231
280
  datasets = _v04_to_ngio_datasets(
232
281
  v04_muliscale,
233
282
  axes_setup=axes_setup,
283
+ allow_non_canonical_axes=allow_non_canonical_axes,
284
+ strict_canonical_order=strict_canonical_order,
234
285
  )
235
286
 
236
287
  source = v04_label.image_label.source
@@ -250,7 +301,7 @@ def v04_to_ngio_label_meta(
250
301
  if name is not None and not isinstance(name, str):
251
302
  name = str(name)
252
303
 
253
- return NgioLabelMeta(
304
+ return True, NgioLabelMeta(
254
305
  version="0.4",
255
306
  name=name,
256
307
  datasets=datasets,
@@ -366,55 +417,48 @@ def ngio_to_v04_label_meta(metadata: NgioLabelMeta) -> dict:
366
417
  "multiscales": [v04_muliscale],
367
418
  "image-label": metadata.image_label.model_dump(),
368
419
  }
369
- v04_label = ImageLabelAttrsV04(**labels_meta)
420
+ v04_label = LabelAttrsV04(**labels_meta)
370
421
  return v04_label.model_dump(exclude_none=True, by_alias=True)
371
422
 
372
423
 
373
- def v04_to_ngio_labels_group_meta(
374
- metadata: dict,
375
- ) -> NgioLabelsGroupMeta:
376
- """Convert a v04 label group metadata to a ngio label group metadata.
377
-
378
- Args:
379
- metadata (dict): The v04 label group metadata.
380
-
381
- Returns:
382
- NgioLabelGroupMeta: The ngio label group metadata.
383
- """
384
- v04_label_group = LabelsAttrsV04(**metadata).model_dump()
385
- labels = v04_label_group.get("labels", [])
386
- return NgioLabelsGroupMeta(labels=labels, version="0.4")
387
-
388
-
389
424
  def v04_to_ngio_well_meta(
390
425
  metadata: dict,
391
- ) -> NgioWellMeta:
426
+ ) -> tuple[bool, NgioWellMeta | ValidationError]:
392
427
  """Convert a v04 well metadata to a ngio well metadata.
393
428
 
394
429
  Args:
395
430
  metadata (dict): The v04 well metadata.
396
431
 
397
432
  Returns:
398
- NgioWellMeta: The ngio well metadata.
433
+ result (bool): True if the conversion was successful, False otherwise.
434
+ ngio_well_meta (NgioWellMeta): The ngio well metadata.
399
435
  """
400
- v04_well = WellAttrsV04(**metadata).well.model_dump()
401
- images = v04_well.get("images", [])
402
- return NgioWellMeta(images=images, version="0.4")
436
+ try:
437
+ v04_well = WellAttrsV04(**metadata)
438
+ except ValidationError as e:
439
+ return False, e
440
+
441
+ return True, NgioWellMeta(**v04_well.model_dump())
403
442
 
404
443
 
405
444
  def v04_to_ngio_plate_meta(
406
445
  metadata: dict,
407
- ) -> NgioPlateMeta:
446
+ ) -> tuple[bool, NgioPlateMeta | ValidationError]:
408
447
  """Convert a v04 plate metadata to a ngio plate metadata.
409
448
 
410
449
  Args:
411
450
  metadata (dict): The v04 plate metadata.
412
451
 
413
452
  Returns:
414
- NgioPlateMeta: The ngio plate metadata.
453
+ result (bool): True if the conversion was successful, False otherwise.
454
+ ngio_plate_meta (NgioPlateMeta): The ngio plate metadata.
415
455
  """
416
- v04_plate = HCSAttrsV04(**metadata).plate.model_dump()
417
- return NgioPlateMeta(plate=v04_plate, version="0.4") # type: ignore
456
+ try:
457
+ v04_plate = HCSAttrsV04(**metadata)
458
+ except ValidationError as e:
459
+ return False, e
460
+
461
+ return True, NgioPlateMeta(**v04_plate.model_dump())
418
462
 
419
463
 
420
464
  def ngio_to_v04_well_meta(metadata: NgioWellMeta) -> dict:
@@ -426,7 +470,7 @@ def ngio_to_v04_well_meta(metadata: NgioWellMeta) -> dict:
426
470
  Returns:
427
471
  dict: The v04 well metadata.
428
472
  """
429
- v04_well = WellAttrsV04(well=metadata.model_dump()) # type: ignore
473
+ v04_well = WellAttrsV04(**metadata.model_dump())
430
474
  return v04_well.model_dump(exclude_none=True, by_alias=True)
431
475
 
432
476
 
@@ -441,16 +485,3 @@ def ngio_to_v04_plate_meta(metadata: NgioPlateMeta) -> dict:
441
485
  """
442
486
  v04_plate = HCSAttrsV04(**metadata.model_dump())
443
487
  return v04_plate.model_dump(exclude_none=True, by_alias=True)
444
-
445
-
446
- def ngio_to_v04_labels_group_meta(metadata: NgioLabelsGroupMeta) -> dict:
447
- """Convert a ngio label group metadata to a v04 label group metadata.
448
-
449
- Args:
450
- metadata (NgioLabelsGroupMeta): The ngio label group metadata.
451
-
452
- Returns:
453
- dict: The v04 label group metadata.
454
- """
455
- v04_label_group = LabelsAttrsV04(labels=metadata.labels)
456
- return v04_label_group.model_dump(exclude_none=True, by_alias=True)
@@ -1,14 +1,12 @@
1
1
  """Utility to read/write OME-Zarr metadata v0.4."""
2
2
 
3
- from ngio.ome_zarr_meta.v05._v05_spec import (
3
+ from ngio.ome_zarr_meta.v05._v05_spec_utils import (
4
4
  ngio_to_v05_image_meta,
5
5
  ngio_to_v05_label_meta,
6
- ngio_to_v05_labels_group_meta,
7
6
  ngio_to_v05_plate_meta,
8
7
  ngio_to_v05_well_meta,
9
8
  v05_to_ngio_image_meta,
10
9
  v05_to_ngio_label_meta,
11
- v05_to_ngio_labels_group_meta,
12
10
  v05_to_ngio_plate_meta,
13
11
  v05_to_ngio_well_meta,
14
12
  )
@@ -16,12 +14,10 @@ from ngio.ome_zarr_meta.v05._v05_spec import (
16
14
  __all__ = [
17
15
  "ngio_to_v05_image_meta",
18
16
  "ngio_to_v05_label_meta",
19
- "ngio_to_v05_labels_group_meta",
20
17
  "ngio_to_v05_plate_meta",
21
18
  "ngio_to_v05_well_meta",
22
19
  "v05_to_ngio_image_meta",
23
20
  "v05_to_ngio_label_meta",
24
- "v05_to_ngio_labels_group_meta",
25
21
  "v05_to_ngio_plate_meta",
26
22
  "v05_to_ngio_well_meta",
27
23
  ]
@@ -9,9 +9,6 @@ For Images and Labels implements the following functionalities:
9
9
  - A function to convert a ngio image metadata to a v05 image metadata.
10
10
  """
11
11
 
12
- from ome_zarr_models.common.coordinate_transformations import (
13
- ValidTransform as ValidTransformV05,
14
- )
15
12
  from ome_zarr_models.common.omero import Channel as ChannelV05
16
13
  from ome_zarr_models.common.omero import Omero as OmeroV05
17
14
  from ome_zarr_models.common.omero import Window as WindowV05
@@ -22,12 +19,11 @@ from ome_zarr_models.v05.coordinate_transformations import (
22
19
  )
23
20
  from ome_zarr_models.v05.hcs import HCSAttrs as HCSAttrsV05
24
21
  from ome_zarr_models.v05.image import ImageAttrs as ImageAttrsV05
25
- from ome_zarr_models.v05.image_label import ImageLabelAttrs as ImageLabelAttrsV05
26
- from ome_zarr_models.v05.labels import Labels as Labels
27
- from ome_zarr_models.v05.labels import LabelsAttrs as LabelsAttrsV05
22
+ from ome_zarr_models.v05.image_label import ImageLabelAttrs as LabelAttrsV05
28
23
  from ome_zarr_models.v05.multiscales import Dataset as DatasetV05
29
24
  from ome_zarr_models.v05.multiscales import Multiscale as MultiscaleV05
30
- from pydantic import BaseModel
25
+ from ome_zarr_models.v05.multiscales import ValidTransform as ValidTransformV05
26
+ from pydantic import BaseModel, ValidationError
31
27
 
32
28
  from ngio.ome_zarr_meta.ngio_specs import (
33
29
  AxesHandler,
@@ -41,7 +37,6 @@ from ngio.ome_zarr_meta.ngio_specs import (
41
37
  ImageLabelSource,
42
38
  NgioImageMeta,
43
39
  NgioLabelMeta,
44
- NgioLabelsGroupMeta,
45
40
  NgioPlateMeta,
46
41
  NgioWellMeta,
47
42
  default_channel_name,
@@ -58,7 +53,37 @@ class ImageV05WithOmero(BaseModel):
58
53
 
59
54
 
60
55
  class ImageLabelV05(BaseModel):
61
- ome: ImageLabelAttrsV05
56
+ ome: LabelAttrsV05
57
+
58
+
59
+ def _is_v05_image_meta(metadata: dict) -> ImageV05WithOmero | ValidationError:
60
+ """Check if the metadata is a valid OME-Zarr v05 metadata.
61
+
62
+ Args:
63
+ metadata (dict): The metadata to check.
64
+
65
+ Returns:
66
+ bool: True if the metadata is a valid OME-Zarr v05 metadata, False otherwise.
67
+ """
68
+ try:
69
+ return ImageV05WithOmero(**metadata)
70
+ except ValidationError as e:
71
+ return e
72
+
73
+
74
+ def _is_v05_label_meta(metadata: dict) -> ImageLabelV05 | ValidationError:
75
+ """Check if the metadata is a valid OME-Zarr v05 metadata.
76
+
77
+ Args:
78
+ metadata (dict): The metadata to check.
79
+
80
+ Returns:
81
+ bool: True if the metadata is a valid OME-Zarr v05 metadata, False otherwise.
82
+ """
83
+ try:
84
+ return ImageLabelV05(**metadata)
85
+ except ValidationError as e:
86
+ return e
62
87
 
63
88
 
64
89
  def _v05_omero_to_channels(v05_omero: OmeroV05 | None) -> ChannelsMeta | None:
@@ -133,6 +158,8 @@ def _compute_scale_translation(
133
158
  def _v05_to_ngio_datasets(
134
159
  v05_multiscale: MultiscaleV05,
135
160
  axes_setup: AxesSetup,
161
+ allow_non_canonical_axes: bool = False,
162
+ strict_canonical_order: bool = True,
136
163
  ) -> list[Dataset]:
137
164
  """Convert a v05 multiscale to a list of ngio datasets."""
138
165
  datasets = []
@@ -163,6 +190,8 @@ def _v05_to_ngio_datasets(
163
190
  axes_handler = AxesHandler(
164
191
  axes=axes,
165
192
  axes_setup=axes_setup,
193
+ allow_non_canonical_axes=allow_non_canonical_axes,
194
+ strict_canonical_order=strict_canonical_order,
166
195
  )
167
196
 
168
197
  for v05_dataset in v05_multiscale.datasets:
@@ -182,19 +211,25 @@ def _v05_to_ngio_datasets(
182
211
 
183
212
  def v05_to_ngio_image_meta(
184
213
  metadata: dict,
185
- axes_setup: AxesSetup,
186
- ) -> NgioImageMeta:
214
+ axes_setup: AxesSetup | None = None,
215
+ allow_non_canonical_axes: bool = False,
216
+ strict_canonical_order: bool = True,
217
+ ) -> tuple[bool, NgioImageMeta | ValidationError]:
187
218
  """Convert a v05 image metadata to a ngio image metadata.
188
219
 
189
220
  Args:
190
221
  metadata (dict): The v05 image metadata.
191
- axes_setup (AxesSetup): The axes setup. This is
222
+ axes_setup (AxesSetup, optional): The axes setup. This is
192
223
  required to convert image with non-canonical axes names.
224
+ allow_non_canonical_axes (bool, optional): Allow non-canonical axes.
225
+ strict_canonical_order (bool, optional): Strict canonical order.
193
226
 
194
227
  Returns:
195
228
  NgioImageMeta: The ngio image metadata.
196
229
  """
197
- v05_image = ImageV05WithOmero(**metadata)
230
+ v05_image = _is_v05_image_meta(metadata)
231
+ if isinstance(v05_image, ValidationError):
232
+ return False, v05_image
198
233
  v05_image = v05_image.ome
199
234
  if len(v05_image.multiscales) > 1:
200
235
  raise NotImplementedError(
@@ -204,15 +239,18 @@ def v05_to_ngio_image_meta(
204
239
  v05_multiscale = v05_image.multiscales[0]
205
240
 
206
241
  channels_meta = _v05_omero_to_channels(v05_image.omero)
242
+ axes_setup = axes_setup if axes_setup is not None else AxesSetup()
207
243
  datasets = _v05_to_ngio_datasets(
208
244
  v05_multiscale,
209
245
  axes_setup=axes_setup,
246
+ allow_non_canonical_axes=allow_non_canonical_axes,
247
+ strict_canonical_order=strict_canonical_order,
210
248
  )
211
249
 
212
250
  name = v05_multiscale.name
213
251
  if name is not None and not isinstance(name, str):
214
252
  name = str(name)
215
- return NgioImageMeta(
253
+ return True, NgioImageMeta(
216
254
  version="0.5",
217
255
  name=name,
218
256
  datasets=datasets,
@@ -222,19 +260,25 @@ def v05_to_ngio_image_meta(
222
260
 
223
261
  def v05_to_ngio_label_meta(
224
262
  metadata: dict,
225
- axes_setup: AxesSetup,
226
- ) -> NgioLabelMeta:
263
+ axes_setup: AxesSetup | None = None,
264
+ allow_non_canonical_axes: bool = False,
265
+ strict_canonical_order: bool = True,
266
+ ) -> tuple[bool, NgioLabelMeta | ValidationError]:
227
267
  """Convert a v05 image metadata to a ngio image metadata.
228
268
 
229
269
  Args:
230
270
  metadata (dict): The v05 image metadata.
231
- axes_setup (AxesSetup): The axes setup. This is
271
+ axes_setup (AxesSetup, optional): The axes setup. This is
232
272
  required to convert image with non-canonical axes names.
273
+ allow_non_canonical_axes (bool, optional): Allow non-canonical axes.
274
+ strict_canonical_order (bool, optional): Strict canonical order.
233
275
 
234
276
  Returns:
235
- NgioLabelMeta: The ngio label metadata.
277
+ NgioImageMeta: The ngio image metadata.
236
278
  """
237
- v05_label = ImageLabelV05(**metadata)
279
+ v05_label = _is_v05_label_meta(metadata)
280
+ if isinstance(v05_label, ValidationError):
281
+ return False, v05_label
238
282
  v05_label = v05_label.ome
239
283
 
240
284
  if len(v05_label.multiscales) > 1:
@@ -244,9 +288,12 @@ def v05_to_ngio_label_meta(
244
288
 
245
289
  v05_multiscale = v05_label.multiscales[0]
246
290
 
291
+ axes_setup = axes_setup if axes_setup is not None else AxesSetup()
247
292
  datasets = _v05_to_ngio_datasets(
248
293
  v05_multiscale,
249
294
  axes_setup=axes_setup,
295
+ allow_non_canonical_axes=allow_non_canonical_axes,
296
+ strict_canonical_order=strict_canonical_order,
250
297
  )
251
298
 
252
299
  if v05_label.image_label is not None:
@@ -269,7 +316,7 @@ def v05_to_ngio_label_meta(
269
316
  if name is not None and not isinstance(name, str):
270
317
  name = str(name)
271
318
 
272
- return NgioLabelMeta(
319
+ return True, NgioLabelMeta(
273
320
  version="0.5",
274
321
  name=name,
275
322
  datasets=datasets,
@@ -388,7 +435,7 @@ def ngio_to_v05_label_meta(metadata: NgioLabelMeta) -> dict:
388
435
  "multiscales": [v05_muliscale],
389
436
  "image-label": metadata.image_label.model_dump(),
390
437
  }
391
- v05_label = ImageLabelAttrsV05(**labels_meta, version="0.5")
438
+ v05_label = LabelAttrsV05(**labels_meta, version="0.5")
392
439
  v05_label = ImageLabelV05(
393
440
  ome=v05_label,
394
441
  )
@@ -405,33 +452,42 @@ class HCSV05(BaseModel):
405
452
 
406
453
  def v05_to_ngio_well_meta(
407
454
  metadata: dict,
408
- ) -> NgioWellMeta:
455
+ ) -> tuple[bool, NgioWellMeta | ValidationError]:
409
456
  """Convert a v05 well metadata to a ngio well metadata.
410
457
 
411
458
  Args:
412
459
  metadata (dict): The v05 well metadata.
413
460
 
414
461
  Returns:
415
- NgioWellMeta: The ngio well metadata.
462
+ result (bool): True if the conversion was successful, False otherwise.
463
+ ngio_well_meta (NgioWellMeta): The ngio well metadata.
416
464
  """
417
- v05_well = WellV05(**metadata).ome.well.model_dump()
418
- images = v05_well.get("images", [])
419
- return NgioWellMeta(images=images, version="0.5")
465
+ try:
466
+ v05_well = WellV05(**metadata)
467
+ except ValidationError as e:
468
+ return False, e
469
+
470
+ return True, NgioWellMeta(**v05_well.ome.model_dump())
420
471
 
421
472
 
422
473
  def v05_to_ngio_plate_meta(
423
474
  metadata: dict,
424
- ) -> NgioPlateMeta:
475
+ ) -> tuple[bool, NgioPlateMeta | ValidationError]:
425
476
  """Convert a v05 plate metadata to a ngio plate metadata.
426
477
 
427
478
  Args:
428
479
  metadata (dict): The v05 plate metadata.
429
480
 
430
481
  Returns:
431
- NgioPlateMeta: The ngio plate metadata.
482
+ result (bool): True if the conversion was successful, False otherwise.
483
+ ngio_plate_meta (NgioPlateMeta): The ngio plate metadata.
432
484
  """
433
- v05_plate = HCSV05(**metadata).ome.plate.model_dump()
434
- return NgioPlateMeta(plate=v05_plate, version="0.5") # type: ignore
485
+ try:
486
+ v05_plate = HCSV05(**metadata)
487
+ except ValidationError as e:
488
+ return False, e
489
+
490
+ return True, NgioPlateMeta(**v05_plate.ome.model_dump())
435
491
 
436
492
 
437
493
  def ngio_to_v05_well_meta(metadata: NgioWellMeta) -> dict:
@@ -443,7 +499,7 @@ def ngio_to_v05_well_meta(metadata: NgioWellMeta) -> dict:
443
499
  Returns:
444
500
  dict: The v05 well metadata.
445
501
  """
446
- v05_well = WellAttrsV05(well=metadata.model_dump()) # type: ignore
502
+ v05_well = WellAttrsV05(**metadata.model_dump())
447
503
  v05_well = WellV05(ome=v05_well)
448
504
  return v05_well.model_dump(exclude_none=True, by_alias=True)
449
505
 
@@ -460,36 +516,3 @@ def ngio_to_v05_plate_meta(metadata: NgioPlateMeta) -> dict:
460
516
  v05_plate = HCSAttrsV05(**metadata.model_dump())
461
517
  v05_plate = HCSV05(ome=v05_plate)
462
518
  return v05_plate.model_dump(exclude_none=True, by_alias=True)
463
-
464
-
465
- class LabelsV05(BaseModel):
466
- ome: LabelsAttrsV05
467
-
468
-
469
- def v05_to_ngio_labels_group_meta(
470
- metadata: dict,
471
- ) -> NgioLabelsGroupMeta:
472
- """Convert a v04 label group metadata to a ngio label group metadata.
473
-
474
- Args:
475
- metadata (dict): The v04 label group metadata.
476
-
477
- Returns:
478
- NgioLabelGroupMeta: The ngio label group metadata.
479
- """
480
- v05_label_group = LabelsV05(**metadata)
481
- return NgioLabelsGroupMeta(labels=v05_label_group.ome.labels, version="0.5")
482
-
483
-
484
- def ngio_to_v05_labels_group_meta(metadata: NgioLabelsGroupMeta) -> dict:
485
- """Convert a ngio label group metadata to a v05 label group metadata.
486
-
487
- Args:
488
- metadata (NgioLabelsGroupMeta): The ngio label group metadata.
489
-
490
- Returns:
491
- dict: The v05 label group metadata.
492
- """
493
- v05_labels_attrs = LabelsAttrsV05(labels=metadata.labels, version="0.5")
494
- v05_labels_group = LabelsV05(ome=v05_labels_attrs)
495
- return v05_labels_group.model_dump(exclude_none=True, by_alias=True)
@@ -31,7 +31,7 @@ _resources = {
31
31
  dtype="uint8",
32
32
  ),
33
33
  ],
34
- pixelsize=0.325,
34
+ xy_pixelsize=0.325,
35
35
  z_spacing=1.0,
36
36
  time_spacing=1.0,
37
37
  name="Cardiomyocyte Differentiation",
@@ -27,7 +27,7 @@ class SampleInfo(BaseModel):
27
27
 
28
28
  img_path: Path
29
29
  labels: list[LabelsInfo] = Field(default_factory=list)
30
- pixelsize: float
30
+ xy_pixelsize: float
31
31
  z_spacing: float = 1.0
32
32
  time_spacing: float = 1.0
33
33
  space_unit: SpaceUnits = DefaultSpaceUnit