ngio 0.2.0a1__py3-none-any.whl → 0.2.0a3__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/common/_pyramid.py +1 -0
- ngio/images/image.py +30 -13
- ngio/images/label.py +174 -6
- ngio/images/omezarr_container.py +74 -15
- ngio/ome_zarr_meta/ngio_specs/_ngio_image.py +19 -8
- ngio/utils/__init__.py +3 -0
- ngio/utils/_datasets.py +1 -1
- ngio/utils/_fractal_fsspec_store.py +12 -0
- {ngio-0.2.0a1.dist-info → ngio-0.2.0a3.dist-info}/METADATA +1 -1
- {ngio-0.2.0a1.dist-info → ngio-0.2.0a3.dist-info}/RECORD +12 -11
- {ngio-0.2.0a1.dist-info → ngio-0.2.0a3.dist-info}/WHEEL +0 -0
- {ngio-0.2.0a1.dist-info → ngio-0.2.0a3.dist-info}/licenses/LICENSE +0 -0
ngio/common/_pyramid.py
CHANGED
ngio/images/image.py
CHANGED
|
@@ -170,17 +170,20 @@ class ImagesContainer:
|
|
|
170
170
|
be shown by default.
|
|
171
171
|
omero_kwargs(dict): Extra fields to store in the omero attributes.
|
|
172
172
|
"""
|
|
173
|
-
|
|
173
|
+
low_res_dataset = self.meta.get_lowest_resolution_dataset()
|
|
174
|
+
ref_image = self.get(path=low_res_dataset.path)
|
|
174
175
|
|
|
175
176
|
if percentiles is not None:
|
|
176
177
|
start, end = compute_image_percentile(
|
|
177
|
-
|
|
178
|
+
ref_image,
|
|
179
|
+
start_percentile=percentiles[0],
|
|
180
|
+
end_percentile=percentiles[1],
|
|
178
181
|
)
|
|
179
182
|
else:
|
|
180
183
|
start, end = None, None
|
|
181
184
|
|
|
182
185
|
if labels is None:
|
|
183
|
-
labels =
|
|
186
|
+
labels = ref_image.num_channels
|
|
184
187
|
|
|
185
188
|
channel_meta = ChannelsMeta.default_init(
|
|
186
189
|
labels=labels,
|
|
@@ -189,7 +192,7 @@ class ImagesContainer:
|
|
|
189
192
|
start=start,
|
|
190
193
|
end=end,
|
|
191
194
|
active=active,
|
|
192
|
-
data_type=
|
|
195
|
+
data_type=ref_image.dtype,
|
|
193
196
|
**omero_kwargs,
|
|
194
197
|
)
|
|
195
198
|
|
|
@@ -206,9 +209,10 @@ class ImagesContainer:
|
|
|
206
209
|
if self.meta._channels_meta is None:
|
|
207
210
|
raise NgioValidationError("The channels meta is not initialized.")
|
|
208
211
|
|
|
209
|
-
|
|
212
|
+
low_res_dataset = self.meta.get_lowest_resolution_dataset()
|
|
213
|
+
ref_image = self.get(path=low_res_dataset.path)
|
|
210
214
|
starts, ends = compute_image_percentile(
|
|
211
|
-
|
|
215
|
+
ref_image, start_percentile=start_percentile, end_percentile=end_percentile
|
|
212
216
|
)
|
|
213
217
|
|
|
214
218
|
channels = []
|
|
@@ -236,6 +240,8 @@ class ImagesContainer:
|
|
|
236
240
|
ref_path: str | None = None,
|
|
237
241
|
shape: Collection[int] | None = None,
|
|
238
242
|
chunks: Collection[int] | None = None,
|
|
243
|
+
xy_scaling_factor: float = 2.0,
|
|
244
|
+
z_scaling_factor: float = 1.0,
|
|
239
245
|
overwrite: bool = False,
|
|
240
246
|
) -> "ImagesContainer":
|
|
241
247
|
"""Create an OME-Zarr image from a numpy array."""
|
|
@@ -245,6 +251,8 @@ class ImagesContainer:
|
|
|
245
251
|
ref_path=ref_path,
|
|
246
252
|
shape=shape,
|
|
247
253
|
chunks=chunks,
|
|
254
|
+
xy_scaling_factor=xy_scaling_factor,
|
|
255
|
+
z_scaling_factor=z_scaling_factor,
|
|
248
256
|
overwrite=overwrite,
|
|
249
257
|
)
|
|
250
258
|
|
|
@@ -252,13 +260,20 @@ class ImagesContainer:
|
|
|
252
260
|
self,
|
|
253
261
|
path: str | None = None,
|
|
254
262
|
pixel_size: PixelSize | None = None,
|
|
255
|
-
|
|
263
|
+
strict: bool = False,
|
|
256
264
|
) -> Image:
|
|
257
|
-
"""Get an image at a specific level.
|
|
258
|
-
|
|
259
|
-
|
|
265
|
+
"""Get an image at a specific level.
|
|
266
|
+
|
|
267
|
+
Args:
|
|
268
|
+
path (str | None): The path to the image in the omezarr file.
|
|
269
|
+
pixel_size (PixelSize | None): The pixel size of the image.
|
|
270
|
+
strict (bool): Only used if the pixel size is provided. If True, the
|
|
271
|
+
pixel size must match the image pixel size exactly. If False, the
|
|
272
|
+
closest pixel size level will be returned.
|
|
273
|
+
|
|
274
|
+
"""
|
|
260
275
|
dataset = self._meta_handler.meta.get_dataset(
|
|
261
|
-
path=path, pixel_size=pixel_size,
|
|
276
|
+
path=path, pixel_size=pixel_size, strict=strict
|
|
262
277
|
)
|
|
263
278
|
return Image(
|
|
264
279
|
group_handler=self._group_handler,
|
|
@@ -314,6 +329,8 @@ def derive_image_container(
|
|
|
314
329
|
ref_path: str | None = None,
|
|
315
330
|
shape: Collection[int] | None = None,
|
|
316
331
|
chunks: Collection[int] | None = None,
|
|
332
|
+
xy_scaling_factor: float = 2.0,
|
|
333
|
+
z_scaling_factor: float = 1.0,
|
|
317
334
|
overwrite: bool = False,
|
|
318
335
|
) -> ImagesContainer:
|
|
319
336
|
"""Create an OME-Zarr image from a numpy array."""
|
|
@@ -347,8 +364,8 @@ def derive_image_container(
|
|
|
347
364
|
z_spacing=ref_image.pixel_size.z,
|
|
348
365
|
time_spacing=ref_image.pixel_size.t,
|
|
349
366
|
levels=ref_meta.levels,
|
|
350
|
-
xy_scaling_factor=
|
|
351
|
-
z_scaling_factor=
|
|
367
|
+
xy_scaling_factor=xy_scaling_factor,
|
|
368
|
+
z_scaling_factor=z_scaling_factor,
|
|
352
369
|
time_unit=ref_image.pixel_size.time_unit,
|
|
353
370
|
space_unit=ref_image.pixel_size.space_unit,
|
|
354
371
|
axes_names=ref_image.dataset.axes_mapper.on_disk_axes_names,
|
ngio/images/label.py
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
"""A module for handling label images in OME-NGFF files."""
|
|
2
2
|
|
|
3
|
+
from collections.abc import Collection
|
|
3
4
|
from typing import Literal
|
|
4
5
|
|
|
5
6
|
from ngio.images.abstract_image import AbstractImage, consolidate_image
|
|
7
|
+
from ngio.images.create import _create_empty_label
|
|
8
|
+
from ngio.images.image import Image
|
|
6
9
|
from ngio.ome_zarr_meta import (
|
|
7
10
|
ImplementedLabelMetaHandlers,
|
|
8
11
|
LabelMetaHandler,
|
|
9
12
|
NgioLabelMeta,
|
|
13
|
+
PixelSize,
|
|
10
14
|
)
|
|
15
|
+
from ngio.ome_zarr_meta.ngio_specs import SpaceUnits, TimeUnits
|
|
11
16
|
from ngio.utils import (
|
|
12
17
|
NgioValidationError,
|
|
18
|
+
NgioValueError,
|
|
19
|
+
StoreOrGroup,
|
|
13
20
|
ZarrGroupHandler,
|
|
14
21
|
)
|
|
15
22
|
|
|
@@ -80,17 +87,178 @@ class LabelsContainer:
|
|
|
80
87
|
attrs = self._group_handler.load_attrs()
|
|
81
88
|
return attrs.get("labels", [])
|
|
82
89
|
|
|
83
|
-
def
|
|
90
|
+
def _get(self, name: str, path: str) -> Label:
|
|
84
91
|
"""Get a label from the group."""
|
|
85
92
|
group_handler = self._group_handler.derive_handler(name)
|
|
86
93
|
return Label(group_handler, path, None)
|
|
87
94
|
|
|
95
|
+
def get(
|
|
96
|
+
self,
|
|
97
|
+
name: str,
|
|
98
|
+
path: str | None = None,
|
|
99
|
+
pixel_size: PixelSize | None = None,
|
|
100
|
+
strict: bool = False,
|
|
101
|
+
) -> Label:
|
|
102
|
+
"""Get a label from the group.
|
|
103
|
+
|
|
104
|
+
Args:
|
|
105
|
+
name (str): The name of the label.
|
|
106
|
+
path (str | None): The path to the image in the omezarr file.
|
|
107
|
+
pixel_size (PixelSize | None): The pixel size of the image.
|
|
108
|
+
strict (bool): Only used if the pixel size is provided. If True, the
|
|
109
|
+
pixel size must match the image pixel size exactly. If False, the
|
|
110
|
+
closest pixel size level will be returned.
|
|
111
|
+
|
|
112
|
+
"""
|
|
113
|
+
group_handler = self._group_handler.derive_handler(name)
|
|
114
|
+
label_meta_handler = ImplementedLabelMetaHandlers().find_meta_handler(
|
|
115
|
+
group_handler
|
|
116
|
+
)
|
|
117
|
+
path = label_meta_handler.meta.get_dataset(
|
|
118
|
+
path=path, pixel_size=pixel_size, strict=strict
|
|
119
|
+
).path
|
|
120
|
+
return Label(group_handler, path, label_meta_handler)
|
|
121
|
+
|
|
88
122
|
def derive(
|
|
89
123
|
self,
|
|
90
124
|
name: str,
|
|
91
|
-
|
|
125
|
+
ref_image: Image,
|
|
126
|
+
shape: Collection[int] | None = None,
|
|
127
|
+
chunks: Collection[int] | None = None,
|
|
128
|
+
dtype: str = "uint16",
|
|
129
|
+
xy_scaling_factor=2.0,
|
|
130
|
+
z_scaling_factor=1.0,
|
|
92
131
|
overwrite: bool = False,
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
132
|
+
) -> None:
|
|
133
|
+
"""Add a label to the group."""
|
|
134
|
+
existing_labels = self.list()
|
|
135
|
+
if name in existing_labels and not overwrite:
|
|
136
|
+
raise NgioValueError(
|
|
137
|
+
f"Table '{name}' already exists in the group. "
|
|
138
|
+
"Use overwrite=True to replace it."
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
label_group = self._group_handler.get_group(name, create_mode=True)
|
|
142
|
+
|
|
143
|
+
_derive_label(
|
|
144
|
+
ref_image=ref_image,
|
|
145
|
+
store=label_group,
|
|
146
|
+
shape=shape,
|
|
147
|
+
chunks=chunks,
|
|
148
|
+
dtype=dtype,
|
|
149
|
+
xy_scaling_factor=xy_scaling_factor,
|
|
150
|
+
z_scaling_factor=z_scaling_factor,
|
|
151
|
+
overwrite=overwrite,
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
if name not in existing_labels:
|
|
155
|
+
existing_labels.append(name)
|
|
156
|
+
self._group_handler.write_attrs({"labels": existing_labels})
|
|
157
|
+
|
|
158
|
+
def new(
|
|
159
|
+
self,
|
|
160
|
+
name: str,
|
|
161
|
+
shape: Collection[int],
|
|
162
|
+
xy_pixelsize: float,
|
|
163
|
+
z_spacing: float = 1.0,
|
|
164
|
+
time_spacing: float = 1.0,
|
|
165
|
+
levels: "int | list[str]" = 5,
|
|
166
|
+
xy_scaling_factor: float = 2.0,
|
|
167
|
+
z_scaling_factor: float = 1.0,
|
|
168
|
+
space_unit: SpaceUnits | str | None = None,
|
|
169
|
+
time_unit: TimeUnits | str | None = None,
|
|
170
|
+
axes_names: Collection[str] | None = None,
|
|
171
|
+
chunks: Collection[int] | None = None,
|
|
172
|
+
dtype: str = "uint16",
|
|
173
|
+
overwrite: bool = False,
|
|
174
|
+
version: str = "0.4",
|
|
175
|
+
) -> None:
|
|
176
|
+
"""Add a label to the group."""
|
|
177
|
+
existing_labels = self.list()
|
|
178
|
+
if name in existing_labels and not overwrite:
|
|
179
|
+
raise NgioValueError(
|
|
180
|
+
f"Table '{name}' already exists in the group. "
|
|
181
|
+
"Use overwrite=True to replace it."
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
label_group = self._group_handler.get_group(name, create_mode=True)
|
|
185
|
+
|
|
186
|
+
_create_empty_label(
|
|
187
|
+
store=label_group,
|
|
188
|
+
shape=shape,
|
|
189
|
+
xy_pixelsize=xy_pixelsize,
|
|
190
|
+
z_spacing=z_spacing,
|
|
191
|
+
time_spacing=time_spacing,
|
|
192
|
+
levels=levels,
|
|
193
|
+
xy_scaling_factor=xy_scaling_factor,
|
|
194
|
+
z_scaling_factor=z_scaling_factor,
|
|
195
|
+
space_unit=space_unit,
|
|
196
|
+
time_unit=time_unit,
|
|
197
|
+
axes_names=axes_names,
|
|
198
|
+
chunks=chunks,
|
|
199
|
+
dtype=dtype,
|
|
200
|
+
overwrite=overwrite,
|
|
201
|
+
version=version,
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
if name not in existing_labels:
|
|
205
|
+
existing_labels.append(name)
|
|
206
|
+
self._group_handler.write_attrs({"labels": existing_labels})
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def _derive_label(
|
|
210
|
+
ref_image: Image,
|
|
211
|
+
store: StoreOrGroup,
|
|
212
|
+
shape: Collection[int] | None = None,
|
|
213
|
+
chunks: Collection[int] | None = None,
|
|
214
|
+
dtype: str = "uint16",
|
|
215
|
+
xy_scaling_factor=2.0,
|
|
216
|
+
z_scaling_factor=1.0,
|
|
217
|
+
overwrite: bool = False,
|
|
218
|
+
) -> None:
|
|
219
|
+
"""Create an OME-Zarr image from a numpy array."""
|
|
220
|
+
ref_meta = ref_image.meta
|
|
221
|
+
# remove channls if present
|
|
222
|
+
shape_ref = ref_image.shape
|
|
223
|
+
chunks_ref = ref_image.chunks
|
|
224
|
+
axes_names_ref = ref_image.dataset.axes_mapper.on_disk_axes_names
|
|
225
|
+
c_axis = ref_image.dataset.axes_mapper.get_index("c")
|
|
226
|
+
if c_axis is not None:
|
|
227
|
+
shape_ref = shape_ref[:c_axis] + shape_ref[c_axis + 1 :]
|
|
228
|
+
chunks_ref = chunks_ref[:c_axis] + chunks_ref[c_axis + 1 :]
|
|
229
|
+
axes_names_ref = axes_names_ref[:c_axis] + axes_names_ref[c_axis + 1 :]
|
|
230
|
+
|
|
231
|
+
if shape is None:
|
|
232
|
+
shape = shape_ref
|
|
233
|
+
|
|
234
|
+
if chunks is None:
|
|
235
|
+
chunks = chunks_ref
|
|
236
|
+
|
|
237
|
+
if len(shape) != len(shape_ref):
|
|
238
|
+
raise NgioValidationError(
|
|
239
|
+
"The shape of the new image does not match the reference image."
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
if len(chunks) != len(chunks_ref):
|
|
243
|
+
raise NgioValidationError(
|
|
244
|
+
"The chunks of the new image does not match the reference image."
|
|
245
|
+
)
|
|
246
|
+
|
|
247
|
+
_ = _create_empty_label(
|
|
248
|
+
store=store,
|
|
249
|
+
shape=shape,
|
|
250
|
+
xy_pixelsize=ref_image.pixel_size.x,
|
|
251
|
+
z_spacing=ref_image.pixel_size.z,
|
|
252
|
+
time_spacing=ref_image.pixel_size.t,
|
|
253
|
+
levels=ref_meta.levels,
|
|
254
|
+
xy_scaling_factor=xy_scaling_factor,
|
|
255
|
+
z_scaling_factor=z_scaling_factor,
|
|
256
|
+
time_unit=ref_image.pixel_size.time_unit,
|
|
257
|
+
space_unit=ref_image.pixel_size.space_unit,
|
|
258
|
+
axes_names=axes_names_ref,
|
|
259
|
+
chunks=chunks,
|
|
260
|
+
dtype=dtype,
|
|
261
|
+
overwrite=overwrite,
|
|
262
|
+
version=ref_meta.version,
|
|
263
|
+
)
|
|
264
|
+
return None
|
ngio/images/omezarr_container.py
CHANGED
|
@@ -160,13 +160,20 @@ class OmeZarrContainer:
|
|
|
160
160
|
self,
|
|
161
161
|
path: str | None = None,
|
|
162
162
|
pixel_size: PixelSize | None = None,
|
|
163
|
-
|
|
163
|
+
strict: bool = False,
|
|
164
164
|
) -> Image:
|
|
165
|
-
"""Get an image at a specific level.
|
|
165
|
+
"""Get an image at a specific level.
|
|
166
|
+
|
|
167
|
+
Args:
|
|
168
|
+
path (str | None): The path to the image in the omezarr file.
|
|
169
|
+
pixel_size (PixelSize | None): The pixel size of the image.
|
|
170
|
+
strict (bool): Only used if the pixel size is provided. If True, the
|
|
171
|
+
pixel size must match the image pixel size exactly. If False, the
|
|
172
|
+
closest pixel size level will be returned.
|
|
173
|
+
|
|
174
|
+
"""
|
|
166
175
|
return self._images_container.get(
|
|
167
|
-
path=path,
|
|
168
|
-
pixel_size=pixel_size,
|
|
169
|
-
highest_resolution=highest_resolution,
|
|
176
|
+
path=path, pixel_size=pixel_size, strict=strict
|
|
170
177
|
)
|
|
171
178
|
|
|
172
179
|
def derive_image(
|
|
@@ -175,6 +182,8 @@ class OmeZarrContainer:
|
|
|
175
182
|
ref_path: str | None = None,
|
|
176
183
|
shape: Collection[int] | None = None,
|
|
177
184
|
chunks: Collection[int] | None = None,
|
|
185
|
+
xy_scaling_factor: float = 2.0,
|
|
186
|
+
z_scaling_factor: float = 1.0,
|
|
178
187
|
copy_tables: bool = False,
|
|
179
188
|
copy_labels: bool = False,
|
|
180
189
|
overwrite: bool = False,
|
|
@@ -191,6 +200,8 @@ class OmeZarrContainer:
|
|
|
191
200
|
ref_path=ref_path,
|
|
192
201
|
shape=shape,
|
|
193
202
|
chunks=chunks,
|
|
203
|
+
xy_scaling_factor=xy_scaling_factor,
|
|
204
|
+
z_scaling_factor=z_scaling_factor,
|
|
194
205
|
overwrite=overwrite,
|
|
195
206
|
)
|
|
196
207
|
return OmeZarrContainer(
|
|
@@ -275,21 +286,57 @@ class OmeZarrContainer:
|
|
|
275
286
|
return []
|
|
276
287
|
return self._labels_container.list()
|
|
277
288
|
|
|
278
|
-
def get_label(
|
|
279
|
-
|
|
289
|
+
def get_label(
|
|
290
|
+
self,
|
|
291
|
+
name: str,
|
|
292
|
+
path: str | None = None,
|
|
293
|
+
pixel_size: PixelSize | None = None,
|
|
294
|
+
strict: bool = False,
|
|
295
|
+
) -> Label:
|
|
296
|
+
"""Get a label from the group.
|
|
297
|
+
|
|
298
|
+
Args:
|
|
299
|
+
name (str): The name of the label.
|
|
300
|
+
path (str | None): The path to the image in the omezarr file.
|
|
301
|
+
pixel_size (PixelSize | None): The pixel size of the image.
|
|
302
|
+
strict (bool): Only used if the pixel size is provided. If True, the
|
|
303
|
+
pixel size must match the image pixel size exactly. If False, the
|
|
304
|
+
closest pixel size level will be returned.
|
|
305
|
+
"""
|
|
280
306
|
if self._labels_container is None:
|
|
281
307
|
raise NgioValidationError("No labels found in the image.")
|
|
282
|
-
return self._labels_container.get(
|
|
308
|
+
return self._labels_container.get(
|
|
309
|
+
name=name, path=path, pixel_size=pixel_size, strict=strict
|
|
310
|
+
)
|
|
283
311
|
|
|
284
|
-
def derive_label(
|
|
312
|
+
def derive_label(
|
|
313
|
+
self,
|
|
314
|
+
name: str,
|
|
315
|
+
ref_image: Image | None = None,
|
|
316
|
+
shape: Collection[int] | None = None,
|
|
317
|
+
chunks: Collection[int] | None = None,
|
|
318
|
+
dtype: str = "uint16",
|
|
319
|
+
xy_scaling_factor=2.0,
|
|
320
|
+
z_scaling_factor=1.0,
|
|
321
|
+
overwrite: bool = False,
|
|
322
|
+
) -> Label:
|
|
285
323
|
"""Derive a label from an image."""
|
|
286
324
|
if self._labels_container is None:
|
|
287
325
|
raise NgioValidationError("No labels found in the image.")
|
|
288
326
|
|
|
289
|
-
ref_image
|
|
290
|
-
|
|
291
|
-
|
|
327
|
+
if ref_image is None:
|
|
328
|
+
ref_image = self.get_image()
|
|
329
|
+
self._labels_container.derive(
|
|
330
|
+
name=name,
|
|
331
|
+
ref_image=ref_image,
|
|
332
|
+
shape=shape,
|
|
333
|
+
chunks=chunks,
|
|
334
|
+
dtype=dtype,
|
|
335
|
+
xy_scaling_factor=xy_scaling_factor,
|
|
336
|
+
z_scaling_factor=z_scaling_factor,
|
|
337
|
+
overwrite=overwrite,
|
|
292
338
|
)
|
|
339
|
+
return self.get_label(name, path="0")
|
|
293
340
|
|
|
294
341
|
|
|
295
342
|
def open_omezarr_container(
|
|
@@ -311,17 +358,29 @@ def open_image(
|
|
|
311
358
|
store: StoreOrGroup,
|
|
312
359
|
path: str | None = None,
|
|
313
360
|
pixel_size: PixelSize | None = None,
|
|
314
|
-
|
|
361
|
+
strict: bool = True,
|
|
315
362
|
cache: bool = False,
|
|
316
363
|
mode: AccessModeLiteral = "r+",
|
|
317
364
|
) -> Image:
|
|
318
|
-
"""Open a single level image from an OME-Zarr image.
|
|
365
|
+
"""Open a single level image from an OME-Zarr image.
|
|
366
|
+
|
|
367
|
+
Args:
|
|
368
|
+
store (StoreOrGroup): The Zarr store or group to create the image in.
|
|
369
|
+
path (str | None): The path to the image in the omezarr file.
|
|
370
|
+
pixel_size (PixelSize | None): The pixel size of the image.
|
|
371
|
+
strict (bool): Only used if the pixel size is provided. If True, the
|
|
372
|
+
pixel size must match the image pixel size exactly. If False, the
|
|
373
|
+
closest pixel size level will be returned.
|
|
374
|
+
cache (bool): Whether to use a cache for the zarr group metadata.
|
|
375
|
+
mode (AccessModeLiteral): The
|
|
376
|
+
access mode for the image. Defaults to "r+".
|
|
377
|
+
"""
|
|
319
378
|
group_handler = ZarrGroupHandler(store, cache, mode)
|
|
320
379
|
images_container = ImagesContainer(group_handler)
|
|
321
380
|
return images_container.get(
|
|
322
381
|
path=path,
|
|
323
382
|
pixel_size=pixel_size,
|
|
324
|
-
|
|
383
|
+
strict=strict,
|
|
325
384
|
)
|
|
326
385
|
|
|
327
386
|
|
|
@@ -138,16 +138,16 @@ class AbstractNgioImageMeta:
|
|
|
138
138
|
path: str | None = None,
|
|
139
139
|
idx: int | None = None,
|
|
140
140
|
pixel_size: PixelSize | None = None,
|
|
141
|
-
highest_resolution: bool = False,
|
|
142
141
|
strict: bool = False,
|
|
143
142
|
) -> Dataset:
|
|
144
143
|
"""Get a dataset by its path, index or pixel size.
|
|
145
144
|
|
|
145
|
+
If all arguments are None, the dataset with the highest resolution is returned.
|
|
146
|
+
|
|
146
147
|
Args:
|
|
147
148
|
path(str): The path of the dataset.
|
|
148
149
|
idx(int): The index of the dataset.
|
|
149
150
|
pixel_size(PixelSize): The pixel size to search for.
|
|
150
|
-
highest_resolution(bool): If True, the dataset with the highest resolution
|
|
151
151
|
strict(bool): If True, the pixel size must be exactly the same.
|
|
152
152
|
If pixel_size is None, strict is ignored.
|
|
153
153
|
"""
|
|
@@ -158,12 +158,11 @@ class AbstractNgioImageMeta:
|
|
|
158
158
|
path is not None,
|
|
159
159
|
idx is not None,
|
|
160
160
|
pixel_size is not None,
|
|
161
|
-
highest_resolution,
|
|
162
161
|
]
|
|
163
162
|
)
|
|
164
|
-
|
|
163
|
+
> 1
|
|
165
164
|
):
|
|
166
|
-
raise NgioValueError("get_dataset must receive only one argument.")
|
|
165
|
+
raise NgioValueError("get_dataset must receive only one argument or None.")
|
|
167
166
|
|
|
168
167
|
if path is not None:
|
|
169
168
|
return self._get_dataset_by_path(path)
|
|
@@ -171,10 +170,8 @@ class AbstractNgioImageMeta:
|
|
|
171
170
|
return self._get_dataset_by_index(idx)
|
|
172
171
|
elif pixel_size is not None:
|
|
173
172
|
return self._get_dataset_by_pixel_size(pixel_size, strict=strict)
|
|
174
|
-
elif highest_resolution:
|
|
175
|
-
return self.get_highest_resolution_dataset()
|
|
176
173
|
else:
|
|
177
|
-
|
|
174
|
+
return self.get_highest_resolution_dataset()
|
|
178
175
|
|
|
179
176
|
@classmethod
|
|
180
177
|
def default_init(
|
|
@@ -237,6 +234,20 @@ class AbstractNgioImageMeta:
|
|
|
237
234
|
strict=False,
|
|
238
235
|
)
|
|
239
236
|
|
|
237
|
+
def get_lowest_resolution_dataset(self) -> Dataset:
|
|
238
|
+
"""Get the dataset with the lowest resolution."""
|
|
239
|
+
return self._get_dataset_by_pixel_size(
|
|
240
|
+
pixel_size=PixelSize(
|
|
241
|
+
x=1000.0,
|
|
242
|
+
y=1000.0,
|
|
243
|
+
z=1000.0,
|
|
244
|
+
t=1000.0,
|
|
245
|
+
space_unit=SpaceUnits.micrometer,
|
|
246
|
+
time_unit=TimeUnits.s,
|
|
247
|
+
),
|
|
248
|
+
strict=False,
|
|
249
|
+
)
|
|
250
|
+
|
|
240
251
|
def get_scaling_factor(self, axis_name: str) -> float:
|
|
241
252
|
"""Get the scaling factors of the dataset."""
|
|
242
253
|
scaling_factors = []
|
ngio/utils/__init__.py
CHANGED
|
@@ -11,6 +11,7 @@ from ngio.utils._errors import (
|
|
|
11
11
|
NgioValidationError,
|
|
12
12
|
NgioValueError,
|
|
13
13
|
)
|
|
14
|
+
from ngio.utils._fractal_fsspec_store import fractal_fsspec_store
|
|
14
15
|
from ngio.utils._logger import ngio_logger, set_logger_level
|
|
15
16
|
from ngio.utils._zarr_utils import (
|
|
16
17
|
AccessModeLiteral,
|
|
@@ -35,6 +36,8 @@ __all__ = [
|
|
|
35
36
|
"ZarrGroupHandler",
|
|
36
37
|
# Datasets
|
|
37
38
|
"download_ome_zarr_dataset",
|
|
39
|
+
# Fractal
|
|
40
|
+
"fractal_fsspec_store",
|
|
38
41
|
"list_ome_zarr_datasets",
|
|
39
42
|
# Logger
|
|
40
43
|
"ngio_logger",
|
ngio/utils/_datasets.py
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import fsspec.implementations.http
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def fractal_fsspec_store(
|
|
5
|
+
url: str, fractal_token: str, client_kwargs: dict | None = None
|
|
6
|
+
) -> fsspec.mapping.FSMap:
|
|
7
|
+
"""Simple function to get an http fsspec store from a url."""
|
|
8
|
+
client_kwargs = {} if client_kwargs is None else client_kwargs
|
|
9
|
+
client_kwargs["headers"] = {"Authorization": f"Bearer {fractal_token}"}
|
|
10
|
+
fs = fsspec.implementations.http.HTTPFileSystem(client_kwargs=client_kwargs)
|
|
11
|
+
store = fs.get_mapper(url)
|
|
12
|
+
return store
|
|
@@ -4,7 +4,7 @@ ngio/common/_array_pipe.py,sha256=DyYjGTy2L74zBtD6S2jGPsFG4zj7KaY39TwPGWsSf8g,48
|
|
|
4
4
|
ngio/common/_axes_transforms.py,sha256=Dmrta3ZT1IgZAWomdUeTZVje8TBF_oU3RMKBv1r4EvM,1989
|
|
5
5
|
ngio/common/_common_types.py,sha256=OkAYNSNjZkixL1MI-HPBVuXamheFBr862uJ4PvTxmhk,129
|
|
6
6
|
ngio/common/_dimensions.py,sha256=t3X2wzqCl3-UeocqIpQgKRdcWYagijtKsaHTQz5bfT4,3680
|
|
7
|
-
ngio/common/_pyramid.py,sha256=
|
|
7
|
+
ngio/common/_pyramid.py,sha256=aBxRBjW7y6D-Rj8f9B3dtqIErxk2eq20O58C33NBU0Q,7231
|
|
8
8
|
ngio/common/_roi.py,sha256=q7HZg2lPbnJ6flKRgK9e4nfOIgkGpDjDcdz-tE8F0Ys,2869
|
|
9
9
|
ngio/common/_slicer.py,sha256=Qk7XXmd4W9T3w55LvFTjAyloyIcS9tt9NTXiDZNwOx8,3076
|
|
10
10
|
ngio/common/_zoom.py,sha256=z2UjgotoDw7pvpeZVrxiGx4PXx65nk1vwQH3osTFACI,5422
|
|
@@ -12,9 +12,9 @@ ngio/hcs/__init__.py,sha256=ugnRl22hM9dic5XRsqQr-HCyyyY1qXTqYOAOzyOZm4M,1624
|
|
|
12
12
|
ngio/images/__init__.py,sha256=aijqG14eyqVgHtnlcKVNx37FRfT6QvKt8V6bwBpX_r8,526
|
|
13
13
|
ngio/images/abstract_image.py,sha256=n4akBHWQul7vmo4OlYtKWZwpsYl8IYg82AThJrvDrxc,7113
|
|
14
14
|
ngio/images/create.py,sha256=DMyiNVmj3uaJmJQqsL9ftzZNvXxeqgZ0-Pjo63WqWoM,8991
|
|
15
|
-
ngio/images/image.py,sha256=
|
|
16
|
-
ngio/images/label.py,sha256=
|
|
17
|
-
ngio/images/omezarr_container.py,sha256=
|
|
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
18
|
ngio/ome_zarr_meta/__init__.py,sha256=9kYdyuCc3ouQCLDyUCB_lCVXUJ69Ls0fYwtodk3GtYI,798
|
|
19
19
|
ngio/ome_zarr_meta/_generic_handlers.py,sha256=4zRm3P1CRKgUQgD5Z2C9j8VVv659DZIifrmzkQ7o31I,10987
|
|
20
20
|
ngio/ome_zarr_meta/_meta_handlers.py,sha256=b6r1zX3SBBTKoQdKfEqvJaSnTOen5t1EPO3rh0I9VH4,4925
|
|
@@ -23,7 +23,7 @@ ngio/ome_zarr_meta/ngio_specs/_axes.py,sha256=zgAE0-2DHzJfqGqBhyjY7y_6qAgDLdV9iu
|
|
|
23
23
|
ngio/ome_zarr_meta/ngio_specs/_channels.py,sha256=KLQAo7eerBXa5NN3-QWSFxeAfM_bvXXaxFjFNM6OMoA,13762
|
|
24
24
|
ngio/ome_zarr_meta/ngio_specs/_dataset.py,sha256=xT4GY2mdIsm6nAP8bXRj5E9-P6rS-iwzcXT_o3pZajo,4696
|
|
25
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=
|
|
26
|
+
ngio/ome_zarr_meta/ngio_specs/_ngio_image.py,sha256=Bf2DyGuVmFqA4zQROYpjGxAcquXkGyztPkHuHh7586Y,14966
|
|
27
27
|
ngio/ome_zarr_meta/ngio_specs/_pixel_size.py,sha256=Ny4F0Wa7uVCKdDQhvFJPCQFUEtKP_DpwId8vdVxkVyQ,2777
|
|
28
28
|
ngio/ome_zarr_meta/v04/__init__.py,sha256=0sb_CaJNgC1AOYeR6LDB91oUmSk6edJyQTTo3Lnh5Y4,226
|
|
29
29
|
ngio/ome_zarr_meta/v04/_meta_handlers.py,sha256=aRvuq9ofzQQCB-CJehD3e2T1eKBtZwKg6r2OkpTG1Oo,1768
|
|
@@ -42,12 +42,13 @@ ngio/tables/v1/_feature_table.py,sha256=WOkFOb0UDxwM-MPZGdv-nLIiqfiGL8etVkMett9i
|
|
|
42
42
|
ngio/tables/v1/_generic_table.py,sha256=KOVzbeUs8AwVvI83Os5gBZky948ucEKjxXl2CGzSQqQ,3483
|
|
43
43
|
ngio/tables/v1/_masking_roi_table.py,sha256=vPlUWGQalxDJ7G4NcSmzsOFqSEIJFXbuCLD_ucBj7ew,5492
|
|
44
44
|
ngio/tables/v1/_roi_table.py,sha256=UMwJEMkOAgDf-80z0qPfIiB6fsQInjzjDlR4OkBYH4o,7147
|
|
45
|
-
ngio/utils/__init__.py,sha256=
|
|
46
|
-
ngio/utils/_datasets.py,sha256=
|
|
45
|
+
ngio/utils/__init__.py,sha256=r3nuLWgp6-cQlS4ODjYSBrfgdTLkCOVke9jKbn1NpkA,1129
|
|
46
|
+
ngio/utils/_datasets.py,sha256=Ir5-DUaplJoWXIsFCVp6yaJNfEKXKygj6RbGsy275uE,1669
|
|
47
47
|
ngio/utils/_errors.py,sha256=pKQ12LUjQLYE1nUawemA5h7HsgznjaSvV1n2PQU33N0,759
|
|
48
|
+
ngio/utils/_fractal_fsspec_store.py,sha256=KxIu37EUJgiKI92qmJKfZtCjNdfMmfNbYez2LAK3dxg,496
|
|
48
49
|
ngio/utils/_logger.py,sha256=zvFG-Ta3ZIJxTyY93zYoPGp2A6TTUf7mSO0zr_uFy4A,837
|
|
49
50
|
ngio/utils/_zarr_utils.py,sha256=5Mo8Nfb7oww7rGVqEWUH29VvOkhD3-Despb3c1SlENM,12172
|
|
50
|
-
ngio-0.2.
|
|
51
|
-
ngio-0.2.
|
|
52
|
-
ngio-0.2.
|
|
53
|
-
ngio-0.2.
|
|
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
|
|
File without changes
|