@@ -554,23 +554,20 @@ def image_shape(self):
554
554
raise WrapperError ('Missing information, cannot remove indices with confidence.' )
555
555
derived_dim_idx = dim_seq .index (derived_tag )
556
556
frame_indices = np .delete (frame_indices , derived_dim_idx , axis = 1 )
557
- # account for the 2 additional dimensions (row and column) not included
558
- # in the indices
559
- n_dim = frame_indices .shape [1 ] + 2
560
557
# Store frame indices
561
558
self ._frame_indices = frame_indices
562
- if n_dim < 4 : # 3D volume
563
- return rows , cols , n_frames
564
- # More than 3 dimensions
559
+ # Determine size of any extra-spatial dimensions
565
560
ns_unique = [len (np .unique (row )) for row in self ._frame_indices .T ]
566
- shape = (rows , cols ) + tuple (ns_unique )
567
- n_vols = np .prod (shape [3 :])
568
- n_frames_calc = n_vols * shape [2 ]
569
- if n_frames != n_frames_calc :
570
- raise WrapperError (
571
- f'Calculated # of frames ({ n_frames_calc } ={ n_vols } *{ shape [2 ]} ) '
572
- f'of shape { shape } does not match NumberOfFrames { n_frames } .'
573
- )
561
+ shape = (rows , cols ) + tuple (x for i , x in enumerate (ns_unique ) if i == 0 or x != 1 )
562
+ n_dim = len (shape )
563
+ if n_dim > 3 :
564
+ n_vols = np .prod (shape [3 :])
565
+ n_frames_calc = n_vols * shape [2 ]
566
+ if n_frames != n_frames_calc :
567
+ raise WrapperError (
568
+ f'Calculated # of frames ({ n_frames_calc } ={ n_vols } *{ shape [2 ]} ) '
569
+ f'of shape { shape } does not match NumberOfFrames { n_frames } .'
570
+ )
574
571
return tuple (shape )
575
572
576
573
@cached_property
@@ -640,10 +637,11 @@ def get_data(self):
640
637
raise WrapperError ('No valid information for image shape' )
641
638
data = self .get_pixel_array ()
642
639
# Roll frames axis to last
643
- data = data .transpose ((1 , 2 , 0 ))
644
- # Sort frames with first index changing fastest, last slowest
645
- sorted_indices = np .lexsort (self ._frame_indices .T )
646
- data = data [..., sorted_indices ]
640
+ if len (data .shape ) > 2 :
641
+ data = data .transpose ((1 , 2 , 0 ))
642
+ # Sort frames with first index changing fastest, last slowest
643
+ sorted_indices = np .lexsort (self ._frame_indices .T )
644
+ data = data [..., sorted_indices ]
647
645
data = data .reshape (shape , order = 'F' )
648
646
return self ._scale_data (data )
649
647
0 commit comments