@@ -398,11 +398,11 @@ class Fake:
398
398
399
399
400
400
def fake_shape_dependents (
401
- div_seq ,
402
- sid_seq = None ,
403
- sid_dim = None ,
404
- ipp_seq = None ,
405
- slice_dim = None ,
401
+ div_seq ,
402
+ sid_seq = None ,
403
+ sid_dim = None ,
404
+ ipp_seq = None ,
405
+ slice_dim = None ,
406
406
flip_ipp_idx_corr = False ,
407
407
):
408
408
"""Make a fake dictionary of data that ``image_shape`` is dependent on.
@@ -431,7 +431,7 @@ def __repr__(self):
431
431
attr_strs = []
432
432
for attr in dir (self ):
433
433
if attr [0 ].isupper ():
434
- attr_strs .append (f" { attr } ={ getattr (self , attr )} " )
434
+ attr_strs .append (f' { attr } ={ getattr (self , attr )} ' )
435
435
return f"{ self .__class__ .__name__ } ({ ', ' .join (attr_strs )} )"
436
436
437
437
class DimIdxSeqElem (PrintBase ):
@@ -444,11 +444,11 @@ class FrmContSeqElem(PrintBase):
444
444
def __init__ (self , div , sid ):
445
445
self .DimensionIndexValues = div
446
446
self .StackID = sid
447
-
447
+
448
448
class PlnPosSeqElem (PrintBase ):
449
449
def __init__ (self , ipp ):
450
450
self .ImagePositionPatient = ipp
451
-
451
+
452
452
class PlnOrientSeqElem (PrintBase ):
453
453
def __init__ (self , iop ):
454
454
self .ImageOrientationPatient = iop
@@ -466,27 +466,25 @@ def __init__(self, div, sid, ipp, iop):
466
466
if sid_dim is None :
467
467
sid_dim = 0
468
468
sid_seq = [div [sid_dim ] for div in div_seq ]
469
- # Dertermine slice_dim and create per-slice ipp information
469
+ # Determine slice_dim and create per-slice ipp information
470
470
if slice_dim is None :
471
471
slice_dim = 1 if sid_dim == 0 else 0
472
472
num_of_frames = len (div_seq )
473
473
frame_slc_indices = np .array (div_seq )[:, slice_dim ]
474
474
uniq_slc_indices = np .unique (frame_slc_indices )
475
475
n_slices = len (uniq_slc_indices )
476
476
assert num_of_frames % n_slices == 0
477
- n_vols = num_of_frames // n_slices
478
- iop_seq = [(0. , 1. , 0. , 1. , 0. , 0. ) for _ in range (num_of_frames )]
477
+ iop_seq = [(0.0 , 1.0 , 0.0 , 1.0 , 0.0 , 0.0 ) for _ in range (num_of_frames )]
479
478
if ipp_seq is None :
480
- slc_locs = np .linspace (- 1. , 1. , n_slices )
479
+ slc_locs = np .linspace (- 1.0 , 1.0 , n_slices )
481
480
if flip_ipp_idx_corr :
482
481
slc_locs = slc_locs [::- 1 ]
483
482
slc_idx_loc = {
484
- div_idx : slc_locs [arr_idx ]
485
- for arr_idx , div_idx in enumerate (np .sort (uniq_slc_indices ))
483
+ div_idx : slc_locs [arr_idx ] for arr_idx , div_idx in enumerate (np .sort (uniq_slc_indices ))
486
484
}
487
- ipp_seq = [(- 1. , - 1. , slc_idx_loc [idx ]) for idx in frame_slc_indices ]
485
+ ipp_seq = [(- 1.0 , - 1.0 , slc_idx_loc [idx ]) for idx in frame_slc_indices ]
488
486
else :
489
- assert flip_ipp_idx_corr is False # caller can flip it themselves
487
+ assert flip_ipp_idx_corr is False # caller can flip it themselves
490
488
assert len (ipp_seq ) == num_of_frames
491
489
# create the DimensionIndexSequence
492
490
dim_idx_seq = [DimIdxSeqElem ()] * n_indices
@@ -500,7 +498,7 @@ def __init__(self, div, sid, ipp, iop):
500
498
dim_idx_seq [sid_dim ] = DimIdxSeqElem (sid_tag , fcs_tag )
501
499
# create the PerFrameFunctionalGroupsSequence
502
500
frames = [
503
- PerFrmFuncGrpSeqElem (div , sid , ipp , iop )
501
+ PerFrmFuncGrpSeqElem (div , sid , ipp , iop )
504
502
for div , sid , ipp , iop in zip (div_seq , sid_seq , ipp_seq , iop_seq )
505
503
]
506
504
return {
@@ -618,9 +616,14 @@ def test_shape(self):
618
616
assert MFW (fake_mf ).image_shape == (32 , 64 , 2 , 3 )
619
617
# Test with combo indices, here with the last two needing to be combined into
620
618
# a single index corresponding to [(1, 1), (1, 1), (2, 1), (2, 1), (2, 2), (2, 2)]
621
- div_seq = ((1 , 1 , 1 , 1 ), (1 , 2 , 1 , 1 ),
622
- (1 , 1 , 2 , 1 ), (1 , 2 , 2 , 1 ),
623
- (1 , 1 , 2 , 2 ), (1 , 2 , 2 , 2 ))
619
+ div_seq = (
620
+ (1 , 1 , 1 , 1 ),
621
+ (1 , 2 , 1 , 1 ),
622
+ (1 , 1 , 2 , 1 ),
623
+ (1 , 2 , 2 , 1 ),
624
+ (1 , 1 , 2 , 2 ),
625
+ (1 , 2 , 2 , 2 ),
626
+ )
624
627
fake_mf .update (fake_shape_dependents (div_seq , sid_dim = 0 ))
625
628
assert MFW (fake_mf ).image_shape == (32 , 64 , 2 , 3 )
626
629
# Test invalid 4D indices
@@ -636,13 +639,20 @@ def test_shape(self):
636
639
div_seq = ((1 , 1 , 1 ), (1 , 2 , 2 ), (1 , 1 , 3 ), (1 , 2 , 4 ), (1 , 1 , 5 ), (1 , 2 , 6 ))
637
640
fake_mf .update (fake_shape_dependents (div_seq , sid_dim = 0 ))
638
641
assert MFW (fake_mf ).image_shape == (32 , 64 , 2 , 3 )
639
- div_seq = ((1 , 1 , 1 , 1 ), (1 , 2 , 2 , 1 ),
640
- (1 , 1 , 3 , 1 ), (1 , 2 , 4 , 1 ),
641
- (1 , 1 , 5 , 1 ), (1 , 2 , 6 , 1 ),
642
- (1 , 1 , 7 , 2 ), (1 , 2 , 8 , 2 ),
643
- (1 , 1 , 9 , 2 ), (1 , 2 , 10 , 2 ),
644
- (1 , 1 , 11 , 2 ), (1 , 2 , 12 , 2 ),
645
- )
642
+ div_seq = (
643
+ (1 , 1 , 1 , 1 ),
644
+ (1 , 2 , 2 , 1 ),
645
+ (1 , 1 , 3 , 1 ),
646
+ (1 , 2 , 4 , 1 ),
647
+ (1 , 1 , 5 , 1 ),
648
+ (1 , 2 , 6 , 1 ),
649
+ (1 , 1 , 7 , 2 ),
650
+ (1 , 2 , 8 , 2 ),
651
+ (1 , 1 , 9 , 2 ),
652
+ (1 , 2 , 10 , 2 ),
653
+ (1 , 1 , 11 , 2 ),
654
+ (1 , 2 , 12 , 2 ),
655
+ )
646
656
fake_mf .update (fake_shape_dependents (div_seq , sid_dim = 0 ))
647
657
assert MFW (fake_mf ).image_shape == (32 , 64 , 2 , 3 , 2 )
648
658
@@ -713,9 +723,7 @@ def test_image_position(self):
713
723
dw .image_position
714
724
# Make a fake frame
715
725
iop = [0 , 1 , 0 , 1 , 0 , 0 ]
716
- frames = fake_frames (
717
- 'PlaneOrientationSequence' , 'ImageOrientationPatient' , [iop ]
718
- )
726
+ frames = fake_frames ('PlaneOrientationSequence' , 'ImageOrientationPatient' , [iop ])
719
727
frames = fake_frames (
720
728
'PlanePositionSequence' , 'ImagePositionPatient' , [[- 2.0 , 3.0 , 7 ]], frames
721
729
)
@@ -733,13 +741,9 @@ def test_image_position(self):
733
741
assert_array_equal (MFW (fake_mf ).image_position , [- 2 , 3 , 7 ])
734
742
assert MFW (fake_mf ).image_position .dtype == float
735
743
# We should get minimum along slice normal with multiple frames
736
- frames = fake_frames (
737
- 'PlaneOrientationSequence' , 'ImageOrientationPatient' , [iop ] * 2
738
- )
744
+ frames = fake_frames ('PlaneOrientationSequence' , 'ImageOrientationPatient' , [iop ] * 2 )
739
745
ipps = [[- 2.0 , 3.0 , 7 ], [- 2.0 , 3.0 , 6 ]]
740
- frames = fake_frames (
741
- 'PlanePositionSequence' , 'ImagePositionPatient' , ipps , frames
742
- )
746
+ frames = fake_frames ('PlanePositionSequence' , 'ImagePositionPatient' , ipps , frames )
743
747
fake_mf ['PerFrameFunctionalGroupsSequence' ] = frames
744
748
assert_array_equal (MFW (fake_mf ).image_position , [- 2 , 3 , 6 ])
745
749
0 commit comments