ngio 0.2.0b3__py3-none-any.whl → 0.2.2__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 +30 -10
- ngio/common/__init__.py +3 -3
- ngio/common/_array_pipe.py +7 -1
- ngio/common/_masking_roi.py +4 -4
- ngio/common/_roi.py +14 -14
- ngio/hcs/__init__.py +16 -2
- ngio/hcs/plate.py +465 -54
- ngio/images/__init__.py +7 -7
- ngio/images/abstract_image.py +30 -10
- ngio/images/create.py +25 -35
- ngio/images/image.py +40 -8
- ngio/images/label.py +33 -8
- ngio/images/masked_image.py +19 -5
- ngio/images/{omezarr_container.py → ome_zarr_container.py} +84 -47
- ngio/ome_zarr_meta/__init__.py +5 -0
- ngio/ome_zarr_meta/ngio_specs/__init__.py +10 -0
- ngio/ome_zarr_meta/ngio_specs/_axes.py +90 -65
- ngio/ome_zarr_meta/ngio_specs/_dataset.py +46 -8
- ngio/ome_zarr_meta/ngio_specs/_ngio_hcs.py +242 -69
- ngio/ome_zarr_meta/ngio_specs/_ngio_image.py +53 -19
- ngio/ome_zarr_meta/ngio_specs/_pixel_size.py +28 -11
- ngio/ome_zarr_meta/v04/_custom_models.py +18 -0
- ngio/ome_zarr_meta/v04/_v04_spec_utils.py +3 -4
- 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.0b3.dist-info → ngio-0.2.2.dist-info}/METADATA +8 -5
- ngio-0.2.2.dist-info/RECORD +55 -0
- ngio-0.2.0b3.dist-info/RECORD +0 -54
- {ngio-0.2.0b3.dist-info → ngio-0.2.2.dist-info}/WHEEL +0 -0
- {ngio-0.2.0b3.dist-info → ngio-0.2.2.dist-info}/licenses/LICENSE +0 -0
ngio/images/__init__.py
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
from ngio.images.image import Image, ImagesContainer
|
|
4
4
|
from ngio.images.label import Label, LabelsContainer
|
|
5
|
-
from ngio.images.
|
|
5
|
+
from ngio.images.ome_zarr_container import (
|
|
6
6
|
OmeZarrContainer,
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
create_empty_ome_zarr,
|
|
8
|
+
create_ome_zarr_from_array,
|
|
9
9
|
open_image,
|
|
10
|
-
|
|
10
|
+
open_ome_zarr_container,
|
|
11
11
|
)
|
|
12
12
|
|
|
13
13
|
__all__ = [
|
|
@@ -16,8 +16,8 @@ __all__ = [
|
|
|
16
16
|
"Label",
|
|
17
17
|
"LabelsContainer",
|
|
18
18
|
"OmeZarrContainer",
|
|
19
|
-
"
|
|
20
|
-
"
|
|
19
|
+
"create_empty_ome_zarr",
|
|
20
|
+
"create_ome_zarr_from_array",
|
|
21
21
|
"open_image",
|
|
22
|
-
"
|
|
22
|
+
"open_ome_zarr_container",
|
|
23
23
|
]
|
ngio/images/abstract_image.py
CHANGED
|
@@ -8,14 +8,15 @@ import zarr
|
|
|
8
8
|
from ngio.common import (
|
|
9
9
|
ArrayLike,
|
|
10
10
|
Dimensions,
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
Roi,
|
|
12
|
+
RoiPixels,
|
|
13
13
|
consolidate_pyramid,
|
|
14
14
|
get_pipe,
|
|
15
15
|
roi_to_slice_kwargs,
|
|
16
16
|
set_pipe,
|
|
17
17
|
)
|
|
18
18
|
from ngio.ome_zarr_meta import (
|
|
19
|
+
AxesMapper,
|
|
19
20
|
Dataset,
|
|
20
21
|
ImageMetaHandler,
|
|
21
22
|
LabelMetaHandler,
|
|
@@ -43,7 +44,7 @@ class AbstractImage(Generic[_image_handler]):
|
|
|
43
44
|
|
|
44
45
|
Args:
|
|
45
46
|
group_handler: The Zarr group handler.
|
|
46
|
-
path: The path to the image in the
|
|
47
|
+
path: The path to the image in the ome_zarr file.
|
|
47
48
|
meta_handler: The image metadata handler.
|
|
48
49
|
|
|
49
50
|
"""
|
|
@@ -63,7 +64,7 @@ class AbstractImage(Generic[_image_handler]):
|
|
|
63
64
|
shape=self._zarr_array.shape, axes_mapper=self._dataset.axes_mapper
|
|
64
65
|
)
|
|
65
66
|
|
|
66
|
-
self.
|
|
67
|
+
self._axes_mapper = self._dataset.axes_mapper
|
|
67
68
|
|
|
68
69
|
def __repr__(self) -> str:
|
|
69
70
|
"""Return a string representation of the image."""
|
|
@@ -99,6 +100,11 @@ class AbstractImage(Generic[_image_handler]):
|
|
|
99
100
|
"""Return the dimensions of the image."""
|
|
100
101
|
return self._dimensions
|
|
101
102
|
|
|
103
|
+
@property
|
|
104
|
+
def axes_mapper(self) -> AxesMapper:
|
|
105
|
+
"""Return the axes mapper of the image."""
|
|
106
|
+
return self._axes_mapper
|
|
107
|
+
|
|
102
108
|
@property
|
|
103
109
|
def is_3d(self) -> bool:
|
|
104
110
|
"""Return True if the image is 3D."""
|
|
@@ -129,6 +135,16 @@ class AbstractImage(Generic[_image_handler]):
|
|
|
129
135
|
"""Return True if the image is multichannel."""
|
|
130
136
|
return self.dimensions.is_multi_channels
|
|
131
137
|
|
|
138
|
+
@property
|
|
139
|
+
def space_unit(self) -> str | None:
|
|
140
|
+
"""Return the space unit of the image."""
|
|
141
|
+
return self.meta_handler.meta.space_unit
|
|
142
|
+
|
|
143
|
+
@property
|
|
144
|
+
def time_unit(self) -> str | None:
|
|
145
|
+
"""Return the time unit of the image."""
|
|
146
|
+
return self.meta_handler.meta.time_unit
|
|
147
|
+
|
|
132
148
|
@property
|
|
133
149
|
def pixel_size(self) -> PixelSize:
|
|
134
150
|
"""Return the pixel size of the image."""
|
|
@@ -144,6 +160,10 @@ class AbstractImage(Generic[_image_handler]):
|
|
|
144
160
|
"""Return the path of the image."""
|
|
145
161
|
return self._dataset.path
|
|
146
162
|
|
|
163
|
+
def has_axis(self, axis: str) -> bool:
|
|
164
|
+
"""Return True if the image has the given axis."""
|
|
165
|
+
return self.dimensions.has_axis(axis)
|
|
166
|
+
|
|
147
167
|
def get_array(
|
|
148
168
|
self,
|
|
149
169
|
axes_order: Collection[str] | None = None,
|
|
@@ -170,7 +190,7 @@ class AbstractImage(Generic[_image_handler]):
|
|
|
170
190
|
|
|
171
191
|
def get_roi(
|
|
172
192
|
self,
|
|
173
|
-
roi:
|
|
193
|
+
roi: Roi,
|
|
174
194
|
axes_order: Collection[str] | None = None,
|
|
175
195
|
mode: Literal["numpy", "dask", "delayed"] = "numpy",
|
|
176
196
|
**slice_kwargs: slice | int | Iterable[int],
|
|
@@ -214,7 +234,7 @@ class AbstractImage(Generic[_image_handler]):
|
|
|
214
234
|
|
|
215
235
|
def set_roi(
|
|
216
236
|
self,
|
|
217
|
-
roi:
|
|
237
|
+
roi: Roi,
|
|
218
238
|
patch: ArrayLike,
|
|
219
239
|
axes_order: Collection[str] | None = None,
|
|
220
240
|
**slice_kwargs: slice | int | Iterable[int],
|
|
@@ -256,7 +276,7 @@ def consolidate_image(
|
|
|
256
276
|
|
|
257
277
|
def get_roi_pipe(
|
|
258
278
|
image: AbstractImage,
|
|
259
|
-
roi:
|
|
279
|
+
roi: Roi,
|
|
260
280
|
axes_order: Collection[str] | None = None,
|
|
261
281
|
mode: Literal["numpy", "dask", "delayed"] = "numpy",
|
|
262
282
|
**slice_kwargs: slice | int | Iterable[int],
|
|
@@ -290,7 +310,7 @@ def get_roi_pipe(
|
|
|
290
310
|
|
|
291
311
|
def set_roi_pipe(
|
|
292
312
|
image: AbstractImage,
|
|
293
|
-
roi:
|
|
313
|
+
roi: Roi,
|
|
294
314
|
patch: ArrayLike,
|
|
295
315
|
axes_order: Collection[str] | None = None,
|
|
296
316
|
**slice_kwargs: slice | int | Iterable[int],
|
|
@@ -327,7 +347,7 @@ def build_image_roi_table(image: AbstractImage, name: str = "image") -> RoiTable
|
|
|
327
347
|
image.dimensions.get("y"),
|
|
328
348
|
image.dimensions.get("x"),
|
|
329
349
|
)
|
|
330
|
-
image_roi =
|
|
350
|
+
image_roi = RoiPixels(
|
|
331
351
|
name=name,
|
|
332
352
|
x=0,
|
|
333
353
|
y=0,
|
|
@@ -336,4 +356,4 @@ def build_image_roi_table(image: AbstractImage, name: str = "image") -> RoiTable
|
|
|
336
356
|
y_length=dim_y,
|
|
337
357
|
z_length=dim_z,
|
|
338
358
|
)
|
|
339
|
-
return RoiTable(rois=[image_roi.
|
|
359
|
+
return RoiTable(rois=[image_roi.to_roi(pixel_size=image.pixel_size)])
|
ngio/images/create.py
CHANGED
|
@@ -12,6 +12,10 @@ from ngio.ome_zarr_meta import (
|
|
|
12
12
|
get_label_meta_handler,
|
|
13
13
|
)
|
|
14
14
|
from ngio.ome_zarr_meta.ngio_specs import (
|
|
15
|
+
DefaultNgffVersion,
|
|
16
|
+
DefaultSpaceUnit,
|
|
17
|
+
DefaultTimeUnit,
|
|
18
|
+
NgffVersions,
|
|
15
19
|
SpaceUnits,
|
|
16
20
|
TimeUnits,
|
|
17
21
|
canonical_axes_order,
|
|
@@ -31,10 +35,10 @@ def _init_generic_meta(
|
|
|
31
35
|
levels: int | list[str] = 5,
|
|
32
36
|
yx_scaling_factor: float | tuple[float, float] = 2.0,
|
|
33
37
|
z_scaling_factor: float = 1.0,
|
|
34
|
-
space_unit: SpaceUnits | str | None =
|
|
35
|
-
time_unit: TimeUnits | str | None =
|
|
38
|
+
space_unit: SpaceUnits | str | None = DefaultSpaceUnit,
|
|
39
|
+
time_unit: TimeUnits | str | None = DefaultTimeUnit,
|
|
36
40
|
name: str | None = None,
|
|
37
|
-
version:
|
|
41
|
+
version: NgffVersions = DefaultNgffVersion,
|
|
38
42
|
) -> tuple[_image_or_label_meta, list[float]]:
|
|
39
43
|
"""Initialize the metadata for an image or label."""
|
|
40
44
|
scaling_factors = []
|
|
@@ -54,20 +58,6 @@ def _init_generic_meta(
|
|
|
54
58
|
else:
|
|
55
59
|
scaling_factors.append(1.0)
|
|
56
60
|
|
|
57
|
-
if space_unit is None:
|
|
58
|
-
space_unit = SpaceUnits.micrometer
|
|
59
|
-
elif isinstance(space_unit, str):
|
|
60
|
-
space_unit = SpaceUnits(space_unit)
|
|
61
|
-
elif not isinstance(space_unit, SpaceUnits):
|
|
62
|
-
raise NgioValueError(f"space_unit can not be {type(space_unit)}.")
|
|
63
|
-
|
|
64
|
-
if time_unit is None:
|
|
65
|
-
time_unit = TimeUnits.seconds
|
|
66
|
-
elif isinstance(time_unit, str):
|
|
67
|
-
time_unit = TimeUnits(time_unit)
|
|
68
|
-
elif not isinstance(time_unit, TimeUnits):
|
|
69
|
-
raise NgioValueError(f"time_units can not be {type(time_unit)}.")
|
|
70
|
-
|
|
71
61
|
pixel_sizes = PixelSize(
|
|
72
62
|
x=pixelsize,
|
|
73
63
|
y=pixelsize,
|
|
@@ -88,7 +78,7 @@ def _init_generic_meta(
|
|
|
88
78
|
return meta, scaling_factors
|
|
89
79
|
|
|
90
80
|
|
|
91
|
-
def
|
|
81
|
+
def create_empty_label_container(
|
|
92
82
|
store: StoreOrGroup,
|
|
93
83
|
shape: Collection[int],
|
|
94
84
|
pixelsize: float,
|
|
@@ -97,14 +87,14 @@ def _create_empty_label(
|
|
|
97
87
|
levels: int | list[str] = 5,
|
|
98
88
|
yx_scaling_factor: float | tuple[float, float] = 2.0,
|
|
99
89
|
z_scaling_factor: float = 1.0,
|
|
100
|
-
space_unit: SpaceUnits | str | None =
|
|
101
|
-
time_unit: TimeUnits | str | None =
|
|
90
|
+
space_unit: SpaceUnits | str | None = DefaultSpaceUnit,
|
|
91
|
+
time_unit: TimeUnits | str | None = DefaultTimeUnit,
|
|
102
92
|
axes_names: Collection[str] | None = None,
|
|
103
93
|
name: str | None = None,
|
|
104
94
|
chunks: Collection[int] | None = None,
|
|
105
95
|
dtype: str = "uint16",
|
|
106
96
|
overwrite: bool = False,
|
|
107
|
-
version:
|
|
97
|
+
version: NgffVersions = DefaultNgffVersion,
|
|
108
98
|
) -> ZarrGroupHandler:
|
|
109
99
|
"""Create an empty label with the given shape and metadata.
|
|
110
100
|
|
|
@@ -121,10 +111,10 @@ def _create_empty_label(
|
|
|
121
111
|
dimensions. Defaults to 2.0.
|
|
122
112
|
z_scaling_factor (float, optional): The down-scaling factor in z dimension.
|
|
123
113
|
Defaults to 1.0.
|
|
124
|
-
space_unit (SpaceUnits
|
|
125
|
-
|
|
126
|
-
time_unit (TimeUnits
|
|
127
|
-
|
|
114
|
+
space_unit (SpaceUnits, optional): The unit of space. Defaults to
|
|
115
|
+
DefaultSpaceUnit.
|
|
116
|
+
time_unit (TimeUnits, optional): The unit of time. Defaults to
|
|
117
|
+
DefaultTimeUnit.
|
|
128
118
|
axes_names (Collection[str] | None, optional): The names of the axes.
|
|
129
119
|
If None the canonical names are used. Defaults to None.
|
|
130
120
|
name (str | None, optional): The name of the image. Defaults to None.
|
|
@@ -134,7 +124,7 @@ def _create_empty_label(
|
|
|
134
124
|
overwrite (bool, optional): Whether to overwrite an existing image.
|
|
135
125
|
Defaults to True.
|
|
136
126
|
version (str, optional): The version of the OME-Zarr specification.
|
|
137
|
-
Defaults to
|
|
127
|
+
Defaults to DefaultVersion.
|
|
138
128
|
|
|
139
129
|
"""
|
|
140
130
|
if axes_names is None:
|
|
@@ -179,7 +169,7 @@ def _create_empty_label(
|
|
|
179
169
|
return group_handler
|
|
180
170
|
|
|
181
171
|
|
|
182
|
-
def
|
|
172
|
+
def create_empty_image_container(
|
|
183
173
|
store: StoreOrGroup,
|
|
184
174
|
shape: Collection[int],
|
|
185
175
|
pixelsize: float,
|
|
@@ -188,14 +178,14 @@ def _create_empty_image(
|
|
|
188
178
|
levels: int | list[str] = 5,
|
|
189
179
|
yx_scaling_factor: float | tuple[float, float] = 2,
|
|
190
180
|
z_scaling_factor: float = 1.0,
|
|
191
|
-
space_unit: SpaceUnits | str | None =
|
|
192
|
-
time_unit: TimeUnits | str | None =
|
|
181
|
+
space_unit: SpaceUnits | str | None = DefaultSpaceUnit,
|
|
182
|
+
time_unit: TimeUnits | str | None = DefaultTimeUnit,
|
|
193
183
|
axes_names: Collection[str] | None = None,
|
|
194
184
|
name: str | None = None,
|
|
195
185
|
chunks: Collection[int] | None = None,
|
|
196
186
|
dtype: str = "uint16",
|
|
197
187
|
overwrite: bool = False,
|
|
198
|
-
version:
|
|
188
|
+
version: NgffVersions = DefaultNgffVersion,
|
|
199
189
|
) -> ZarrGroupHandler:
|
|
200
190
|
"""Create an empty OME-Zarr image with the given shape and metadata.
|
|
201
191
|
|
|
@@ -212,10 +202,10 @@ def _create_empty_image(
|
|
|
212
202
|
dimensions. Defaults to 2.0.
|
|
213
203
|
z_scaling_factor (float, optional): The down-scaling factor in z dimension.
|
|
214
204
|
Defaults to 1.0.
|
|
215
|
-
space_unit (SpaceUnits
|
|
216
|
-
|
|
217
|
-
time_unit (TimeUnits
|
|
218
|
-
|
|
205
|
+
space_unit (SpaceUnits, optional): The unit of space. Defaults to
|
|
206
|
+
DefaultSpaceUnit.
|
|
207
|
+
time_unit (TimeUnits, optional): The unit of time. Defaults to
|
|
208
|
+
DefaultTimeUnit.
|
|
219
209
|
axes_names (Collection[str] | None, optional): The names of the axes.
|
|
220
210
|
If None the canonical names are used. Defaults to None.
|
|
221
211
|
name (str | None, optional): The name of the image. Defaults to None.
|
|
@@ -225,7 +215,7 @@ def _create_empty_image(
|
|
|
225
215
|
overwrite (bool, optional): Whether to overwrite an existing image.
|
|
226
216
|
Defaults to True.
|
|
227
217
|
version (str, optional): The version of the OME-Zarr specification.
|
|
228
|
-
Defaults to
|
|
218
|
+
Defaults to DefaultVersion.
|
|
229
219
|
|
|
230
220
|
"""
|
|
231
221
|
if axes_names is None:
|
ngio/images/image.py
CHANGED
|
@@ -7,14 +7,22 @@ from dask import array as da
|
|
|
7
7
|
|
|
8
8
|
from ngio.common import Dimensions
|
|
9
9
|
from ngio.images.abstract_image import AbstractImage, consolidate_image
|
|
10
|
-
from ngio.images.create import
|
|
10
|
+
from ngio.images.create import create_empty_image_container
|
|
11
11
|
from ngio.ome_zarr_meta import (
|
|
12
12
|
ImageMetaHandler,
|
|
13
13
|
NgioImageMeta,
|
|
14
14
|
PixelSize,
|
|
15
15
|
find_image_meta_handler,
|
|
16
16
|
)
|
|
17
|
-
from ngio.ome_zarr_meta.ngio_specs import
|
|
17
|
+
from ngio.ome_zarr_meta.ngio_specs import (
|
|
18
|
+
Channel,
|
|
19
|
+
ChannelsMeta,
|
|
20
|
+
ChannelVisualisation,
|
|
21
|
+
DefaultSpaceUnit,
|
|
22
|
+
DefaultTimeUnit,
|
|
23
|
+
SpaceUnits,
|
|
24
|
+
TimeUnits,
|
|
25
|
+
)
|
|
18
26
|
from ngio.utils import (
|
|
19
27
|
NgioValidationError,
|
|
20
28
|
StoreOrGroup,
|
|
@@ -55,7 +63,7 @@ class Image(AbstractImage[ImageMetaHandler]):
|
|
|
55
63
|
|
|
56
64
|
Args:
|
|
57
65
|
group_handler: The Zarr group handler.
|
|
58
|
-
path: The path to the image in the
|
|
66
|
+
path: The path to the image in the ome_zarr file.
|
|
59
67
|
meta_handler: The image metadata handler.
|
|
60
68
|
|
|
61
69
|
"""
|
|
@@ -142,7 +150,7 @@ class ImagesContainer:
|
|
|
142
150
|
image = self.get()
|
|
143
151
|
return image.wavelength_ids
|
|
144
152
|
|
|
145
|
-
def
|
|
153
|
+
def set_channel_meta(
|
|
146
154
|
self,
|
|
147
155
|
labels: Collection[str] | int | None = None,
|
|
148
156
|
wavelength_id: Collection[str] | None = None,
|
|
@@ -196,7 +204,7 @@ class ImagesContainer:
|
|
|
196
204
|
meta.set_channels_meta(channel_meta)
|
|
197
205
|
self._meta_handler.write_meta(meta)
|
|
198
206
|
|
|
199
|
-
def
|
|
207
|
+
def set_channel_percentiles(
|
|
200
208
|
self,
|
|
201
209
|
start_percentile: float = 0.1,
|
|
202
210
|
end_percentile: float = 99.9,
|
|
@@ -230,6 +238,21 @@ class ImagesContainer:
|
|
|
230
238
|
meta.set_channels_meta(new_meta)
|
|
231
239
|
self._meta_handler.write_meta(meta)
|
|
232
240
|
|
|
241
|
+
def set_axes_unit(
|
|
242
|
+
self,
|
|
243
|
+
space_unit: SpaceUnits = DefaultSpaceUnit,
|
|
244
|
+
time_unit: TimeUnits = DefaultTimeUnit,
|
|
245
|
+
) -> None:
|
|
246
|
+
"""Set the axes unit of the image.
|
|
247
|
+
|
|
248
|
+
Args:
|
|
249
|
+
space_unit (SpaceUnits): The space unit of the image.
|
|
250
|
+
time_unit (TimeUnits): The time unit of the image.
|
|
251
|
+
"""
|
|
252
|
+
meta = self.meta
|
|
253
|
+
meta = meta.to_units(space_unit=space_unit, time_unit=time_unit)
|
|
254
|
+
self._meta_handler.write_meta(meta)
|
|
255
|
+
|
|
233
256
|
def derive(
|
|
234
257
|
self,
|
|
235
258
|
store: StoreOrGroup,
|
|
@@ -238,6 +261,7 @@ class ImagesContainer:
|
|
|
238
261
|
labels: Collection[str] | None = None,
|
|
239
262
|
pixel_size: PixelSize | None = None,
|
|
240
263
|
axes_names: Collection[str] | None = None,
|
|
264
|
+
name: str | None = None,
|
|
241
265
|
chunks: Collection[int] | None = None,
|
|
242
266
|
dtype: str | None = None,
|
|
243
267
|
overwrite: bool = False,
|
|
@@ -252,6 +276,7 @@ class ImagesContainer:
|
|
|
252
276
|
labels (Collection[str] | None): The labels of the new image.
|
|
253
277
|
pixel_size (PixelSize | None): The pixel size of the new image.
|
|
254
278
|
axes_names (Collection[str] | None): The axes names of the new image.
|
|
279
|
+
name (str | None): The name of the new image.
|
|
255
280
|
chunks (Collection[int] | None): The chunk shape of the new image.
|
|
256
281
|
dtype (str | None): The data type of the new image.
|
|
257
282
|
overwrite (bool): Whether to overwrite an existing image.
|
|
@@ -267,6 +292,7 @@ class ImagesContainer:
|
|
|
267
292
|
labels=labels,
|
|
268
293
|
pixel_size=pixel_size,
|
|
269
294
|
axes_names=axes_names,
|
|
295
|
+
name=name,
|
|
270
296
|
chunks=chunks,
|
|
271
297
|
dtype=dtype,
|
|
272
298
|
overwrite=overwrite,
|
|
@@ -281,7 +307,7 @@ class ImagesContainer:
|
|
|
281
307
|
"""Get an image at a specific level.
|
|
282
308
|
|
|
283
309
|
Args:
|
|
284
|
-
path (str | None): The path to the image in the
|
|
310
|
+
path (str | None): The path to the image in the ome_zarr file.
|
|
285
311
|
pixel_size (PixelSize | None): The pixel size of the image.
|
|
286
312
|
strict (bool): Only used if the pixel size is provided. If True, the
|
|
287
313
|
pixel size must match the image pixel size exactly. If False, the
|
|
@@ -346,6 +372,7 @@ def derive_image_container(
|
|
|
346
372
|
labels: Collection[str] | None = None,
|
|
347
373
|
pixel_size: PixelSize | None = None,
|
|
348
374
|
axes_names: Collection[str] | None = None,
|
|
375
|
+
name: str | None = None,
|
|
349
376
|
chunks: Collection[int] | None = None,
|
|
350
377
|
dtype: str | None = None,
|
|
351
378
|
overwrite: bool = False,
|
|
@@ -360,6 +387,7 @@ def derive_image_container(
|
|
|
360
387
|
labels (Collection[str] | None): The labels of the new image.
|
|
361
388
|
pixel_size (PixelSize | None): The pixel size of the new image.
|
|
362
389
|
axes_names (Collection[str] | None): The axes names of the new image.
|
|
390
|
+
name (str | None): The name of the new image.
|
|
363
391
|
chunks (Collection[int] | None): The chunk shape of the new image.
|
|
364
392
|
dtype (str | None): The data type of the new image.
|
|
365
393
|
overwrite (bool): Whether to overwrite an existing image.
|
|
@@ -399,9 +427,12 @@ def derive_image_container(
|
|
|
399
427
|
f"Got {chunks} for shape {shape}."
|
|
400
428
|
)
|
|
401
429
|
|
|
430
|
+
if name is None:
|
|
431
|
+
name = ref_meta.name
|
|
432
|
+
|
|
402
433
|
if dtype is None:
|
|
403
434
|
dtype = ref_image.dtype
|
|
404
|
-
handler =
|
|
435
|
+
handler = create_empty_image_container(
|
|
405
436
|
store=store,
|
|
406
437
|
shape=shape,
|
|
407
438
|
pixelsize=pixel_size.x,
|
|
@@ -413,6 +444,7 @@ def derive_image_container(
|
|
|
413
444
|
time_unit=pixel_size.time_unit,
|
|
414
445
|
space_unit=pixel_size.space_unit,
|
|
415
446
|
axes_names=axes_names,
|
|
447
|
+
name=name,
|
|
416
448
|
chunks=chunks,
|
|
417
449
|
dtype=dtype,
|
|
418
450
|
overwrite=overwrite,
|
|
@@ -443,7 +475,7 @@ def derive_image_container(
|
|
|
443
475
|
)
|
|
444
476
|
_labels = labels
|
|
445
477
|
|
|
446
|
-
image_container.
|
|
478
|
+
image_container.set_channel_meta(
|
|
447
479
|
labels=_labels,
|
|
448
480
|
wavelength_id=wavelength_id,
|
|
449
481
|
percentiles=None,
|
ngio/images/label.py
CHANGED
|
@@ -5,7 +5,7 @@ from typing import Literal
|
|
|
5
5
|
|
|
6
6
|
from ngio.common import compute_masking_roi
|
|
7
7
|
from ngio.images.abstract_image import AbstractImage, consolidate_image
|
|
8
|
-
from ngio.images.create import
|
|
8
|
+
from ngio.images.create import create_empty_label_container
|
|
9
9
|
from ngio.images.image import Image
|
|
10
10
|
from ngio.ome_zarr_meta import (
|
|
11
11
|
LabelMetaHandler,
|
|
@@ -13,7 +13,13 @@ from ngio.ome_zarr_meta import (
|
|
|
13
13
|
PixelSize,
|
|
14
14
|
find_label_meta_handler,
|
|
15
15
|
)
|
|
16
|
-
from ngio.
|
|
16
|
+
from ngio.ome_zarr_meta.ngio_specs import (
|
|
17
|
+
DefaultSpaceUnit,
|
|
18
|
+
DefaultTimeUnit,
|
|
19
|
+
SpaceUnits,
|
|
20
|
+
TimeUnits,
|
|
21
|
+
)
|
|
22
|
+
from ngio.tables import MaskingRoiTable
|
|
17
23
|
from ngio.utils import (
|
|
18
24
|
NgioValidationError,
|
|
19
25
|
NgioValueError,
|
|
@@ -35,7 +41,7 @@ class Label(AbstractImage[LabelMetaHandler]):
|
|
|
35
41
|
|
|
36
42
|
Args:
|
|
37
43
|
group_handler: The Zarr group handler.
|
|
38
|
-
path: The path to the image in the
|
|
44
|
+
path: The path to the image in the ome_zarr file.
|
|
39
45
|
meta_handler: The image metadata handler.
|
|
40
46
|
|
|
41
47
|
"""
|
|
@@ -45,12 +51,31 @@ class Label(AbstractImage[LabelMetaHandler]):
|
|
|
45
51
|
group_handler=group_handler, path=path, meta_handler=meta_handler
|
|
46
52
|
)
|
|
47
53
|
|
|
54
|
+
def __repr__(self) -> str:
|
|
55
|
+
"""Return the string representation of the label."""
|
|
56
|
+
return f"Label(path={self.path}, {self.dimensions})"
|
|
57
|
+
|
|
48
58
|
@property
|
|
49
59
|
def meta(self) -> NgioLabelMeta:
|
|
50
60
|
"""Return the metadata."""
|
|
51
61
|
return self._meta_handler.meta
|
|
52
62
|
|
|
53
|
-
def
|
|
63
|
+
def set_axes_unit(
|
|
64
|
+
self,
|
|
65
|
+
space_unit: SpaceUnits = DefaultSpaceUnit,
|
|
66
|
+
time_unit: TimeUnits = DefaultTimeUnit,
|
|
67
|
+
) -> None:
|
|
68
|
+
"""Set the axes unit of the image.
|
|
69
|
+
|
|
70
|
+
Args:
|
|
71
|
+
space_unit (SpaceUnits): The space unit of the image.
|
|
72
|
+
time_unit (TimeUnits): The time unit of the image.
|
|
73
|
+
"""
|
|
74
|
+
meta = self.meta
|
|
75
|
+
meta = meta.to_units(space_unit=space_unit, time_unit=time_unit)
|
|
76
|
+
self._meta_handler.write_meta(meta)
|
|
77
|
+
|
|
78
|
+
def build_masking_roi_table(self) -> MaskingRoiTable:
|
|
54
79
|
"""Compute the masking ROI table."""
|
|
55
80
|
return build_masking_roi_table(self)
|
|
56
81
|
|
|
@@ -101,7 +126,7 @@ class LabelsContainer:
|
|
|
101
126
|
|
|
102
127
|
Args:
|
|
103
128
|
name (str): The name of the label.
|
|
104
|
-
path (str | None): The path to the image in the
|
|
129
|
+
path (str | None): The path to the image in the ome_zarr file.
|
|
105
130
|
pixel_size (PixelSize | None): The pixel size of the image.
|
|
106
131
|
strict (bool): Only used if the pixel size is provided. If True, the
|
|
107
132
|
pixel size must match the image pixel size exactly. If False, the
|
|
@@ -249,7 +274,7 @@ def _derive_label(
|
|
|
249
274
|
axes_names = list(axes_names)
|
|
250
275
|
axes_names = axes_names[:c_axis] + axes_names[c_axis + 1 :]
|
|
251
276
|
|
|
252
|
-
_ =
|
|
277
|
+
_ = create_empty_label_container(
|
|
253
278
|
store=store,
|
|
254
279
|
shape=shape,
|
|
255
280
|
pixelsize=ref_image.pixel_size.x,
|
|
@@ -270,7 +295,7 @@ def _derive_label(
|
|
|
270
295
|
return None
|
|
271
296
|
|
|
272
297
|
|
|
273
|
-
def build_masking_roi_table(label: Label) ->
|
|
298
|
+
def build_masking_roi_table(label: Label) -> MaskingRoiTable:
|
|
274
299
|
"""Compute the masking ROI table for a label."""
|
|
275
300
|
if label.dimensions.is_time_series:
|
|
276
301
|
raise NgioValueError("Time series labels are not supported.")
|
|
@@ -278,4 +303,4 @@ def build_masking_roi_table(label: Label) -> MaskingROITable:
|
|
|
278
303
|
array = label.get_array(axes_order=["z", "y", "x"], mode="dask")
|
|
279
304
|
|
|
280
305
|
rois = compute_masking_roi(array, label.pixel_size)
|
|
281
|
-
return
|
|
306
|
+
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,
|