ngio 0.5.0b6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. ngio/__init__.py +69 -0
  2. ngio/common/__init__.py +28 -0
  3. ngio/common/_dimensions.py +335 -0
  4. ngio/common/_masking_roi.py +153 -0
  5. ngio/common/_pyramid.py +408 -0
  6. ngio/common/_roi.py +315 -0
  7. ngio/common/_synt_images_utils.py +101 -0
  8. ngio/common/_zoom.py +188 -0
  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 +19 -0
  18. ngio/hcs/_plate.py +1354 -0
  19. ngio/images/__init__.py +44 -0
  20. ngio/images/_abstract_image.py +967 -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 +411 -0
  25. ngio/images/_masked_image.py +531 -0
  26. ngio/images/_ome_zarr_container.py +1237 -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 +65 -0
  40. ngio/ome_zarr_meta/_meta_handlers.py +536 -0
  41. ngio/ome_zarr_meta/ngio_specs/__init__.py +77 -0
  42. ngio/ome_zarr_meta/ngio_specs/_axes.py +515 -0
  43. ngio/ome_zarr_meta/ngio_specs/_channels.py +462 -0
  44. ngio/ome_zarr_meta/ngio_specs/_dataset.py +89 -0
  45. ngio/ome_zarr_meta/ngio_specs/_ngio_hcs.py +539 -0
  46. ngio/ome_zarr_meta/ngio_specs/_ngio_image.py +438 -0
  47. ngio/ome_zarr_meta/ngio_specs/_pixel_size.py +122 -0
  48. ngio/ome_zarr_meta/v04/__init__.py +27 -0
  49. ngio/ome_zarr_meta/v04/_custom_models.py +18 -0
  50. ngio/ome_zarr_meta/v04/_v04_spec.py +473 -0
  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 +43 -0
  60. ngio/tables/_abstract_table.py +270 -0
  61. ngio/tables/_tables_container.py +449 -0
  62. ngio/tables/backends/__init__.py +57 -0
  63. ngio/tables/backends/_abstract_backend.py +240 -0
  64. ngio/tables/backends/_anndata.py +139 -0
  65. ngio/tables/backends/_anndata_utils.py +90 -0
  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 +226 -0
  71. ngio/tables/backends/_utils.py +608 -0
  72. ngio/tables/v1/__init__.py +23 -0
  73. ngio/tables/v1/_condition_table.py +71 -0
  74. ngio/tables/v1/_feature_table.py +125 -0
  75. ngio/tables/v1/_generic_table.py +49 -0
  76. ngio/tables/v1/_roi_table.py +575 -0
  77. ngio/transforms/__init__.py +5 -0
  78. ngio/transforms/_zoom.py +19 -0
  79. ngio/utils/__init__.py +45 -0
  80. ngio/utils/_cache.py +48 -0
  81. ngio/utils/_datasets.py +165 -0
  82. ngio/utils/_errors.py +37 -0
  83. ngio/utils/_fractal_fsspec_store.py +42 -0
  84. ngio/utils/_zarr_utils.py +534 -0
  85. ngio-0.5.0b6.dist-info/METADATA +148 -0
  86. ngio-0.5.0b6.dist-info/RECORD +88 -0
  87. ngio-0.5.0b6.dist-info/WHEEL +4 -0
  88. ngio-0.5.0b6.dist-info/licenses/LICENSE +28 -0
@@ -0,0 +1,125 @@
1
+ """Implementation of the FeatureTableV1 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 typing import Literal
8
+
9
+ from pydantic import BaseModel, Field
10
+
11
+ from ngio.tables._abstract_table import AbstractBaseTable
12
+ from ngio.tables.backends import BackendMeta, TableBackend, TabularData
13
+ from ngio.utils import NgioValueError
14
+ from ngio.utils._zarr_utils import ZarrGroupHandler
15
+
16
+
17
+ class RegionMeta(BaseModel):
18
+ """Metadata for the region."""
19
+
20
+ path: str
21
+
22
+
23
+ class FeatureTableMeta(BackendMeta):
24
+ """Metadata for the ROI table."""
25
+
26
+ table_version: Literal["1"] = "1"
27
+ type: Literal["feature_table"] = "feature_table"
28
+ region: RegionMeta | None = None
29
+ instance_key: str = "label" # Legacy field, kept for compatibility
30
+ # Backend metadata
31
+ index_key: str | None = "label"
32
+ index_type: Literal["int", "str"] | None = "int"
33
+ # Columns optional types
34
+ categorical_columns: list[str] = Field(default_factory=list)
35
+ measurement_columns: list[str] = Field(default_factory=list)
36
+ metadata_columns: list[str] = Field(default_factory=list)
37
+
38
+
39
+ class FeatureTableV1(AbstractBaseTable):
40
+ def __init__(
41
+ self,
42
+ table_data: TabularData | None = None,
43
+ *,
44
+ reference_label: str | None = None,
45
+ meta: FeatureTableMeta | None = None,
46
+ ) -> None:
47
+ """Initialize the GenericTable."""
48
+ if meta is None:
49
+ meta = FeatureTableMeta()
50
+
51
+ if reference_label is not None:
52
+ path = f"../labels/{reference_label}"
53
+ meta = FeatureTableMeta(region=RegionMeta(path=path))
54
+
55
+ if table_data is not None and not isinstance(table_data, TabularData):
56
+ raise NgioValueError(
57
+ f"The table is not of type SupportedTables. Got {type(table_data)}"
58
+ )
59
+
60
+ if meta.index_key is None:
61
+ meta.index_key = "label"
62
+
63
+ if meta.index_type is None:
64
+ meta.index_type = "int"
65
+
66
+ meta.instance_key = meta.index_key
67
+
68
+ super().__init__(
69
+ table_data=table_data,
70
+ meta=meta,
71
+ )
72
+
73
+ def __repr__(self) -> str:
74
+ """Return a string representation of the table."""
75
+ num_rows = len(self.dataframe) if self.dataframe is not None else 0
76
+ num_columns = len(self.dataframe.columns) if self.dataframe is not None else 0
77
+ properties = f"num_rows={num_rows}, num_columns={num_columns}"
78
+ if self.reference_label is not None:
79
+ properties += f", reference_label={self.reference_label}"
80
+ return f"FeatureTableV1({properties})"
81
+
82
+ @classmethod
83
+ def from_handler(
84
+ cls,
85
+ handler: ZarrGroupHandler,
86
+ backend: TableBackend | None = None,
87
+ ) -> "FeatureTableV1":
88
+ return cls._from_handler(
89
+ handler=handler,
90
+ backend=backend,
91
+ meta_model=FeatureTableMeta,
92
+ )
93
+
94
+ @property
95
+ def meta(self) -> FeatureTableMeta:
96
+ """Return the metadata of the table."""
97
+ if not isinstance(self._meta, FeatureTableMeta):
98
+ raise NgioValueError(
99
+ "The metadata of the table is not of type FeatureTableMeta."
100
+ )
101
+ return self._meta
102
+
103
+ @staticmethod
104
+ def table_type() -> str:
105
+ """Return the type of the table."""
106
+ return "feature_table"
107
+
108
+ @staticmethod
109
+ def version() -> str:
110
+ """The generic table does not have a version.
111
+
112
+ Since does not follow a specific schema.
113
+ """
114
+ return "1"
115
+
116
+ @property
117
+ def reference_label(self) -> str | None:
118
+ """Return the reference label."""
119
+ path = self.meta.region
120
+ if path is None:
121
+ return None
122
+
123
+ path = path.path
124
+ path = path.split("/")[-1]
125
+ return path
@@ -0,0 +1,49 @@
1
+ """Implementation of a generic table class."""
2
+
3
+ from ngio.tables._abstract_table import AbstractBaseTable
4
+ from ngio.tables.backends import BackendMeta, TableBackend
5
+ from ngio.utils import ZarrGroupHandler
6
+
7
+
8
+ class GenericTableMeta(BackendMeta):
9
+ """Metadata for the generic table.
10
+
11
+ This is used to store metadata for a generic table.
12
+ It does not have a specific definition.
13
+ """
14
+
15
+ table_version: str | None = "1"
16
+ type: str | None = "generic_table"
17
+
18
+
19
+ class GenericTable(AbstractBaseTable):
20
+ """Class to a non-specific table.
21
+
22
+ This can be used to load any table that does not have
23
+ a specific definition.
24
+ """
25
+
26
+ @staticmethod
27
+ def table_type() -> str:
28
+ """Return the type of the table."""
29
+ return "generic_table"
30
+
31
+ @staticmethod
32
+ def version() -> str:
33
+ """The generic table does not have a version.
34
+
35
+ Since does not follow a specific schema.
36
+ """
37
+ return "1"
38
+
39
+ @classmethod
40
+ def from_handler(
41
+ cls,
42
+ handler: ZarrGroupHandler,
43
+ backend: TableBackend | None = None,
44
+ ) -> "GenericTable":
45
+ return cls._from_handler(
46
+ handler=handler,
47
+ backend=backend,
48
+ meta_model=BackendMeta,
49
+ )