ngio 0.2.0b2__py3-none-any.whl → 0.2.1__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 +11 -9
- ngio/common/__init__.py +3 -3
- ngio/common/_array_pipe.py +6 -7
- ngio/common/_masking_roi.py +4 -4
- ngio/common/_roi.py +12 -12
- ngio/hcs/__init__.py +2 -2
- ngio/hcs/plate.py +86 -34
- ngio/images/__init__.py +7 -7
- ngio/images/abstract_image.py +50 -10
- ngio/images/create.py +4 -3
- ngio/images/image.py +2 -2
- ngio/images/label.py +10 -6
- ngio/images/masked_image.py +19 -5
- ngio/images/{omezarr_container.py → ome_zarr_container.py} +57 -30
- ngio/ome_zarr_meta/__init__.py +3 -0
- ngio/ome_zarr_meta/ngio_specs/__init__.py +2 -0
- ngio/ome_zarr_meta/ngio_specs/_ngio_hcs.py +5 -4
- ngio/ome_zarr_meta/ngio_specs/_ngio_image.py +9 -19
- ngio/ome_zarr_meta/v04/_v04_spec_utils.py +1 -2
- ngio/tables/__init__.py +2 -2
- ngio/tables/tables_container.py +3 -3
- ngio/tables/v1/__init__.py +2 -2
- ngio/tables/v1/_feature_table.py +20 -1
- ngio/tables/v1/_generic_table.py +10 -0
- ngio/tables/v1/_roi_table.py +35 -13
- {ngio-0.2.0b2.dist-info → ngio-0.2.1.dist-info}/METADATA +9 -5
- ngio-0.2.1.dist-info/RECORD +54 -0
- ngio-0.2.0b2.dist-info/RECORD +0 -54
- {ngio-0.2.0b2.dist-info → ngio-0.2.1.dist-info}/WHEEL +0 -0
- {ngio-0.2.0b2.dist-info → ngio-0.2.1.dist-info}/licenses/LICENSE +0 -0
ngio/images/label.py
CHANGED
|
@@ -13,7 +13,7 @@ from ngio.ome_zarr_meta import (
|
|
|
13
13
|
PixelSize,
|
|
14
14
|
find_label_meta_handler,
|
|
15
15
|
)
|
|
16
|
-
from ngio.tables import
|
|
16
|
+
from ngio.tables import MaskingRoiTable
|
|
17
17
|
from ngio.utils import (
|
|
18
18
|
NgioValidationError,
|
|
19
19
|
NgioValueError,
|
|
@@ -35,7 +35,7 @@ class Label(AbstractImage[LabelMetaHandler]):
|
|
|
35
35
|
|
|
36
36
|
Args:
|
|
37
37
|
group_handler: The Zarr group handler.
|
|
38
|
-
path: The path to the image in the
|
|
38
|
+
path: The path to the image in the ome_zarr file.
|
|
39
39
|
meta_handler: The image metadata handler.
|
|
40
40
|
|
|
41
41
|
"""
|
|
@@ -45,12 +45,16 @@ class Label(AbstractImage[LabelMetaHandler]):
|
|
|
45
45
|
group_handler=group_handler, path=path, meta_handler=meta_handler
|
|
46
46
|
)
|
|
47
47
|
|
|
48
|
+
def __repr__(self) -> str:
|
|
49
|
+
"""Return the string representation of the label."""
|
|
50
|
+
return f"Label(path={self.path}, {self.dimensions})"
|
|
51
|
+
|
|
48
52
|
@property
|
|
49
53
|
def meta(self) -> NgioLabelMeta:
|
|
50
54
|
"""Return the metadata."""
|
|
51
55
|
return self._meta_handler.meta
|
|
52
56
|
|
|
53
|
-
def build_masking_roi_table(self) ->
|
|
57
|
+
def build_masking_roi_table(self) -> MaskingRoiTable:
|
|
54
58
|
"""Compute the masking ROI table."""
|
|
55
59
|
return build_masking_roi_table(self)
|
|
56
60
|
|
|
@@ -101,7 +105,7 @@ class LabelsContainer:
|
|
|
101
105
|
|
|
102
106
|
Args:
|
|
103
107
|
name (str): The name of the label.
|
|
104
|
-
path (str | None): The path to the image in the
|
|
108
|
+
path (str | None): The path to the image in the ome_zarr file.
|
|
105
109
|
pixel_size (PixelSize | None): The pixel size of the image.
|
|
106
110
|
strict (bool): Only used if the pixel size is provided. If True, the
|
|
107
111
|
pixel size must match the image pixel size exactly. If False, the
|
|
@@ -270,7 +274,7 @@ def _derive_label(
|
|
|
270
274
|
return None
|
|
271
275
|
|
|
272
276
|
|
|
273
|
-
def build_masking_roi_table(label: Label) ->
|
|
277
|
+
def build_masking_roi_table(label: Label) -> MaskingRoiTable:
|
|
274
278
|
"""Compute the masking ROI table for a label."""
|
|
275
279
|
if label.dimensions.is_time_series:
|
|
276
280
|
raise NgioValueError("Time series labels are not supported.")
|
|
@@ -278,4 +282,4 @@ def build_masking_roi_table(label: Label) -> MaskingROITable:
|
|
|
278
282
|
array = label.get_array(axes_order=["z", "y", "x"], mode="dask")
|
|
279
283
|
|
|
280
284
|
rois = compute_masking_roi(array, label.pixel_size)
|
|
281
|
-
return
|
|
285
|
+
return MaskingRoiTable(rois, reference_label=label.meta.name)
|
ngio/images/masked_image.py
CHANGED
|
@@ -7,7 +7,7 @@ from ngio.common import ArrayLike, get_masked_pipe, roi_to_slice_kwargs, set_mas
|
|
|
7
7
|
from ngio.images.image import Image
|
|
8
8
|
from ngio.images.label import Label
|
|
9
9
|
from ngio.ome_zarr_meta import ImageMetaHandler, LabelMetaHandler
|
|
10
|
-
from ngio.tables import
|
|
10
|
+
from ngio.tables import MaskingRoiTable
|
|
11
11
|
from ngio.utils import (
|
|
12
12
|
ZarrGroupHandler,
|
|
13
13
|
)
|
|
@@ -22,13 +22,13 @@ class MaskedImage(Image):
|
|
|
22
22
|
path: str,
|
|
23
23
|
meta_handler: ImageMetaHandler | None,
|
|
24
24
|
label: Label,
|
|
25
|
-
masking_roi_table:
|
|
25
|
+
masking_roi_table: MaskingRoiTable,
|
|
26
26
|
) -> None:
|
|
27
27
|
"""Initialize the Image at a single level.
|
|
28
28
|
|
|
29
29
|
Args:
|
|
30
30
|
group_handler: The Zarr group handler.
|
|
31
|
-
path: The path to the image in the
|
|
31
|
+
path: The path to the image in the ome_zarr file.
|
|
32
32
|
meta_handler: The image metadata handler.
|
|
33
33
|
label: The label image.
|
|
34
34
|
masking_roi_table: The masking ROI table.
|
|
@@ -40,6 +40,13 @@ class MaskedImage(Image):
|
|
|
40
40
|
self._label = label
|
|
41
41
|
self._masking_roi_table = masking_roi_table
|
|
42
42
|
|
|
43
|
+
def __repr__(self) -> str:
|
|
44
|
+
"""Return a string representation of the object."""
|
|
45
|
+
label_name = self._label.meta.name
|
|
46
|
+
if label_name is None:
|
|
47
|
+
label_name = self._masking_roi_table.reference_label
|
|
48
|
+
return f"MaskedImage(path={self.path}, {self.dimensions}, {label_name})"
|
|
49
|
+
|
|
43
50
|
def get_roi(
|
|
44
51
|
self,
|
|
45
52
|
label: int,
|
|
@@ -116,13 +123,13 @@ class MaskedLabel(Label):
|
|
|
116
123
|
path: str,
|
|
117
124
|
meta_handler: LabelMetaHandler | None,
|
|
118
125
|
label: Label,
|
|
119
|
-
masking_roi_table:
|
|
126
|
+
masking_roi_table: MaskingRoiTable,
|
|
120
127
|
) -> None:
|
|
121
128
|
"""Initialize the Image at a single level.
|
|
122
129
|
|
|
123
130
|
Args:
|
|
124
131
|
group_handler: The Zarr group handler.
|
|
125
|
-
path: The path to the image in the
|
|
132
|
+
path: The path to the image in the ome_zarr file.
|
|
126
133
|
meta_handler: The image metadata handler.
|
|
127
134
|
label: The label image.
|
|
128
135
|
masking_roi_table: The masking ROI table.
|
|
@@ -134,6 +141,13 @@ class MaskedLabel(Label):
|
|
|
134
141
|
self._label = label
|
|
135
142
|
self._masking_roi_table = masking_roi_table
|
|
136
143
|
|
|
144
|
+
def __repr__(self) -> str:
|
|
145
|
+
"""Return a string representation of the object."""
|
|
146
|
+
label_name = self._label.meta.name
|
|
147
|
+
if label_name is None:
|
|
148
|
+
label_name = self._masking_roi_table.reference_label
|
|
149
|
+
return f"MaskedLabel(path={self.path}, {self.dimensions}, {label_name})"
|
|
150
|
+
|
|
137
151
|
def get_roi(
|
|
138
152
|
self,
|
|
139
153
|
label: int,
|
|
@@ -13,14 +13,11 @@ from ngio.ome_zarr_meta import (
|
|
|
13
13
|
NgioImageMeta,
|
|
14
14
|
PixelSize,
|
|
15
15
|
)
|
|
16
|
-
from ngio.ome_zarr_meta.ngio_specs import
|
|
17
|
-
SpaceUnits,
|
|
18
|
-
TimeUnits,
|
|
19
|
-
)
|
|
16
|
+
from ngio.ome_zarr_meta.ngio_specs import NgffVersion, SpaceUnits, TimeUnits
|
|
20
17
|
from ngio.tables import (
|
|
21
18
|
FeatureTable,
|
|
22
19
|
GenericRoiTable,
|
|
23
|
-
|
|
20
|
+
MaskingRoiTable,
|
|
24
21
|
RoiTable,
|
|
25
22
|
Table,
|
|
26
23
|
TablesContainer,
|
|
@@ -125,6 +122,36 @@ class OmeZarrContainer:
|
|
|
125
122
|
"""Return the paths of the levels in the image."""
|
|
126
123
|
return self._images_container.levels_paths
|
|
127
124
|
|
|
125
|
+
@property
|
|
126
|
+
def is_3d(self) -> bool:
|
|
127
|
+
"""Return True if the image is 3D."""
|
|
128
|
+
return self.get_image().is_3d
|
|
129
|
+
|
|
130
|
+
@property
|
|
131
|
+
def is_2d(self) -> bool:
|
|
132
|
+
"""Return True if the image is 2D."""
|
|
133
|
+
return self.get_image().is_2d
|
|
134
|
+
|
|
135
|
+
@property
|
|
136
|
+
def is_time_series(self) -> bool:
|
|
137
|
+
"""Return True if the image is a time series."""
|
|
138
|
+
return self.get_image().is_time_series
|
|
139
|
+
|
|
140
|
+
@property
|
|
141
|
+
def is_2d_time_series(self) -> bool:
|
|
142
|
+
"""Return True if the image is a 2D time series."""
|
|
143
|
+
return self.get_image().is_2d_time_series
|
|
144
|
+
|
|
145
|
+
@property
|
|
146
|
+
def is_3d_time_series(self) -> bool:
|
|
147
|
+
"""Return True if the image is a 3D time series."""
|
|
148
|
+
return self.get_image().is_3d_time_series
|
|
149
|
+
|
|
150
|
+
@property
|
|
151
|
+
def is_multi_channels(self) -> bool:
|
|
152
|
+
"""Return True if the image is multichannel."""
|
|
153
|
+
return self.get_image().is_multi_channels
|
|
154
|
+
|
|
128
155
|
def initialize_channel_meta(
|
|
129
156
|
self,
|
|
130
157
|
labels: Collection[str] | int | None = None,
|
|
@@ -163,7 +190,7 @@ class OmeZarrContainer:
|
|
|
163
190
|
"""Get an image at a specific level.
|
|
164
191
|
|
|
165
192
|
Args:
|
|
166
|
-
path (str | None): The path to the image in the
|
|
193
|
+
path (str | None): The path to the image in the ome_zarr file.
|
|
167
194
|
pixel_size (PixelSize | None): The pixel size of the image.
|
|
168
195
|
strict (bool): Only used if the pixel size is provided. If True, the
|
|
169
196
|
pixel size must match the image pixel size exactly. If False, the
|
|
@@ -187,7 +214,7 @@ class OmeZarrContainer:
|
|
|
187
214
|
Args:
|
|
188
215
|
masking_label_name (str): The name of the label.
|
|
189
216
|
masking_table_name (str | None): The name of the masking table.
|
|
190
|
-
path (str | None): The path to the image in the
|
|
217
|
+
path (str | None): The path to the image in the ome_zarr file.
|
|
191
218
|
pixel_size (PixelSize | None): The pixel size of the image.
|
|
192
219
|
strict (bool): Only used if the pixel size is provided. If True, the
|
|
193
220
|
pixel size must match the image pixel size exactly. If False, the
|
|
@@ -262,21 +289,21 @@ class OmeZarrContainer:
|
|
|
262
289
|
store, cache=self._group_handler.use_cache, mode=self._group_handler.mode
|
|
263
290
|
)
|
|
264
291
|
|
|
265
|
-
|
|
292
|
+
new_ome_zarr = OmeZarrContainer(
|
|
266
293
|
group_handler=handler,
|
|
267
294
|
validate_arrays=False,
|
|
268
295
|
)
|
|
269
296
|
|
|
270
297
|
if copy_labels:
|
|
271
298
|
self.labels_container._group_handler.copy_handler(
|
|
272
|
-
|
|
299
|
+
new_ome_zarr.labels_container._group_handler
|
|
273
300
|
)
|
|
274
301
|
|
|
275
302
|
if copy_tables:
|
|
276
303
|
self.tables_container._group_handler.copy_handler(
|
|
277
|
-
|
|
304
|
+
new_ome_zarr.tables_container._group_handler
|
|
278
305
|
)
|
|
279
|
-
return
|
|
306
|
+
return new_ome_zarr
|
|
280
307
|
|
|
281
308
|
def list_tables(self) -> list[str]:
|
|
282
309
|
"""List all tables in the image."""
|
|
@@ -295,7 +322,7 @@ class OmeZarrContainer:
|
|
|
295
322
|
@overload
|
|
296
323
|
def get_table(
|
|
297
324
|
self, name: str, check_type: Literal["masking_roi_table"]
|
|
298
|
-
) ->
|
|
325
|
+
) -> MaskingRoiTable: ...
|
|
299
326
|
|
|
300
327
|
@overload
|
|
301
328
|
def get_table(
|
|
@@ -318,7 +345,7 @@ class OmeZarrContainer:
|
|
|
318
345
|
)
|
|
319
346
|
return table
|
|
320
347
|
case "masking_roi_table":
|
|
321
|
-
if not isinstance(table,
|
|
348
|
+
if not isinstance(table, MaskingRoiTable):
|
|
322
349
|
raise NgioValueError(
|
|
323
350
|
f"Table '{name}' is not a masking ROI table. "
|
|
324
351
|
f"Found type: {table.type()}"
|
|
@@ -349,7 +376,7 @@ class OmeZarrContainer:
|
|
|
349
376
|
"""Compute the ROI table for an image."""
|
|
350
377
|
return self.get_image().build_image_roi_table(name=name)
|
|
351
378
|
|
|
352
|
-
def build_masking_roi_table(self, label: str) ->
|
|
379
|
+
def build_masking_roi_table(self, label: str) -> MaskingRoiTable:
|
|
353
380
|
"""Compute the masking ROI table for a label."""
|
|
354
381
|
return self.get_label(label).build_masking_roi_table()
|
|
355
382
|
|
|
@@ -380,7 +407,7 @@ class OmeZarrContainer:
|
|
|
380
407
|
|
|
381
408
|
Args:
|
|
382
409
|
name (str): The name of the label.
|
|
383
|
-
path (str | None): The path to the image in the
|
|
410
|
+
path (str | None): The path to the image in the ome_zarr file.
|
|
384
411
|
pixel_size (PixelSize | None): The pixel size of the image.
|
|
385
412
|
strict (bool): Only used if the pixel size is provided. If True, the
|
|
386
413
|
pixel size must match the image pixel size exactly. If False, the
|
|
@@ -405,7 +432,7 @@ class OmeZarrContainer:
|
|
|
405
432
|
label_name (str): The name of the label.
|
|
406
433
|
masking_label_name (str): The name of the masking label.
|
|
407
434
|
masking_table_name (str | None): The name of the masking table.
|
|
408
|
-
path (str | None): The path to the image in the
|
|
435
|
+
path (str | None): The path to the image in the ome_zarr file.
|
|
409
436
|
pixel_size (PixelSize | None): The pixel size of the image.
|
|
410
437
|
strict (bool): Only used if the pixel size is provided. If True, the
|
|
411
438
|
pixel size must match the image pixel size exactly. If False, the
|
|
@@ -477,7 +504,7 @@ class OmeZarrContainer:
|
|
|
477
504
|
)
|
|
478
505
|
|
|
479
506
|
|
|
480
|
-
def
|
|
507
|
+
def open_ome_zarr_container(
|
|
481
508
|
store: StoreOrGroup,
|
|
482
509
|
cache: bool = False,
|
|
483
510
|
mode: AccessModeLiteral = "r+",
|
|
@@ -503,7 +530,7 @@ def open_image(
|
|
|
503
530
|
|
|
504
531
|
Args:
|
|
505
532
|
store (StoreOrGroup): The Zarr store or group to create the image in.
|
|
506
|
-
path (str | None): The path to the image in the
|
|
533
|
+
path (str | None): The path to the image in the ome_zarr file.
|
|
507
534
|
pixel_size (PixelSize | None): The pixel size of the image.
|
|
508
535
|
strict (bool): Only used if the pixel size is provided. If True, the
|
|
509
536
|
pixel size must match the image pixel size exactly. If False, the
|
|
@@ -521,7 +548,7 @@ def open_image(
|
|
|
521
548
|
)
|
|
522
549
|
|
|
523
550
|
|
|
524
|
-
def
|
|
551
|
+
def create_empty_ome_zarr(
|
|
525
552
|
store: StoreOrGroup,
|
|
526
553
|
shape: Collection[int],
|
|
527
554
|
xy_pixelsize: float,
|
|
@@ -542,7 +569,7 @@ def create_empty_omezarr(
|
|
|
542
569
|
channel_colors: Collection[str] | None = None,
|
|
543
570
|
channel_active: Collection[bool] | None = None,
|
|
544
571
|
overwrite: bool = False,
|
|
545
|
-
version:
|
|
572
|
+
version: NgffVersion = "0.4",
|
|
546
573
|
) -> OmeZarrContainer:
|
|
547
574
|
"""Create an empty OME-Zarr image with the given shape and metadata.
|
|
548
575
|
|
|
@@ -581,7 +608,7 @@ def create_empty_omezarr(
|
|
|
581
608
|
active. Defaults to None.
|
|
582
609
|
overwrite (bool, optional): Whether to overwrite an existing image.
|
|
583
610
|
Defaults to True.
|
|
584
|
-
version (
|
|
611
|
+
version (NgffVersion, optional): The version of the OME-Zarr specification.
|
|
585
612
|
Defaults to "0.4".
|
|
586
613
|
"""
|
|
587
614
|
handler = _create_empty_image(
|
|
@@ -603,18 +630,18 @@ def create_empty_omezarr(
|
|
|
603
630
|
version=version,
|
|
604
631
|
)
|
|
605
632
|
|
|
606
|
-
|
|
607
|
-
|
|
633
|
+
ome_zarr = OmeZarrContainer(group_handler=handler)
|
|
634
|
+
ome_zarr.initialize_channel_meta(
|
|
608
635
|
labels=channel_labels,
|
|
609
636
|
wavelength_id=channel_wavelengths,
|
|
610
637
|
percentiles=percentiles,
|
|
611
638
|
colors=channel_colors,
|
|
612
639
|
active=channel_active,
|
|
613
640
|
)
|
|
614
|
-
return
|
|
641
|
+
return ome_zarr
|
|
615
642
|
|
|
616
643
|
|
|
617
|
-
def
|
|
644
|
+
def create_ome_zarr_from_array(
|
|
618
645
|
store: StoreOrGroup,
|
|
619
646
|
array: np.ndarray,
|
|
620
647
|
xy_pixelsize: float,
|
|
@@ -634,7 +661,7 @@ def create_omezarr_from_array(
|
|
|
634
661
|
name: str | None = None,
|
|
635
662
|
chunks: Collection[int] | None = None,
|
|
636
663
|
overwrite: bool = False,
|
|
637
|
-
version:
|
|
664
|
+
version: NgffVersion = "0.4",
|
|
638
665
|
) -> OmeZarrContainer:
|
|
639
666
|
"""Create an OME-Zarr image from a numpy array.
|
|
640
667
|
|
|
@@ -694,15 +721,15 @@ def create_omezarr_from_array(
|
|
|
694
721
|
version=version,
|
|
695
722
|
)
|
|
696
723
|
|
|
697
|
-
|
|
698
|
-
image =
|
|
724
|
+
ome_zarr = OmeZarrContainer(group_handler=handler)
|
|
725
|
+
image = ome_zarr.get_image()
|
|
699
726
|
image.set_array(array)
|
|
700
727
|
image.consolidate()
|
|
701
|
-
|
|
728
|
+
ome_zarr.initialize_channel_meta(
|
|
702
729
|
labels=channel_labels,
|
|
703
730
|
wavelength_id=channel_wavelengths,
|
|
704
731
|
percentiles=percentiles,
|
|
705
732
|
colors=channel_colors,
|
|
706
733
|
active=channel_active,
|
|
707
734
|
)
|
|
708
|
-
return
|
|
735
|
+
return ome_zarr
|
ngio/ome_zarr_meta/__init__.py
CHANGED
|
@@ -16,6 +16,7 @@ from ngio.ome_zarr_meta.ngio_specs import (
|
|
|
16
16
|
AxesMapper,
|
|
17
17
|
Dataset,
|
|
18
18
|
ImageInWellPath,
|
|
19
|
+
NgffVersion,
|
|
19
20
|
NgioImageMeta,
|
|
20
21
|
NgioLabelMeta,
|
|
21
22
|
NgioPlateMeta,
|
|
@@ -31,6 +32,8 @@ __all__ = [
|
|
|
31
32
|
"ImageMetaHandler",
|
|
32
33
|
"LabelMetaHandler",
|
|
33
34
|
"LabelMetaHandler",
|
|
35
|
+
"NgffVersion",
|
|
36
|
+
"NgffVersion",
|
|
34
37
|
"NgioImageMeta",
|
|
35
38
|
"NgioLabelMeta",
|
|
36
39
|
"NgioPlateMeta",
|
|
@@ -35,6 +35,7 @@ from ngio.ome_zarr_meta.ngio_specs._ngio_hcs import (
|
|
|
35
35
|
)
|
|
36
36
|
from ngio.ome_zarr_meta.ngio_specs._ngio_image import (
|
|
37
37
|
ImageLabelSource,
|
|
38
|
+
NgffVersion,
|
|
38
39
|
NgioImageLabelMeta,
|
|
39
40
|
NgioImageMeta,
|
|
40
41
|
NgioLabelMeta,
|
|
@@ -56,6 +57,7 @@ __all__ = [
|
|
|
56
57
|
"Dataset",
|
|
57
58
|
"ImageInWellPath",
|
|
58
59
|
"ImageLabelSource",
|
|
60
|
+
"NgffVersion",
|
|
59
61
|
"NgioColors",
|
|
60
62
|
"NgioImageLabelMeta",
|
|
61
63
|
"NgioImageMeta",
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"""HCS (High Content Screening) specific metadata classes for NGIO."""
|
|
2
2
|
|
|
3
|
-
from typing import Literal
|
|
4
|
-
|
|
5
3
|
from ome_zarr_models.v04.hcs import HCSAttrs
|
|
6
4
|
from ome_zarr_models.v04.plate import (
|
|
7
5
|
Acquisition,
|
|
@@ -14,6 +12,7 @@ from ome_zarr_models.v04.well import WellAttrs
|
|
|
14
12
|
from ome_zarr_models.v04.well_types import WellImage, WellMeta
|
|
15
13
|
from pydantic import BaseModel
|
|
16
14
|
|
|
15
|
+
from ngio.ome_zarr_meta.ngio_specs._ngio_image import NgffVersion
|
|
17
16
|
from ngio.utils import NgioValueError
|
|
18
17
|
|
|
19
18
|
|
|
@@ -34,8 +33,10 @@ class NgioWellMeta(WellAttrs):
|
|
|
34
33
|
def default_init(
|
|
35
34
|
cls,
|
|
36
35
|
images: list[ImageInWellPath] | None = None,
|
|
37
|
-
version:
|
|
36
|
+
version: NgffVersion | None = None,
|
|
38
37
|
) -> "NgioWellMeta":
|
|
38
|
+
if version is None:
|
|
39
|
+
version = "0.4"
|
|
39
40
|
well = cls(well=WellMeta(images=[], version=version))
|
|
40
41
|
if images is None:
|
|
41
42
|
return well
|
|
@@ -164,7 +165,7 @@ class NgioPlateMeta(HCSAttrs):
|
|
|
164
165
|
cls,
|
|
165
166
|
images: list[ImageInWellPath] | None = None,
|
|
166
167
|
name: str | None = None,
|
|
167
|
-
version:
|
|
168
|
+
version: NgffVersion | None = None,
|
|
168
169
|
) -> "NgioPlateMeta":
|
|
169
170
|
plate = cls(
|
|
170
171
|
plate=Plate(
|
|
@@ -7,8 +7,7 @@ can be converted to the OME standard.
|
|
|
7
7
|
"""
|
|
8
8
|
|
|
9
9
|
from collections.abc import Collection
|
|
10
|
-
from
|
|
11
|
-
from typing import Any, TypeVar
|
|
10
|
+
from typing import Any, Literal, TypeVar
|
|
12
11
|
|
|
13
12
|
import numpy as np
|
|
14
13
|
from pydantic import BaseModel
|
|
@@ -22,12 +21,7 @@ from ngio.ome_zarr_meta.ngio_specs._pixel_size import PixelSize
|
|
|
22
21
|
from ngio.utils import NgioValidationError, NgioValueError
|
|
23
22
|
|
|
24
23
|
T = TypeVar("T")
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
class NgffVersion(str, Enum):
|
|
28
|
-
"""Allowed NGFF versions."""
|
|
29
|
-
|
|
30
|
-
v04 = "0.4"
|
|
24
|
+
NgffVersion = Literal["0.4"]
|
|
31
25
|
|
|
32
26
|
|
|
33
27
|
class ImageLabelSource(BaseModel):
|
|
@@ -45,9 +39,11 @@ class ImageLabelSource(BaseModel):
|
|
|
45
39
|
class AbstractNgioImageMeta:
|
|
46
40
|
"""Base class for ImageMeta and LabelMeta."""
|
|
47
41
|
|
|
48
|
-
def __init__(
|
|
42
|
+
def __init__(
|
|
43
|
+
self, version: NgffVersion, name: str | None, datasets: list[Dataset]
|
|
44
|
+
) -> None:
|
|
49
45
|
"""Initialize the ImageMeta object."""
|
|
50
|
-
self._version =
|
|
46
|
+
self._version = version
|
|
51
47
|
self._name = name
|
|
52
48
|
|
|
53
49
|
if len(datasets) == 0:
|
|
@@ -70,7 +66,7 @@ class AbstractNgioImageMeta:
|
|
|
70
66
|
pixel_size: PixelSize,
|
|
71
67
|
scaling_factors: Collection[float] | None = None,
|
|
72
68
|
name: str | None = None,
|
|
73
|
-
version:
|
|
69
|
+
version: NgffVersion = "0.4",
|
|
74
70
|
):
|
|
75
71
|
"""Initialize the ImageMeta object."""
|
|
76
72
|
axes = canonical_axes(
|
|
@@ -335,19 +331,13 @@ class NgioLabelMeta(AbstractNgioImageMeta):
|
|
|
335
331
|
|
|
336
332
|
def __init__(
|
|
337
333
|
self,
|
|
338
|
-
version:
|
|
334
|
+
version: NgffVersion,
|
|
339
335
|
name: str | None,
|
|
340
336
|
datasets: list[Dataset],
|
|
341
337
|
image_label: ImageLabelSource | None = None,
|
|
342
338
|
) -> None:
|
|
343
339
|
"""Initialize the ImageMeta object."""
|
|
344
340
|
super().__init__(version, name, datasets)
|
|
345
|
-
|
|
346
|
-
# Make sure that there are no channel axes
|
|
347
|
-
channel_axis = self.axes_mapper.get_axis("c")
|
|
348
|
-
if channel_axis is not None:
|
|
349
|
-
raise NgioValidationError("Label metadata must not have channel axes.")
|
|
350
|
-
|
|
351
341
|
image_label = (
|
|
352
342
|
ImageLabelSource.default_init(self.version)
|
|
353
343
|
if image_label is None
|
|
@@ -380,7 +370,7 @@ class NgioImageMeta(AbstractNgioImageMeta):
|
|
|
380
370
|
|
|
381
371
|
def __init__(
|
|
382
372
|
self,
|
|
383
|
-
version:
|
|
373
|
+
version: NgffVersion,
|
|
384
374
|
name: str | None,
|
|
385
375
|
datasets: list[Dataset],
|
|
386
376
|
channels: ChannelsMeta | None = None,
|
|
@@ -41,7 +41,6 @@ from ngio.ome_zarr_meta.ngio_specs import (
|
|
|
41
41
|
NgioWellMeta,
|
|
42
42
|
default_channel_name,
|
|
43
43
|
)
|
|
44
|
-
from ngio.ome_zarr_meta.ngio_specs._ngio_image import NgffVersion
|
|
45
44
|
|
|
46
45
|
|
|
47
46
|
def _is_v04_image_meta(metadata: dict) -> ImageAttrsV04 | ValidationError:
|
|
@@ -290,7 +289,7 @@ def v04_to_ngio_label_meta(
|
|
|
290
289
|
else:
|
|
291
290
|
image_label_source = source.image
|
|
292
291
|
image_label_source = ImageLabelSource(
|
|
293
|
-
version=
|
|
292
|
+
version="0.4",
|
|
294
293
|
source={"image": image_label_source},
|
|
295
294
|
)
|
|
296
295
|
name = v04_muliscale.name
|
ngio/tables/__init__.py
CHANGED
|
@@ -4,7 +4,7 @@ from ngio.tables.backends import ImplementedTableBackends
|
|
|
4
4
|
from ngio.tables.tables_container import (
|
|
5
5
|
FeatureTable,
|
|
6
6
|
GenericRoiTable,
|
|
7
|
-
|
|
7
|
+
MaskingRoiTable,
|
|
8
8
|
RoiTable,
|
|
9
9
|
Table,
|
|
10
10
|
TablesContainer,
|
|
@@ -19,7 +19,7 @@ __all__ = [
|
|
|
19
19
|
"GenericRoiTable",
|
|
20
20
|
"GenericTable",
|
|
21
21
|
"ImplementedTableBackends",
|
|
22
|
-
"
|
|
22
|
+
"MaskingRoiTable",
|
|
23
23
|
"RoiTable",
|
|
24
24
|
"Table",
|
|
25
25
|
"TablesContainer",
|
ngio/tables/tables_container.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
from typing import Literal, Protocol
|
|
4
4
|
|
|
5
|
-
from ngio.tables.v1 import FeatureTableV1,
|
|
5
|
+
from ngio.tables.v1 import FeatureTableV1, MaskingRoiTableV1, RoiTableV1
|
|
6
6
|
from ngio.tables.v1._generic_table import GenericTable
|
|
7
7
|
from ngio.tables.v1._roi_table import _GenericRoiTableV1
|
|
8
8
|
from ngio.utils import (
|
|
@@ -15,7 +15,7 @@ from ngio.utils import (
|
|
|
15
15
|
|
|
16
16
|
GenericRoiTable = _GenericRoiTableV1
|
|
17
17
|
RoiTable = RoiTableV1
|
|
18
|
-
|
|
18
|
+
MaskingRoiTable = MaskingRoiTableV1
|
|
19
19
|
FeatureTable = FeatureTableV1
|
|
20
20
|
|
|
21
21
|
|
|
@@ -253,7 +253,7 @@ class TablesContainer:
|
|
|
253
253
|
|
|
254
254
|
|
|
255
255
|
ImplementedTables().add_implementation(RoiTableV1)
|
|
256
|
-
ImplementedTables().add_implementation(
|
|
256
|
+
ImplementedTables().add_implementation(MaskingRoiTableV1)
|
|
257
257
|
ImplementedTables().add_implementation(FeatureTableV1)
|
|
258
258
|
|
|
259
259
|
###################################################################################
|
ngio/tables/v1/__init__.py
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
from ngio.tables.v1._feature_table import FeatureTableV1
|
|
4
4
|
from ngio.tables.v1._generic_table import GenericTable
|
|
5
|
-
from ngio.tables.v1._roi_table import
|
|
5
|
+
from ngio.tables.v1._roi_table import MaskingRoiTableV1, RoiTableV1
|
|
6
6
|
|
|
7
|
-
__all__ = ["FeatureTableV1", "GenericTable", "
|
|
7
|
+
__all__ = ["FeatureTableV1", "GenericTable", "MaskingRoiTableV1", "RoiTableV1"]
|
ngio/tables/v1/_feature_table.py
CHANGED
|
@@ -49,7 +49,6 @@ class FeatureTableV1:
|
|
|
49
49
|
path = f"../labels/{reference_label}"
|
|
50
50
|
self._meta = FeatureTableMeta(region=RegionMeta(path=path))
|
|
51
51
|
|
|
52
|
-
self._reference_label = reference_label
|
|
53
52
|
self._instance_key = "label"
|
|
54
53
|
if dataframe is None:
|
|
55
54
|
self._dataframe = None
|
|
@@ -59,6 +58,15 @@ class FeatureTableV1:
|
|
|
59
58
|
)
|
|
60
59
|
self._table_backend = None
|
|
61
60
|
|
|
61
|
+
def __repr__(self) -> str:
|
|
62
|
+
"""Return a string representation of the table."""
|
|
63
|
+
num_rows = len(self.dataframe) if self.dataframe is not None else 0
|
|
64
|
+
num_columns = len(self.dataframe.columns) if self.dataframe is not None else 0
|
|
65
|
+
properties = f"num_rows={num_rows}, num_columns={num_columns}"
|
|
66
|
+
if self.reference_label is not None:
|
|
67
|
+
properties += f", reference_label={self.reference_label}"
|
|
68
|
+
return f"FeatureTableV1({properties})"
|
|
69
|
+
|
|
62
70
|
@staticmethod
|
|
63
71
|
def type() -> str:
|
|
64
72
|
"""Return the type of the table."""
|
|
@@ -79,6 +87,17 @@ class FeatureTableV1:
|
|
|
79
87
|
return None
|
|
80
88
|
return self._table_backend.backend_name()
|
|
81
89
|
|
|
90
|
+
@property
|
|
91
|
+
def reference_label(self) -> str | None:
|
|
92
|
+
"""Return the reference label."""
|
|
93
|
+
path = self._meta.region
|
|
94
|
+
if path is None:
|
|
95
|
+
return None
|
|
96
|
+
|
|
97
|
+
path = path.path
|
|
98
|
+
path = path.split("/")[-1]
|
|
99
|
+
return path
|
|
100
|
+
|
|
82
101
|
@property
|
|
83
102
|
def dataframe(self) -> pd.DataFrame:
|
|
84
103
|
"""Return the table as a DataFrame."""
|
ngio/tables/v1/_generic_table.py
CHANGED
|
@@ -51,6 +51,16 @@ class GenericTable:
|
|
|
51
51
|
|
|
52
52
|
self._table_backend = None
|
|
53
53
|
|
|
54
|
+
def __repr__(self) -> str:
|
|
55
|
+
"""Return a string representation of the table."""
|
|
56
|
+
if self._dataframe is not None:
|
|
57
|
+
num_rows = len(self.dataframe)
|
|
58
|
+
num_columns = len(self.dataframe.columns)
|
|
59
|
+
prop = f"num_rows={num_rows}, num_columns={num_columns}, mode=dataframe"
|
|
60
|
+
else:
|
|
61
|
+
prop = "mode=anndata"
|
|
62
|
+
return f"GenericTable({prop})"
|
|
63
|
+
|
|
54
64
|
@staticmethod
|
|
55
65
|
def type() -> str:
|
|
56
66
|
"""Return the type of the table."""
|