@@ -57,7 +57,7 @@ def __init__(
57
57
self .specs .append (PlateLabels (self ))
58
58
elif Plate .matches (zarr ):
59
59
self .specs .append (Plate (self ))
60
- self .add (zarr , plate_labels = True )
60
+ # self.add(zarr, plate_labels=True)
61
61
if Well .matches (zarr ):
62
62
self .specs .append (Well (self ))
63
63
@@ -412,6 +412,8 @@ def __init__(self, node: Node) -> None:
412
412
# Use first Field for rendering settings, shape etc.
413
413
image_zarr = self .zarr .create (image_paths [0 ])
414
414
image_node = Node (image_zarr , node )
415
+ x_index = len (image_node .metadata ["axes" ]) - 1
416
+ y_index = len (image_node .metadata ["axes" ]) - 2
415
417
level = 0 # load full resolution image
416
418
self .numpy_type = image_node .data [level ].dtype
417
419
self .img_metadata = image_node .metadata
@@ -448,8 +450,8 @@ def get_lazy_well() -> da.Array:
448
450
dtype = self .numpy_type ,
449
451
)
450
452
lazy_row .append (lazy_tile )
451
- lazy_rows .append (da .concatenate (lazy_row , axis = 4 ))
452
- return da .concatenate (lazy_rows , axis = 3 )
453
+ lazy_rows .append (da .concatenate (lazy_row , axis = x_index ))
454
+ return da .concatenate (lazy_rows , axis = y_index )
453
455
454
456
node .data = [get_lazy_well ()]
455
457
node .metadata = image_node .metadata
@@ -470,7 +472,7 @@ def get_pyramid_lazy(self, node: Node) -> None:
470
472
stitched full-resolution images.
471
473
"""
472
474
self .plate_data = self .lookup ("plate" , {})
473
- LOGGER .info ("plate_data" , self .plate_data )
475
+ LOGGER .info ("plate_data: %s " , self .plate_data )
474
476
self .rows = self .plate_data .get ("rows" )
475
477
self .columns = self .plate_data .get ("columns" )
476
478
self .first_field = "0"
@@ -491,10 +493,11 @@ def get_pyramid_lazy(self, node: Node) -> None:
491
493
raise Exception ("could not find first well" )
492
494
self .numpy_type = well_spec .numpy_type
493
495
494
- LOGGER .debug ("img_pyramid_shapes" , well_spec .img_pyramid_shapes )
496
+ LOGGER .debug (f "img_pyramid_shapes: { well_spec .img_pyramid_shapes } " )
495
497
496
- size_y = well_spec .img_shape [3 ]
497
- size_x = well_spec .img_shape [4 ]
498
+ self .axes = well_spec .img_metadata ["axes" ]
499
+ size_y = well_spec .img_shape [len (self .axes ) - 2 ]
500
+ size_x = well_spec .img_shape [len (self .axes ) - 1 ]
498
501
499
502
# FIXME - if only returning a single stiched plate (not a pyramid)
500
503
# need to decide optimal size. E.g. longest side < 1500
@@ -511,7 +514,7 @@ def get_pyramid_lazy(self, node: Node) -> None:
511
514
if longest_side <= TARGET_SIZE :
512
515
break
513
516
514
- LOGGER .debug ("target_level" , target_level )
517
+ LOGGER .debug (f "target_level: { target_level } " )
515
518
516
519
pyramid = []
517
520
@@ -541,16 +544,19 @@ def get_tile_path(self, level: int, row: int, col: int) -> str:
541
544
)
542
545
543
546
def get_stitched_grid (self , level : int , tile_shape : tuple ) -> da .core .Array :
547
+ LOGGER .debug (f"get_stitched_grid() level: { level } , tile_shape: { tile_shape } " )
548
+
544
549
def get_tile (tile_name : str ) -> np .ndarray :
545
550
"""tile_name is 'level,z,c,t,row,col'"""
546
551
row , col = (int (n ) for n in tile_name .split ("," ))
547
552
path = self .get_tile_path (level , row , col )
548
- LOGGER .debug (f"LOADING tile... { path } " )
553
+ LOGGER .debug (f"LOADING tile... { path } with shape: { tile_shape } " )
549
554
550
555
try :
551
556
data = self .zarr .load (path )
552
- except ValueError :
557
+ except ValueError as e :
553
558
LOGGER .error (f"Failed to load { path } " )
559
+ LOGGER .debug (f"{ e } " )
554
560
data = np .zeros (tile_shape , dtype = self .numpy_type )
555
561
return data
556
562
@@ -566,23 +572,29 @@ def get_tile(tile_name: str) -> np.ndarray:
566
572
lazy_reader (tile_name ), shape = tile_shape , dtype = self .numpy_type
567
573
)
568
574
lazy_row .append (lazy_tile )
569
- lazy_rows .append (da .concatenate (lazy_row , axis = 4 ))
570
- return da .concatenate (lazy_rows , axis = 3 )
575
+ lazy_rows .append (da .concatenate (lazy_row , axis = len ( self . axes ) - 1 ))
576
+ return da .concatenate (lazy_rows , axis = len ( self . axes ) - 2 )
571
577
572
578
573
579
class PlateLabels (Plate ):
574
- def get_tile_path (self , level : int , row : int , col : int ) -> str :
580
+ def get_tile_path (self , level : int , row : int , col : int ) -> str : # pragma: no cover
575
581
"""251.zarr/A/1/0/labels/0/3/"""
576
582
path = (
577
583
f"{ self .row_names [row ]} /{ self .col_names [col ]} /"
578
584
f"{ self .first_field } /labels/0/{ level } "
579
585
)
580
586
return path
581
587
582
- def get_pyramid_lazy (self , node : Node ) -> None :
588
+ def get_pyramid_lazy (self , node : Node ) -> None : # pragma: no cover
583
589
super ().get_pyramid_lazy (node )
584
590
# pyramid data may be multi-channel, but we only have 1 labels channel
585
- node .data [0 ] = node .data [0 ][:, 0 :1 , :, :, :]
591
+ # TODO: when PlateLabels are re-enabled, update the logic to handle
592
+ # 0.4 axes (list of dictionaries)
593
+ if "c" in self .axes :
594
+ c_index = self .axes .index ("c" )
595
+ idx = [slice (None )] * len (self .axes )
596
+ idx [c_index ] = slice (0 , 1 )
597
+ node .data [0 ] = node .data [0 ][tuple (idx )]
586
598
# remove image metadata
587
599
node .metadata = {}
588
600
@@ -602,7 +614,7 @@ def get_pyramid_lazy(self, node: Node) -> None:
602
614
del properties [label_val ]["label-value" ]
603
615
node .metadata ["properties" ] = properties
604
616
605
- def get_numpy_type (self , image_node : Node ) -> np .dtype :
617
+ def get_numpy_type (self , image_node : Node ) -> np .dtype : # pragma: no cover
606
618
# FIXME - don't assume Well A1 is valid
607
619
path = self .get_tile_path (0 , 0 , 0 )
608
620
label_zarr = self .zarr .load (path )
0 commit comments