@@ -544,22 +544,40 @@ def test_data_fake(self):
544
544
dw = MFW (fake_mf )
545
545
# Fails - no shape
546
546
assert_raises (didw .WrapperError , dw .get_data )
547
- # Set shape
547
+ # Set shape by cheating
548
548
dw .image_shape = (2 , 3 , 4 )
549
- # Fails - no data
549
+ # Still fails - no data
550
+ assert_raises (didw .WrapperError , dw .get_data )
551
+ # Make shape and indices
552
+ fake_mf ['Rows' ] = 2
553
+ fake_mf ['Columns' ] = 3
554
+ fake_mf ['NumberOfFrames' ] = 4
555
+ frames = fake_frames ('FrameContentSequence' ,
556
+ 'DimensionIndexValues' ,
557
+ ((1 , 1 ), (1 , 2 ), (1 , 3 ), (1 , 4 )))
558
+ fake_mf ['PerFrameFunctionalGroupsSequence' ] = frames
559
+ assert_equal (MFW (fake_mf ).image_shape , (2 , 3 , 4 ))
560
+ # Still fails - no data
550
561
assert_raises (didw .WrapperError , dw .get_data )
551
562
# Add data - 3D
552
- class Fake (dict ): pass
553
- dw .dcm_data = Fake ()
554
563
data = np .arange (24 ).reshape ((2 , 3 , 4 ))
555
564
# Frames dim is first for some reason
556
- dw .dcm_data .pixel_array = np .rollaxis (data , 2 )
565
+ fake_mf ['pixel_array' ] = np .rollaxis (data , 2 )
566
+ # Now it should work
567
+ dw = MFW (fake_mf )
557
568
assert_array_equal (dw .get_data (), data )
558
569
# Test scaling works
559
- dw .dcm_data ['RescaleSlope' ] = 2.0
560
- dw .dcm_data ['RescaleIntercept' ] = - 1
561
- assert_array_equal (dw .get_data (), data * 2.0 - 1 )
562
- # 5D case
570
+ fake_mf ['RescaleSlope' ] = 2.0
571
+ fake_mf ['RescaleIntercept' ] = - 1
572
+ assert_array_equal (MFW (fake_mf ).get_data (), data * 2.0 - 1 )
573
+ # Check slice sorting
574
+ frames = fake_frames ('FrameContentSequence' ,
575
+ 'DimensionIndexValues' ,
576
+ ((1 , 4 ), (1 , 2 ), (1 , 3 ), (1 , 1 )))
577
+ fake_mf ['PerFrameFunctionalGroupsSequence' ] = frames
578
+ sorted_data = data [..., [3 , 1 , 2 , 0 ]]
579
+ fake_mf ['pixel_array' ] = np .rollaxis (sorted_data , 2 )
580
+ assert_array_equal (MFW (fake_mf ).get_data (), data * 2.0 - 1 )
563
581
564
582
def test__scale_data (self ):
565
583
# Test data scaling
0 commit comments