@@ -105,7 +105,7 @@ def _numpy_to_zarr_dtype(dtype):
105105
106106
107107def _write_with_tensorstore (
108- store_path : str , array , region , chunks , zarr_format
108+ store_path : str , array , region , chunks , zarr_format , dimension_names = None
109109) -> None :
110110 """Write array using tensorstore backend"""
111111 import tensorstore as ts
@@ -131,6 +131,8 @@ def _write_with_tensorstore(
131131 "configuration" : {"chunk_shape" : chunks },
132132 }
133133 spec ["metadata" ]["data_type" ] = _numpy_to_zarr_dtype (array .dtype )
134+ if dimension_names :
135+ spec ["metadata" ]["dimension_names" ] = dimension_names
134136 else :
135137 raise ValueError (f"Unsupported zarr format: { zarr_format } " )
136138 dataset = ts .open (spec , create = True , dtype = array .dtype ).result ()
@@ -199,6 +201,10 @@ def to_ngff_zarr(
199201 coordinateTransformations = metadata .coordinateTransformations ,
200202 name = metadata .name ,
201203 )
204+ dimension_names = tuple ([ax .name for ax in metadata .axes ])
205+ dimension_names_kwargs = (
206+ {"dimension_names" : dimension_names } if version != "0.4" else {}
207+ )
202208
203209 metadata_dict = asdict (metadata )
204210 metadata_dict = _pop_metadata_optionals (metadata_dict )
@@ -274,6 +280,7 @@ def to_ngff_zarr(
274280 path = path ,
275281 mode = "a" ,
276282 ** zarr_kwargs ,
283+ ** dimension_names_kwargs ,
277284 )
278285
279286 shape = image .data .shape
@@ -407,6 +414,7 @@ def to_ngff_zarr(
407414 region ,
408415 [c [0 ] for c in arr_region .chunks ],
409416 zarr_format = zarr_format ,
417+ dimension_names = dimension_names ,
410418 ** kwargs ,
411419 )
412420 else :
@@ -419,6 +427,7 @@ def to_ngff_zarr(
419427 compute = True ,
420428 return_stored = False ,
421429 ** zarr_kwargs ,
430+ ** dimension_names_kwargs ,
422431 ** kwargs ,
423432 )
424433 else :
@@ -435,6 +444,7 @@ def to_ngff_zarr(
435444 region ,
436445 [c [0 ] for c in arr .chunks ],
437446 zarr_format = zarr_format ,
447+ dimension_names = dimension_names ,
438448 ** kwargs ,
439449 )
440450 else :
@@ -447,6 +457,7 @@ def to_ngff_zarr(
447457 compute = True ,
448458 return_stored = False ,
449459 ** zarr_kwargs ,
460+ ** dimension_names_kwargs ,
450461 ** kwargs ,
451462 )
452463
0 commit comments