ngio 0.2.0a2__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/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
- ref = self.get()
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
- ref, start_percentile=percentiles[0], end_percentile=percentiles[1]
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 = ref.num_channels
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=ref.dtype,
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
- image = self.get()
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
- image, start_percentile=start_percentile, end_percentile=end_percentile
215
+ ref_image, start_percentile=start_percentile, end_percentile=end_percentile
212
216
  )
213
217
 
214
218
  channels = []
@@ -256,13 +260,20 @@ class ImagesContainer:
256
260
  self,
257
261
  path: str | None = None,
258
262
  pixel_size: PixelSize | None = None,
259
- highest_resolution: bool = True,
263
+ strict: bool = False,
260
264
  ) -> Image:
261
- """Get an image at a specific level."""
262
- if path is not None or pixel_size is not None:
263
- highest_resolution = False
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
+ """
264
275
  dataset = self._meta_handler.meta.get_dataset(
265
- path=path, pixel_size=pixel_size, highest_resolution=highest_resolution
276
+ path=path, pixel_size=pixel_size, strict=strict
266
277
  )
267
278
  return Image(
268
279
  group_handler=self._group_handler,
ngio/images/label.py CHANGED
@@ -10,6 +10,7 @@ from ngio.ome_zarr_meta import (
10
10
  ImplementedLabelMetaHandlers,
11
11
  LabelMetaHandler,
12
12
  NgioLabelMeta,
13
+ PixelSize,
13
14
  )
14
15
  from ngio.ome_zarr_meta.ngio_specs import SpaceUnits, TimeUnits
15
16
  from ngio.utils import (
@@ -86,11 +87,38 @@ class LabelsContainer:
86
87
  attrs = self._group_handler.load_attrs()
87
88
  return attrs.get("labels", [])
88
89
 
89
- def get(self, name: str, path: str) -> Label:
90
+ def _get(self, name: str, path: str) -> Label:
90
91
  """Get a label from the group."""
91
92
  group_handler = self._group_handler.derive_handler(name)
92
93
  return Label(group_handler, path, None)
93
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
+
94
122
  def derive(
95
123
  self,
96
124
  name: str,
@@ -160,13 +160,20 @@ class OmeZarrContainer:
160
160
  self,
161
161
  path: str | None = None,
162
162
  pixel_size: PixelSize | None = None,
163
- highest_resolution: bool = True,
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(
@@ -279,11 +286,28 @@ class OmeZarrContainer:
279
286
  return []
280
287
  return self._labels_container.list()
281
288
 
282
- def get_label(self, name: str, path: str) -> Label:
283
- """Get a label from the image."""
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
+ """
284
306
  if self._labels_container is None:
285
307
  raise NgioValidationError("No labels found in the image.")
286
- return self._labels_container.get(name=name, path=path)
308
+ return self._labels_container.get(
309
+ name=name, path=path, pixel_size=pixel_size, strict=strict
310
+ )
287
311
 
288
312
  def derive_label(
289
313
  self,
@@ -334,17 +358,29 @@ def open_image(
334
358
  store: StoreOrGroup,
335
359
  path: str | None = None,
336
360
  pixel_size: PixelSize | None = None,
337
- highest_resolution: bool = False,
361
+ strict: bool = True,
338
362
  cache: bool = False,
339
363
  mode: AccessModeLiteral = "r+",
340
364
  ) -> Image:
341
- """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
+ """
342
378
  group_handler = ZarrGroupHandler(store, cache, mode)
343
379
  images_container = ImagesContainer(group_handler)
344
380
  return images_container.get(
345
381
  path=path,
346
382
  pixel_size=pixel_size,
347
- highest_resolution=highest_resolution,
383
+ strict=strict,
348
384
  )
349
385
 
350
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
- != 1
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
- raise NgioValueError("get_dataset has no valid arguments.")
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",
@@ -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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ngio
3
- Version: 0.2.0a2
3
+ Version: 0.2.0a3
4
4
  Summary: Next Generation file format IO
5
5
  Project-URL: homepage, https://github.com/lorenzocerrone/ngio
6
6
  Project-URL: repository, https://github.com/lorenzocerrone/ngio
@@ -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=QiSdOaZSLWtAweecMj69hXXAdVnPIkO3Qfjvs8QII3o,12586
16
- ngio/images/label.py,sha256=wzpIsIFuKdTOcTU57PHpIf_U4Fh6TwRhM-tLpEt4GbI,7520
17
- ngio/images/omezarr_container.py,sha256=E0uDyBM1vZ8kCwXI6tIyPDl7QEdi5e91hI5AIWf8kFY,19161
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=FnVSupNHHsUxlQOfDXQP2fBZqL8BOX7bB_c1gHP0iWk,14703
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=fhT4CUTk3obQHzjfTcZYOwjZrSuuI1uXQ8qJmyH17iY,1021
45
+ ngio/utils/__init__.py,sha256=r3nuLWgp6-cQlS4ODjYSBrfgdTLkCOVke9jKbn1NpkA,1129
46
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.0a2.dist-info/METADATA,sha256=-NUZl0xeZ-rFEqPilWo_hFfbQ-uuyCFa2cv2bLxkABo,4804
51
- ngio-0.2.0a2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
52
- ngio-0.2.0a2.dist-info/licenses/LICENSE,sha256=UgN_a1QCeNh9rZWfz-wORQFxE3elQzLWPQaoK6N6fxQ,1502
53
- ngio-0.2.0a2.dist-info/RECORD,,
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