ngio 0.2.0a3__py3-none-any.whl → 0.2.0b1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. ngio/__init__.py +4 -4
  2. ngio/common/__init__.py +12 -2
  3. ngio/common/_array_pipe.py +106 -0
  4. ngio/common/_axes_transforms.py +3 -2
  5. ngio/common/_dimensions.py +7 -0
  6. ngio/common/_masking_roi.py +158 -0
  7. ngio/common/_pyramid.py +16 -11
  8. ngio/common/_roi.py +74 -0
  9. ngio/common/_slicer.py +1 -2
  10. ngio/common/_zoom.py +5 -3
  11. ngio/hcs/__init__.py +2 -57
  12. ngio/hcs/plate.py +399 -0
  13. ngio/images/abstract_image.py +97 -28
  14. ngio/images/create.py +48 -29
  15. ngio/images/image.py +99 -46
  16. ngio/images/label.py +109 -92
  17. ngio/images/masked_image.py +259 -0
  18. ngio/images/omezarr_container.py +201 -64
  19. ngio/ome_zarr_meta/__init__.py +25 -13
  20. ngio/ome_zarr_meta/_meta_handlers.py +718 -69
  21. ngio/ome_zarr_meta/ngio_specs/__init__.py +8 -0
  22. ngio/ome_zarr_meta/ngio_specs/_channels.py +11 -0
  23. ngio/ome_zarr_meta/ngio_specs/_ngio_hcs.py +374 -2
  24. ngio/ome_zarr_meta/ngio_specs/_ngio_image.py +169 -119
  25. ngio/ome_zarr_meta/ngio_specs/_pixel_size.py +35 -3
  26. ngio/ome_zarr_meta/v04/__init__.py +17 -5
  27. ngio/ome_zarr_meta/v04/_v04_spec_utils.py +85 -12
  28. ngio/tables/__init__.py +2 -0
  29. ngio/tables/_validators.py +2 -4
  30. ngio/tables/backends/_anndata_utils.py +2 -1
  31. ngio/tables/backends/_anndata_v1.py +2 -1
  32. ngio/tables/backends/_json_v1.py +1 -1
  33. ngio/tables/tables_container.py +12 -2
  34. ngio/tables/v1/__init__.py +1 -2
  35. ngio/tables/v1/_feature_table.py +7 -5
  36. ngio/tables/v1/_generic_table.py +65 -11
  37. ngio/tables/v1/_roi_table.py +145 -27
  38. ngio/utils/_datasets.py +4 -2
  39. ngio/utils/_fractal_fsspec_store.py +3 -2
  40. ngio/utils/_logger.py +3 -1
  41. ngio/utils/_zarr_utils.py +25 -2
  42. {ngio-0.2.0a3.dist-info → ngio-0.2.0b1.dist-info}/METADATA +4 -1
  43. ngio-0.2.0b1.dist-info/RECORD +54 -0
  44. ngio/ome_zarr_meta/_generic_handlers.py +0 -320
  45. ngio/ome_zarr_meta/v04/_meta_handlers.py +0 -54
  46. ngio/tables/v1/_masking_roi_table.py +0 -175
  47. ngio-0.2.0a3.dist-info/RECORD +0 -54
  48. {ngio-0.2.0a3.dist-info → ngio-0.2.0b1.dist-info}/WHEEL +0 -0
  49. {ngio-0.2.0a3.dist-info → ngio-0.2.0b1.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,54 @@
1
+ ngio/__init__.py,sha256=8-5UcDEIPVIM3mk4GqyBJNteQo0WZNOox1-F6UJoHjg,1001
2
+ ngio/common/__init__.py,sha256=4MLD3Xgr6-I6NwGoY7pa5qQfbfEobFCW3KvLybYcgOc,1373
3
+ ngio/common/_array_pipe.py,sha256=TTdSGJp8eFFycfme_gtdSKk9vcu-A--PhpP4qSi7N40,7840
4
+ ngio/common/_axes_transforms.py,sha256=kWU0M5erNmgWBXdu5LNv-tLW3jqkT00MMYX7cz-kyHs,2035
5
+ ngio/common/_common_types.py,sha256=OkAYNSNjZkixL1MI-HPBVuXamheFBr862uJ4PvTxmhk,129
6
+ ngio/common/_dimensions.py,sha256=UV2XulWaROb3Y2f4fv27ZkTIu-MoS53U26aDkrv-_lk,3900
7
+ ngio/common/_masking_roi.py,sha256=WSlFwoLH4Rjh0AJFFNa2FtFNfs5NB0exgzGb3Gy5K0s,4951
8
+ ngio/common/_pyramid.py,sha256=8xTFnrKcldYXSnBqcVtH1E6hzS9_et8NdoPo8zfTCjc,7308
9
+ ngio/common/_roi.py,sha256=PIxiMarPZwIjqcd1P4aUpwZttvaTQscqXOS7xJCxz7Y,5181
10
+ ngio/common/_slicer.py,sha256=AKpwXRncOmF9nhjKYma0C_41WqAgSv860beKGx-aw-0,3075
11
+ ngio/common/_zoom.py,sha256=KsURa5VuixmpbAAY5-6obmuQV8vfiHKZqBxZDXvchpM,5473
12
+ ngio/hcs/__init__.py,sha256=9YNmtHgCKhYSjmAE2-YVg5BycH-5cQGAE9xFrxxWo8c,188
13
+ ngio/hcs/plate.py,sha256=b-EHns-OGQF_RXEa-GDzP2TJFqpRFc0rBKdgf4l7MwU,12409
14
+ ngio/images/__init__.py,sha256=aijqG14eyqVgHtnlcKVNx37FRfT6QvKt8V6bwBpX_r8,526
15
+ ngio/images/abstract_image.py,sha256=zA1LAZNAuBmZwInUhL33NiFLsCtfyEhI-4XPIRQgCIg,8770
16
+ ngio/images/create.py,sha256=wQfoB9pmQkHFFYE3WNbhgQt36XhoTopGcPGcEXTNI-0,9764
17
+ ngio/images/image.py,sha256=BL9TINwYrT2_HdkhCKoRcfy7XqiiwEIVQvHDFkF8ZWc,15246
18
+ ngio/images/label.py,sha256=gvVuRUsrDBk-EpsuUMepC4M5hYPb5yTVvWwozaLM7-g,9333
19
+ ngio/images/masked_image.py,sha256=4YYVqf8OtIp-wWGVGUKMHMTqod4p4F7ZyWrsUIXMjEs,7905
20
+ ngio/images/omezarr_container.py,sha256=80bqjl3Km7lAp0p_eKOpslgCY1UEj-7kM8M67THUZHo,26469
21
+ ngio/ome_zarr_meta/__init__.py,sha256=EfBX9ppb_wliSIcVb4NBDt3dFVldeIJ0h9tY9HELRY4,1075
22
+ ngio/ome_zarr_meta/_meta_handlers.py,sha256=BLvYt5PONYrWkEb2XgEiAXR_OX9rfeX_C0eEqen0jQA,25549
23
+ ngio/ome_zarr_meta/ngio_specs/__init__.py,sha256=ZpghXfbq0r-YJklD7J76BRMTlzEIAJFzneYlsosdyTY,1548
24
+ ngio/ome_zarr_meta/ngio_specs/_axes.py,sha256=zgAE0-2DHzJfqGqBhyjY7y_6qAgDLdV9iuWz-YsHe9Y,16682
25
+ ngio/ome_zarr_meta/ngio_specs/_channels.py,sha256=ufZuYuTO5PJA1vcBrNAcuZCMgIEwF57buPloTHIzB1Q,14082
26
+ ngio/ome_zarr_meta/ngio_specs/_dataset.py,sha256=xT4GY2mdIsm6nAP8bXRj5E9-P6rS-iwzcXT_o3pZajo,4696
27
+ ngio/ome_zarr_meta/ngio_specs/_ngio_hcs.py,sha256=YQlobPYU7vbo9fShHQyCfzLlDUlP-mprAivay6W4-A0,11610
28
+ ngio/ome_zarr_meta/ngio_specs/_ngio_image.py,sha256=6bJNONxf1UbpxF635Dckm7RTG11zY0EWyRNtQAUkBYw,17004
29
+ ngio/ome_zarr_meta/ngio_specs/_pixel_size.py,sha256=QZy94THDBkeLgOtN6o_jF3oXSewRxdM2E7ZTSBTo7RU,3878
30
+ ngio/ome_zarr_meta/v04/__init__.py,sha256=dJRzzxyYc81kf-0Hip_bqvbdManaM8XTdQX2meWyCSs,583
31
+ ngio/ome_zarr_meta/v04/_v04_spec_utils.py,sha256=G4GGarkktjdsIzHUhaoZEL69-r-ZLpLz6y5TDVsN4W0,15939
32
+ ngio/tables/__init__.py,sha256=Mu3P8D-AtAxv9l4vUo-UJPfTYkgvB5A8qpOh3gMWX4E,609
33
+ ngio/tables/_validators.py,sha256=RzF09YrlUSb-xdVlosuU-_BaLswtvhpduHfzLaWu2mY,6468
34
+ ngio/tables/tables_container.py,sha256=FXp-s_zKqbMcBFh4515kbSdxYaFK1ULE2Pf0pzlnpEE,9845
35
+ ngio/tables/backends/__init__.py,sha256=NlOXmZXDA1kOCVONUyo_aqSjdMHmfqk-3xuKBLXpaUM,217
36
+ ngio/tables/backends/_abstract_backend.py,sha256=JlaHqLjDm2uVnXFWxsHMojNeKo3leg6uauzoFMSF5O4,2256
37
+ ngio/tables/backends/_anndata_utils.py,sha256=TnrjOI70tSRl0bYJvVzvMSMojD61GDK3Uo8wS6EOXZg,6816
38
+ ngio/tables/backends/_anndata_v1.py,sha256=hhEwoBybWFDHqajOk_JEazniYmhAlCehOYTtmcYJfyY,2615
39
+ ngio/tables/backends/_json_v1.py,sha256=9ZC0d_tMiiugm-VXDL3sRFfESzSnnY9kAtSxoXYV-dY,1910
40
+ ngio/tables/backends/_table_backends.py,sha256=XXtnZqVDbMqFkbUkHbf9IBNz4teCouLpa5fWgEgVtfg,3269
41
+ ngio/tables/v1/__init__.py,sha256=VtS1RUiPn_jHa__IUsGGzXSYsG0O1V0fpVR6xCOSFHY,314
42
+ ngio/tables/v1/_feature_table.py,sha256=yO1fWUfEM5nTSU6vx4QEwSY3MsgB8zZyr6Ui0fwc16w,5161
43
+ ngio/tables/v1/_generic_table.py,sha256=NcDWa6NI7LQplSVPOn0HG5CjrILTf0ZKZ1i_E-H5LJM,5279
44
+ ngio/tables/v1/_roi_table.py,sha256=GanlVPcmtFn5mzQYQi3-ldDLAdxPdC92NAvtvezp5Ps,10674
45
+ ngio/utils/__init__.py,sha256=r3nuLWgp6-cQlS4ODjYSBrfgdTLkCOVke9jKbn1NpkA,1129
46
+ ngio/utils/_datasets.py,sha256=EdYJHIifpRou4f43dIuiKsdxe4K6FaeS4f1_e_EYrcI,1727
47
+ ngio/utils/_errors.py,sha256=pKQ12LUjQLYE1nUawemA5h7HsgznjaSvV1n2PQU33N0,759
48
+ ngio/utils/_fractal_fsspec_store.py,sha256=7qoGLiLi8JQFh9Ej_z5WNwQQuWrujb0f6p9nj8ocsS8,548
49
+ ngio/utils/_logger.py,sha256=HIuqD_2ShfFGDswBddcouStbKfL0Vz_ah8cAIFGhbS8,888
50
+ ngio/utils/_zarr_utils.py,sha256=r075cNpr-JHZ1PaDHX1KlENIGMvLf-WTTYwpODACWm4,12924
51
+ ngio-0.2.0b1.dist-info/METADATA,sha256=J-tCuj8BXolhGSU57DFUkgm3dvFkyQq9JQy5MrXznTs,4933
52
+ ngio-0.2.0b1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
53
+ ngio-0.2.0b1.dist-info/licenses/LICENSE,sha256=UgN_a1QCeNh9rZWfz-wORQFxE3elQzLWPQaoK6N6fxQ,1502
54
+ ngio-0.2.0b1.dist-info/RECORD,,
@@ -1,320 +0,0 @@
1
- """Base class for handling OME-NGFF metadata in Zarr groups."""
2
-
3
- from typing import Generic, Protocol, TypeVar
4
-
5
- from pydantic import ValidationError
6
-
7
- from ngio.ome_zarr_meta.ngio_specs import AxesSetup, NgioImageMeta, NgioLabelMeta
8
- from ngio.utils import (
9
- NgioValueError,
10
- ZarrGroupHandler,
11
- )
12
-
13
- ConverterError = ValidationError | Exception | None
14
-
15
-
16
- class ImageMetaHandler(Protocol):
17
- """Protocol for OME-Zarr image handlers."""
18
-
19
- def __init__(
20
- self,
21
- group_handler: ZarrGroupHandler,
22
- axes_setup: AxesSetup | None = None,
23
- allow_non_canonical_axes: bool = False,
24
- strict_canonical_order: bool = True,
25
- ):
26
- """Initialize the handler."""
27
- ...
28
-
29
- def safe_load_meta(self) -> NgioImageMeta | ConverterError:
30
- """Load the metadata from the store."""
31
- ...
32
-
33
- @property
34
- def meta(self) -> NgioImageMeta:
35
- """Return the metadata."""
36
- ...
37
-
38
- def write_meta(self, meta: NgioImageMeta) -> None:
39
- """Write the metadata to the store."""
40
- ...
41
-
42
-
43
- class LabelMetaHandler(Protocol):
44
- """Protocol for OME-Zarr label handlers."""
45
-
46
- def __init__(
47
- self,
48
- group_handler: ZarrGroupHandler,
49
- axes_setup: AxesSetup | None = None,
50
- allow_non_canonical_axes: bool = False,
51
- strict_canonical_order: bool = True,
52
- ):
53
- """Initialize the handler."""
54
- ...
55
-
56
- def safe_load_meta(self) -> NgioLabelMeta | ConverterError:
57
- """Load the metadata from the store."""
58
- ...
59
-
60
- @property
61
- def meta(self) -> NgioLabelMeta:
62
- """Return the metadata."""
63
- ...
64
-
65
- def write_meta(self, meta: NgioLabelMeta) -> None:
66
- """Write the metadata to the store."""
67
- ...
68
-
69
-
70
- ###########################################################################
71
- #
72
- # The code below implements a generic class for handling OME-Zarr metadata
73
- # in Zarr groups.
74
- #
75
- ###########################################################################
76
-
77
-
78
- class ImageMetaImporter(Protocol):
79
- @staticmethod
80
- def __call__(
81
- metadata: dict,
82
- axes_setup: AxesSetup | None = None,
83
- allow_non_canonical_axes: bool = False,
84
- strict_canonical_order: bool = True,
85
- ) -> tuple[bool, NgioImageMeta | ConverterError]:
86
- """Convert the metadata to a NgioImageMeta object.
87
-
88
- Args:
89
- metadata (dict): The metadata (typically from a Zarr group .attrs).
90
- axes_setup (AxesSetup, optional): The axes setup.
91
- This is used to map axes with non-canonical names.
92
- allow_non_canonical_axes (bool, optional): Whether to allow non-canonical
93
- axes.
94
- strict_canonical_order (bool, optional): Whether to enforce a strict
95
- canonical order.
96
-
97
- Returns:
98
- tuple[bool, NgioImageMeta | ConverterError]: A tuple with a boolean
99
- indicating whether the conversion was successful and the
100
- NgioImageMeta object or an error.
101
-
102
- """
103
- ...
104
-
105
-
106
- class ImageMetaExporter(Protocol):
107
- def __call__(self, metadata: NgioImageMeta) -> dict: ...
108
-
109
-
110
- class LabelMetaImporter(Protocol):
111
- @staticmethod
112
- def __call__(
113
- metadata: dict,
114
- axes_setup: AxesSetup | None = None,
115
- allow_non_canonical_axes: bool = False,
116
- strict_canonical_order: bool = True,
117
- ) -> tuple[bool, NgioLabelMeta | ConverterError]:
118
- """Convert the metadata to a NgioLabelMeta object.
119
-
120
- Args:
121
- metadata (dict): The metadata (typically from a Zarr group .attrs).
122
- axes_setup (AxesSetup, optional): The axes setup.
123
- This is used to map axes with non-canonical names.
124
- allow_non_canonical_axes (bool, optional): Whether to allow non-canonical
125
- axes.
126
- strict_canonical_order (bool, optional): Whether to enforce a strict
127
- canonical order.
128
-
129
- Returns:
130
- tuple[bool, NgioLabelMeta | ConverterError]: A tuple with a boolean
131
- indicating whether the conversion was successful and the
132
- NgioLabelMeta object or an error.
133
-
134
- """
135
- ...
136
-
137
-
138
- class LabelMetaExporter(Protocol):
139
- def __call__(self, metadata: NgioLabelMeta) -> dict: ...
140
-
141
-
142
- _meta = TypeVar("_meta", NgioImageMeta, NgioLabelMeta)
143
- _meta_importer = TypeVar("_meta_importer", ImageMetaImporter, LabelMetaImporter)
144
- _meta_exporter = TypeVar("_meta_exporter", ImageMetaExporter, LabelMetaExporter)
145
-
146
-
147
- class GenericMetaHandler(Generic[_meta, _meta_importer, _meta_exporter]):
148
- """Generic class for handling OME-Zarr metadata in Zarr groups."""
149
-
150
- def __init__(
151
- self,
152
- meta_importer: _meta_importer,
153
- meta_exporter: _meta_exporter,
154
- group_handler: ZarrGroupHandler,
155
- axes_setup: AxesSetup | None = None,
156
- allow_non_canonical_axes: bool = False,
157
- strict_canonical_order: bool = True,
158
- ):
159
- """Initialize the handler.
160
-
161
- Args:
162
- meta_importer (MetaImporter): The metadata importer.
163
- meta_exporter (MetaExporter): The metadata exporter.
164
- group_handler (ZarrGroupHandler): The Zarr group handler.
165
- axes_setup (AxesSetup, optional): The axes setup.
166
- This is used to map axes with non-canonical names.
167
- allow_non_canonical_axes (bool, optional): Whether to allow non-canonical
168
- axes.
169
- strict_canonical_order (bool, optional): Whether to enforce a strict
170
- canonical order.
171
- """
172
- self._group_handler = group_handler
173
- self._meta_importer = meta_importer
174
- self._meta_exporter = meta_exporter
175
- self._axes_setup = axes_setup
176
- self._allow_non_canonical_axes = allow_non_canonical_axes
177
- self._strict_canonical_order = strict_canonical_order
178
-
179
- def _load_meta(self, return_error: bool = False):
180
- """Load the metadata from the store."""
181
- attrs = self._group_handler.load_attrs()
182
- is_valid, meta_or_error = self._meta_importer(
183
- metadata=attrs,
184
- axes_setup=self._axes_setup,
185
- allow_non_canonical_axes=self._allow_non_canonical_axes,
186
- strict_canonical_order=self._strict_canonical_order,
187
- )
188
- if is_valid:
189
- return meta_or_error
190
-
191
- if return_error:
192
- return meta_or_error
193
-
194
- raise NgioValueError(f"Could not load metadata: {meta_or_error}")
195
-
196
- def safe_load_meta(self) -> _meta | ConverterError:
197
- """Load the metadata from the store."""
198
- return self._load_meta(return_error=True)
199
-
200
- def _write_meta(self, meta) -> None:
201
- """Write the metadata to the store."""
202
- v04_meta = self._meta_exporter(metadata=meta)
203
- self._group_handler.write_attrs(v04_meta)
204
-
205
- def write_meta(self, meta: _meta) -> None:
206
- """Write the metadata to the store."""
207
- raise NotImplementedError
208
-
209
- @property
210
- def meta(self) -> _meta:
211
- """Return the metadata."""
212
- raise NotImplementedError
213
-
214
-
215
- class BaseImageMetaHandler(
216
- GenericMetaHandler[NgioImageMeta, ImageMetaImporter, ImageMetaExporter]
217
- ):
218
- """Generic class for handling OME-Zarr metadata in Zarr groups."""
219
-
220
- def __init__(
221
- self,
222
- meta_importer: ImageMetaImporter,
223
- meta_exporter: ImageMetaExporter,
224
- group_handler: ZarrGroupHandler,
225
- axes_setup: AxesSetup | None = None,
226
- allow_non_canonical_axes: bool = False,
227
- strict_canonical_order: bool = True,
228
- ):
229
- """Initialize the handler.
230
-
231
- Args:
232
- meta_importer (ImageMetaImporter): The metadata importer.
233
- meta_exporter (ImageMetaExporter): The metadata exporter.
234
- group_handler (ZarrGroupHandler): The Zarr group handler.
235
- axes_setup (AxesSetup, optional): The axes setup.
236
- This is used to map axes with non-canonical names.
237
- allow_non_canonical_axes (bool, optional): Whether to allow non-canonical
238
- axes.
239
- strict_canonical_order (bool, optional): Whether to enforce a strict
240
- canonical order.
241
- """
242
- super().__init__(
243
- meta_importer=meta_importer,
244
- meta_exporter=meta_exporter,
245
- group_handler=group_handler,
246
- axes_setup=axes_setup,
247
- allow_non_canonical_axes=allow_non_canonical_axes,
248
- strict_canonical_order=strict_canonical_order,
249
- )
250
-
251
- def safe_load_meta(
252
- self, return_error: bool = False
253
- ) -> NgioImageMeta | ConverterError:
254
- """Load the metadata from the store."""
255
- return self._load_meta(return_error)
256
-
257
- @property
258
- def meta(self) -> NgioImageMeta:
259
- """Load the metadata from the store."""
260
- meta = self._load_meta()
261
- if isinstance(meta, NgioImageMeta):
262
- return meta
263
- raise NgioValueError(f"Could not load metadata: {meta}")
264
-
265
- def write_meta(self, meta: NgioImageMeta) -> None:
266
- self._write_meta(meta)
267
-
268
-
269
- class BaseLabelMetaHandler(
270
- GenericMetaHandler[NgioLabelMeta, LabelMetaImporter, LabelMetaExporter]
271
- ):
272
- """Generic class for handling OME-Zarr metadata in Zarr groups."""
273
-
274
- def __init__(
275
- self,
276
- meta_importer: LabelMetaImporter,
277
- meta_exporter: LabelMetaExporter,
278
- group_handler: ZarrGroupHandler,
279
- axes_setup: AxesSetup | None = None,
280
- allow_non_canonical_axes: bool = False,
281
- strict_canonical_order: bool = True,
282
- ):
283
- """Initialize the handler.
284
-
285
- Args:
286
- meta_importer (LabelMetaImporter): The metadata importer.
287
- meta_exporter (LabelMetaExporter): The metadata exporter.
288
- group_handler (ZarrGroupHandler): The Zarr group handler.
289
- axes_setup (AxesSetup, optional): The axes setup.
290
- This is used to map axes with non-canonical names.
291
- allow_non_canonical_axes (bool, optional): Whether to allow non-canonical
292
- axes.
293
- strict_canonical_order (bool, optional): Whether to enforce a strict
294
- canonical order.
295
- """
296
- super().__init__(
297
- meta_importer=meta_importer,
298
- meta_exporter=meta_exporter,
299
- group_handler=group_handler,
300
- axes_setup=axes_setup,
301
- allow_non_canonical_axes=allow_non_canonical_axes,
302
- strict_canonical_order=strict_canonical_order,
303
- )
304
-
305
- def safe_load_meta(
306
- self, return_error: bool = False
307
- ) -> NgioLabelMeta | ConverterError:
308
- """Load the metadata from the store."""
309
- return self._load_meta(return_error)
310
-
311
- @property
312
- def meta(self) -> NgioLabelMeta:
313
- """Load the metadata from the store."""
314
- meta = self._load_meta()
315
- if isinstance(meta, NgioLabelMeta):
316
- return meta
317
- raise NgioValueError(f"Could not load metadata: {meta}")
318
-
319
- def write_meta(self, meta: NgioLabelMeta) -> None:
320
- self._write_meta(meta)
@@ -1,54 +0,0 @@
1
- """Concrete implementation of the OME-Zarr metadata handlers for version 0.4."""
2
-
3
- from ngio.ome_zarr_meta._generic_handlers import (
4
- BaseImageMetaHandler,
5
- BaseLabelMetaHandler,
6
- )
7
- from ngio.ome_zarr_meta.ngio_specs import AxesSetup
8
- from ngio.ome_zarr_meta.v04._v04_spec_utils import (
9
- ngio_to_v04_image_meta,
10
- ngio_to_v04_label_meta,
11
- v04_to_ngio_image_meta,
12
- v04_to_ngio_label_meta,
13
- )
14
- from ngio.utils import ZarrGroupHandler
15
-
16
-
17
- class V04ImageMetaHandler(BaseImageMetaHandler):
18
- """Base class for handling OME-Zarr 0.4 metadata."""
19
-
20
- def __init__(
21
- self,
22
- group_handler: ZarrGroupHandler,
23
- axes_setup: AxesSetup | None = None,
24
- allow_non_canonical_axes: bool = False,
25
- strict_canonical_order: bool = True,
26
- ):
27
- super().__init__(
28
- meta_importer=v04_to_ngio_image_meta,
29
- meta_exporter=ngio_to_v04_image_meta,
30
- group_handler=group_handler,
31
- axes_setup=axes_setup,
32
- allow_non_canonical_axes=allow_non_canonical_axes,
33
- strict_canonical_order=strict_canonical_order,
34
- )
35
-
36
-
37
- class V04LabelMetaHandler(BaseLabelMetaHandler):
38
- """Base class for handling OME-Zarr 0.4 metadata."""
39
-
40
- def __init__(
41
- self,
42
- group_handler: ZarrGroupHandler,
43
- axes_setup: AxesSetup | None = None,
44
- allow_non_canonical_axes: bool = False,
45
- strict_canonical_order: bool = True,
46
- ):
47
- super().__init__(
48
- meta_importer=v04_to_ngio_label_meta,
49
- meta_exporter=ngio_to_v04_label_meta,
50
- group_handler=group_handler,
51
- axes_setup=axes_setup,
52
- allow_non_canonical_axes=allow_non_canonical_axes,
53
- strict_canonical_order=strict_canonical_order,
54
- )
@@ -1,175 +0,0 @@
1
- """Implementation of the Masking ROI table class.
2
-
3
- This class follows the roi_table specification at:
4
- https://fractal-analytics-platform.github.io/fractal-tasks-core/tables/
5
- """
6
-
7
- from collections.abc import Iterable
8
- from typing import Literal
9
-
10
- from pydantic import BaseModel
11
-
12
- from ngio.common import WorldCooROI
13
- from ngio.tables._validators import validate_columns
14
- from ngio.tables.backends import ImplementedTableBackends
15
- from ngio.tables.v1._roi_table import (
16
- OPTIONAL_COLUMNS,
17
- REQUIRED_COLUMNS,
18
- _dataframe_to_rois,
19
- _rois_to_dataframe,
20
- )
21
- from ngio.utils import NgioValueError, ZarrGroupHandler
22
-
23
-
24
- class RegionMeta(BaseModel):
25
- """Metadata for the region."""
26
-
27
- path: str
28
-
29
-
30
- class MaskingROITableV1Meta(BaseModel):
31
- """Metadata for the ROI table."""
32
-
33
- fractal_table_version: Literal["1"] = "1"
34
- type: Literal["masking_roi_table"] = "masking_roi_table"
35
- backend: str | None = None
36
- region: RegionMeta | None = None
37
- instance_key: str = "label"
38
-
39
-
40
- class MaskingROITableV1:
41
- """Class to handle fractal ROI tables.
42
-
43
- To know more about the ROI table format, please refer to the
44
- specification at:
45
- https://fractal-analytics-platform.github.io/fractal-tasks-core/tables/
46
- """
47
-
48
- def __init__(
49
- self,
50
- rois: Iterable[WorldCooROI] | None = None,
51
- reference_label: str | None = None,
52
- ) -> None:
53
- """Create a new ROI table."""
54
- if reference_label is None:
55
- self._meta = MaskingROITableV1Meta()
56
- else:
57
- path = f"../labels/{reference_label}"
58
- self._meta = MaskingROITableV1Meta(region=RegionMeta(path=path))
59
- self._table_backend = None
60
-
61
- self._rois = {}
62
- if rois is not None:
63
- self.add(rois)
64
-
65
- @staticmethod
66
- def type() -> Literal["masking_roi_table"]:
67
- """Return the type of the table."""
68
- return "masking_roi_table"
69
-
70
- @staticmethod
71
- def version() -> Literal["1"]:
72
- """Return the version of the fractal table."""
73
- return "1"
74
-
75
- @property
76
- def backend_name(self) -> str | None:
77
- """Return the name of the backend."""
78
- if self._table_backend is None:
79
- return None
80
- return self._table_backend.backend_name()
81
-
82
- @classmethod
83
- def _from_handler(
84
- cls, handler: ZarrGroupHandler, backend_name: str | None = None
85
- ) -> "MaskingROITableV1":
86
- """Create a new ROI table from a Zarr store."""
87
- meta = MaskingROITableV1Meta(**handler.load_attrs())
88
-
89
- if backend_name is None:
90
- backend = ImplementedTableBackends().get_backend(
91
- backend_name=meta.backend,
92
- group_handler=handler,
93
- index_key="label",
94
- index_type="int",
95
- )
96
- else:
97
- backend = ImplementedTableBackends().get_backend(
98
- backend_name=backend_name,
99
- group_handler=handler,
100
- index_key="label",
101
- index_type="int",
102
- )
103
- meta.backend = backend_name
104
-
105
- if not backend.implements_dataframe:
106
- raise NgioValueError(
107
- "The backend does not implement the dataframe protocol."
108
- )
109
-
110
- table = cls()
111
- table._meta = meta
112
- table._table_backend = backend
113
-
114
- dataframe = backend.load_as_dataframe()
115
- dataframe = validate_columns(
116
- dataframe,
117
- required_columns=REQUIRED_COLUMNS,
118
- optional_columns=OPTIONAL_COLUMNS,
119
- )
120
- table._rois = _dataframe_to_rois(dataframe)
121
- return table
122
-
123
- def _set_backend(
124
- self,
125
- handler: ZarrGroupHandler,
126
- backend_name: str | None = None,
127
- ) -> None:
128
- """Set the backend of the table."""
129
- backend = ImplementedTableBackends().get_backend(
130
- backend_name=backend_name,
131
- group_handler=handler,
132
- index_key="label",
133
- index_type="int",
134
- )
135
- self._meta.backend = backend_name
136
- self._table_backend = backend
137
-
138
- def rois(self) -> list[WorldCooROI]:
139
- """List all ROIs in the table."""
140
- return list(self._rois.values())
141
-
142
- def get(self, label: int) -> WorldCooROI:
143
- """Get an ROI from the table."""
144
- _label = str(label)
145
- if _label not in self._rois:
146
- raise KeyError(f"ROI {_label} not found in the table.")
147
- return self._rois[_label]
148
-
149
- def add(self, roi: WorldCooROI | Iterable[WorldCooROI]) -> None:
150
- """Append ROIs to the current table."""
151
- if isinstance(roi, WorldCooROI):
152
- roi = [roi]
153
-
154
- for _roi in roi:
155
- if _roi.name in self._rois:
156
- raise NgioValueError(f"ROI {_roi.name} already exists in the table.")
157
- self._rois[_roi.name] = _roi
158
-
159
- def consolidate(self) -> None:
160
- """Write the current state of the table to the Zarr file."""
161
- if self._table_backend is None:
162
- raise NgioValueError(
163
- "No backend set for the table. "
164
- "Please add the table to a OME-Zarr Image before calling consolidate."
165
- )
166
-
167
- dataframe = _rois_to_dataframe(self._rois, index_key="label")
168
- dataframe = validate_columns(
169
- dataframe,
170
- required_columns=REQUIRED_COLUMNS,
171
- optional_columns=OPTIONAL_COLUMNS,
172
- )
173
- self._table_backend.write_from_dataframe(
174
- dataframe, metadata=self._meta.model_dump(exclude_none=True)
175
- )
@@ -1,54 +0,0 @@
1
- ngio/__init__.py,sha256=8FKJLwwoat9eykBHWa-U93PkzIlkQcde-sRZvtOdDYg,991
2
- ngio/common/__init__.py,sha256=1vyK1i1ueu2BKKI-gaUhEyERVtHOtfKjQuPJOKDbrLA,1140
3
- ngio/common/_array_pipe.py,sha256=DyYjGTy2L74zBtD6S2jGPsFG4zj7KaY39TwPGWsSf8g,4877
4
- ngio/common/_axes_transforms.py,sha256=Dmrta3ZT1IgZAWomdUeTZVje8TBF_oU3RMKBv1r4EvM,1989
5
- ngio/common/_common_types.py,sha256=OkAYNSNjZkixL1MI-HPBVuXamheFBr862uJ4PvTxmhk,129
6
- ngio/common/_dimensions.py,sha256=t3X2wzqCl3-UeocqIpQgKRdcWYagijtKsaHTQz5bfT4,3680
7
- ngio/common/_pyramid.py,sha256=aBxRBjW7y6D-Rj8f9B3dtqIErxk2eq20O58C33NBU0Q,7231
8
- ngio/common/_roi.py,sha256=q7HZg2lPbnJ6flKRgK9e4nfOIgkGpDjDcdz-tE8F0Ys,2869
9
- ngio/common/_slicer.py,sha256=Qk7XXmd4W9T3w55LvFTjAyloyIcS9tt9NTXiDZNwOx8,3076
10
- ngio/common/_zoom.py,sha256=z2UjgotoDw7pvpeZVrxiGx4PXx65nk1vwQH3osTFACI,5422
11
- ngio/hcs/__init__.py,sha256=ugnRl22hM9dic5XRsqQr-HCyyyY1qXTqYOAOzyOZm4M,1624
12
- ngio/images/__init__.py,sha256=aijqG14eyqVgHtnlcKVNx37FRfT6QvKt8V6bwBpX_r8,526
13
- ngio/images/abstract_image.py,sha256=n4akBHWQul7vmo4OlYtKWZwpsYl8IYg82AThJrvDrxc,7113
14
- ngio/images/create.py,sha256=DMyiNVmj3uaJmJQqsL9ftzZNvXxeqgZ0-Pjo63WqWoM,8991
15
- ngio/images/image.py,sha256=zdrOVFlalUMdBwQTzDY6gy-BejttBHHkjJd2oOeEWLE,13101
16
- ngio/images/label.py,sha256=6DgliUcTUNUXNIDRGF7lfCp_eyQ2aCys6l-bnHQeAs8,8558
17
- ngio/images/omezarr_container.py,sha256=Et9FFJmgyqVm7hZsTPB5xBLRsGlGyL65tXdUs2Z4dE8,20695
18
- ngio/ome_zarr_meta/__init__.py,sha256=9kYdyuCc3ouQCLDyUCB_lCVXUJ69Ls0fYwtodk3GtYI,798
19
- ngio/ome_zarr_meta/_generic_handlers.py,sha256=4zRm3P1CRKgUQgD5Z2C9j8VVv659DZIifrmzkQ7o31I,10987
20
- ngio/ome_zarr_meta/_meta_handlers.py,sha256=b6r1zX3SBBTKoQdKfEqvJaSnTOen5t1EPO3rh0I9VH4,4925
21
- ngio/ome_zarr_meta/ngio_specs/__init__.py,sha256=S2bNEhqrUhp2muDCCiVik3E6HrbaG91Q9mfT9EXnWNs,1370
22
- ngio/ome_zarr_meta/ngio_specs/_axes.py,sha256=zgAE0-2DHzJfqGqBhyjY7y_6qAgDLdV9iuWz-YsHe9Y,16682
23
- ngio/ome_zarr_meta/ngio_specs/_channels.py,sha256=KLQAo7eerBXa5NN3-QWSFxeAfM_bvXXaxFjFNM6OMoA,13762
24
- ngio/ome_zarr_meta/ngio_specs/_dataset.py,sha256=xT4GY2mdIsm6nAP8bXRj5E9-P6rS-iwzcXT_o3pZajo,4696
25
- ngio/ome_zarr_meta/ngio_specs/_ngio_hcs.py,sha256=Gk29MJ4Vn4TLFK4M7X_33BumCLiZWRuXtSeLX6H56s4,115
26
- ngio/ome_zarr_meta/ngio_specs/_ngio_image.py,sha256=Bf2DyGuVmFqA4zQROYpjGxAcquXkGyztPkHuHh7586Y,14966
27
- ngio/ome_zarr_meta/ngio_specs/_pixel_size.py,sha256=Ny4F0Wa7uVCKdDQhvFJPCQFUEtKP_DpwId8vdVxkVyQ,2777
28
- ngio/ome_zarr_meta/v04/__init__.py,sha256=0sb_CaJNgC1AOYeR6LDB91oUmSk6edJyQTTo3Lnh5Y4,226
29
- ngio/ome_zarr_meta/v04/_meta_handlers.py,sha256=aRvuq9ofzQQCB-CJehD3e2T1eKBtZwKg6r2OkpTG1Oo,1768
30
- ngio/ome_zarr_meta/v04/_v04_spec_utils.py,sha256=_vszk3ORSLObwW_0xbR61ptekvwgFiXsBLZ-5wgWli8,13775
31
- ngio/tables/__init__.py,sha256=7Mz0kzssaM4k39az__6F9L8s46RaN0Vbw1JkfkysCPU,565
32
- ngio/tables/_validators.py,sha256=Cg2sFb__G60RwSbNv4n9g_941R4Dzbp_LnaQBdVyaWw,6457
33
- ngio/tables/tables_container.py,sha256=d7PVerDkAtrhWRmv8BVVE0tbrdugPSxZEa8w9tR5KrA,9508
34
- ngio/tables/backends/__init__.py,sha256=NlOXmZXDA1kOCVONUyo_aqSjdMHmfqk-3xuKBLXpaUM,217
35
- ngio/tables/backends/_abstract_backend.py,sha256=JlaHqLjDm2uVnXFWxsHMojNeKo3leg6uauzoFMSF5O4,2256
36
- ngio/tables/backends/_anndata_utils.py,sha256=xqkm52XMMWC-jJ126oK7x1w7s4Y2jDjtgP8dmHSB3uU,6792
37
- ngio/tables/backends/_anndata_v1.py,sha256=rzr471-Ae76KFJ0vjgzbGyW2m2Gb0El7JcmnT6mwGJY,2573
38
- ngio/tables/backends/_json_v1.py,sha256=mT7qJY2U4vhwromZnT9foz_vVtNh_fwmsASGnLZbIac,1897
39
- ngio/tables/backends/_table_backends.py,sha256=XXtnZqVDbMqFkbUkHbf9IBNz4teCouLpa5fWgEgVtfg,3269
40
- ngio/tables/v1/__init__.py,sha256=C35WD3vSqB-AcATi7MRhGbCw5Z5VK7gGb8E8cMgL_L0,359
41
- ngio/tables/v1/_feature_table.py,sha256=WOkFOb0UDxwM-MPZGdv-nLIiqfiGL8etVkMett9iQic,5099
42
- ngio/tables/v1/_generic_table.py,sha256=KOVzbeUs8AwVvI83Os5gBZky948ucEKjxXl2CGzSQqQ,3483
43
- ngio/tables/v1/_masking_roi_table.py,sha256=vPlUWGQalxDJ7G4NcSmzsOFqSEIJFXbuCLD_ucBj7ew,5492
44
- ngio/tables/v1/_roi_table.py,sha256=UMwJEMkOAgDf-80z0qPfIiB6fsQInjzjDlR4OkBYH4o,7147
45
- ngio/utils/__init__.py,sha256=r3nuLWgp6-cQlS4ODjYSBrfgdTLkCOVke9jKbn1NpkA,1129
46
- ngio/utils/_datasets.py,sha256=Ir5-DUaplJoWXIsFCVp6yaJNfEKXKygj6RbGsy275uE,1669
47
- ngio/utils/_errors.py,sha256=pKQ12LUjQLYE1nUawemA5h7HsgznjaSvV1n2PQU33N0,759
48
- ngio/utils/_fractal_fsspec_store.py,sha256=KxIu37EUJgiKI92qmJKfZtCjNdfMmfNbYez2LAK3dxg,496
49
- ngio/utils/_logger.py,sha256=zvFG-Ta3ZIJxTyY93zYoPGp2A6TTUf7mSO0zr_uFy4A,837
50
- ngio/utils/_zarr_utils.py,sha256=5Mo8Nfb7oww7rGVqEWUH29VvOkhD3-Despb3c1SlENM,12172
51
- ngio-0.2.0a3.dist-info/METADATA,sha256=L6dq7gPr76J0FFjE0K6mFTm5UFFpOaHVpi8mKS15hRk,4804
52
- ngio-0.2.0a3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
53
- ngio-0.2.0a3.dist-info/licenses/LICENSE,sha256=UgN_a1QCeNh9rZWfz-wORQFxE3elQzLWPQaoK6N6fxQ,1502
54
- ngio-0.2.0a3.dist-info/RECORD,,
File without changes