@@ -325,6 +325,14 @@ def _read_voxel_size_offset(ds, order="C"):
325
325
return regularize_offset (voxel_size , offset )
326
326
327
327
328
+ def _read_axis_names (ds , order = "C" ):
329
+
330
+ if "axis_names" in ds .attrs :
331
+ return ds .attrs ["axis_names" ]
332
+
333
+ return None
334
+
335
+
328
336
def open_ds (filename : str , ds_name : str , mode : str = "r" ) -> Array :
329
337
"""Open a Zarr, N5, or HDF5 dataset as an :class:`Array`. If the
330
338
dataset has attributes ``resolution`` and ``offset``, those will be
@@ -363,26 +371,26 @@ def open_ds(filename: str, ds_name: str, mode: str = "r") -> Array:
363
371
except KeyError :
364
372
order = ds .order
365
373
voxel_size , offset = _read_voxel_size_offset (ds , order )
374
+ axis_names = _read_axis_names (ds , order )
366
375
shape = Coordinate (ds .shape [- len (voxel_size ) :])
367
- roi = Roi (offset , voxel_size * shape )
368
376
369
377
chunk_shape = ds .chunks
370
378
371
379
logger .debug ("opened zarr dataset %s in %s" , ds_name , filename )
372
- return Array (ds , roi , voxel_size , chunk_shape = chunk_shape )
380
+ return Array (ds , offset , voxel_size , axis_names = axis_names , chunk_shape = chunk_shape )
373
381
374
382
elif filename .endswith (".n5" ):
375
383
logger .debug ("opening N5 dataset %s in %s" , ds_name , filename )
376
384
ds = zarr .open (N5FSStore (filename ), mode = mode )[ds_name ]
377
385
378
386
voxel_size , offset = _read_voxel_size_offset (ds , "F" )
387
+ axis_names = _read_axis_names (ds , order )
379
388
shape = Coordinate (ds .shape [- len (voxel_size ) :])
380
- roi = Roi (offset , voxel_size * shape )
381
389
382
390
chunk_shape = ds .chunks
383
391
384
392
logger .debug ("opened N5 dataset %s in %s" , ds_name , filename )
385
- return Array (ds , roi , voxel_size , chunk_shape = chunk_shape )
393
+ return Array (ds , offset , voxel_size , axis_names = axis_names , chunk_shape = chunk_shape )
386
394
387
395
elif (
388
396
filename .endswith (".h5" )
@@ -393,27 +401,13 @@ def open_ds(filename: str, ds_name: str, mode: str = "r") -> Array:
393
401
ds = h5py .File (filename , mode = mode )[ds_name ]
394
402
395
403
voxel_size , offset = _read_voxel_size_offset (ds , "C" )
404
+ axis_names = _read_axis_names (ds , "C" )
396
405
shape = Coordinate (ds .shape [- len (voxel_size ) :])
397
- roi = Roi (offset , voxel_size * shape )
398
406
399
407
chunk_shape = ds .chunks
400
408
401
409
logger .debug ("opened H5 dataset %s in %s" , ds_name , filename )
402
- return Array (ds , roi , voxel_size , chunk_shape = chunk_shape )
403
-
404
- elif filename .endswith (".json" ):
405
- logger .debug ("found JSON container spec" )
406
- with open (filename , "r" ) as f :
407
- spec = json .load (f )
408
-
409
- array = open_ds (spec ["container" ], ds_name , mode )
410
- return Array (
411
- array .data ,
412
- Roi (spec ["offset" ], spec ["size" ]),
413
- array .voxel_size ,
414
- array .roi .begin ,
415
- chunk_shape = array .chunk_shape ,
416
- )
410
+ return Array (ds , offset , voxel_size , axis_names = axis_names , chunk_shape = chunk_shape )
417
411
418
412
else :
419
413
logger .error ("don't know data format of %s in %s" , ds_name , filename )
0 commit comments