Skip to content

Commit b9fde3f

Browse files
add dimensio separator and derive to new version of ngff
1 parent 28e97b4 commit b9fde3f

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

src/ngio/common/_pyramid.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ def init_empty_pyramid(
203203
paths: list[str],
204204
ref_shape: Sequence[int],
205205
scaling_factors: Sequence[float],
206+
axes: Sequence[str],
206207
chunks: Sequence[int] | Literal["auto"] = "auto",
207208
dtype: str = "uint16",
208209
mode: AccessModeLiteral = "a",
@@ -248,6 +249,7 @@ def init_empty_pyramid(
248249
"name": "default",
249250
"separator": dimension_separator,
250251
}
252+
array_static_kwargs["dimension_names"] = axes
251253

252254
for path in paths:
253255
if any(s < 1 for s in ref_shape):

src/ngio/images/_create.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ def create_empty_label_container(
171171
scaling_factors=scaling_factors,
172172
ref_shape=shape,
173173
chunks=chunks,
174+
axes=axes_names,
174175
dtype=dtype,
175176
mode="a",
176177
dimension_separator=dimension_separator,
@@ -270,6 +271,7 @@ def create_empty_image_container(
270271
scaling_factors=scaling_factors,
271272
ref_shape=shape,
272273
chunks=chunks,
274+
axes=axes_names,
273275
dtype=dtype,
274276
mode="a",
275277
dimension_separator=dimension_separator,

src/ngio/images/_image.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
ChannelVisualisation,
3333
DefaultSpaceUnit,
3434
DefaultTimeUnit,
35+
NgffVersions,
3536
SpaceUnits,
3637
TimeUnits,
3738
)
@@ -607,6 +608,7 @@ def derive(
607608
dtype: str | None = None,
608609
dimension_separator: Literal[".", "/"] | None = None,
609610
compressors: CompressorLike | None = None,
611+
ngff_version: NgffVersions | None = None,
610612
overwrite: bool = False,
611613
) -> "ImagesContainer":
612614
"""Create an empty OME-Zarr image from an existing image.
@@ -626,6 +628,7 @@ def derive(
626628
compressors: The compressor to use. If None it will use
627629
the same as the reference image.
628630
dtype (str | None): The data type of the new image.
631+
ngff_version (NgffVersions): The NGFF version to use.
629632
overwrite (bool): Whether to overwrite an existing image.
630633
631634
Returns:
@@ -644,6 +647,7 @@ def derive(
644647
dtype=dtype,
645648
dimension_separator=dimension_separator,
646649
compressors=compressors,
650+
ngff_version=ngff_version,
647651
overwrite=overwrite,
648652
)
649653

@@ -728,6 +732,7 @@ def derive_image_container(
728732
dtype: str | None = None,
729733
dimension_separator: Literal[".", "/"] | None = None,
730734
compressors: CompressorLike | None = None,
735+
ngff_version: NgffVersions | None = None,
731736
overwrite: bool = False,
732737
) -> ImagesContainer:
733738
"""Create an empty OME-Zarr image from an existing image.
@@ -746,6 +751,7 @@ def derive_image_container(
746751
dimensions. If None it will use the same as the reference image.
747752
compressors (CompressorLike | None): The compressors to use. If None it will use
748753
the same as the reference image.
754+
ngff_version (NgffVersions): The NGFF version to use.
749755
dtype (str | None): The data type of the new image.
750756
overwrite (bool): Whether to overwrite an existing image.
751757
@@ -796,6 +802,9 @@ def derive_image_container(
796802
if compressors is None:
797803
compressors = ref_image.zarr_array.compressors # type: ignore
798804

805+
if ngff_version is None:
806+
ngff_version = ref_meta.version
807+
799808
handler = create_empty_image_container(
800809
store=store,
801810
shape=shape,
@@ -814,7 +823,7 @@ def derive_image_container(
814823
dimension_separator=dimension_separator,
815824
compressors=compressors,
816825
overwrite=overwrite,
817-
version=ref_meta.version,
826+
version=ngff_version,
818827
)
819828
image_container = ImagesContainer(handler)
820829

src/ngio/images/_ome_zarr_container.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ def derive_image(
414414
compressors: CompressorLike | None = None,
415415
copy_labels: bool = False,
416416
copy_tables: bool = False,
417+
ngff_version: NgffVersions | None = None,
417418
overwrite: bool = False,
418419
) -> "OmeZarrContainer":
419420
"""Create an empty OME-Zarr container from an existing image.
@@ -436,13 +437,14 @@ def derive_image(
436437
the compressors of the reference image will be used.
437438
copy_labels (bool): Whether to copy the labels from the reference image.
438439
copy_tables (bool): Whether to copy the tables from the reference image.
440+
ngff_version (NgffVersions): The NGFF version to use.
439441
overwrite (bool): Whether to overwrite an existing image.
440442
441443
Returns:
442444
OmeZarrContainer: The new image container.
443445
444446
"""
445-
_ = self._images_container.derive(
447+
new_container = self._images_container.derive(
446448
store=store,
447449
ref_path=ref_path,
448450
shape=shape,
@@ -454,18 +456,12 @@ def derive_image(
454456
dtype=dtype,
455457
dimension_separator=dimension_separator,
456458
compressors=compressors,
459+
ngff_version=ngff_version,
457460
overwrite=overwrite,
458461
)
459462

460-
handler = ZarrGroupHandler(
461-
store,
462-
cache=self._group_handler.use_cache,
463-
mode=self._group_handler.mode,
464-
zarr_format=self._group_handler.zarr_format,
465-
)
466-
467463
new_ome_zarr = OmeZarrContainer(
468-
group_handler=handler,
464+
group_handler=new_container._group_handler,
469465
validate_paths=False,
470466
)
471467

0 commit comments

Comments
 (0)