Skip to content

Commit 367076c

Browse files
committed
TST: extend fake data tests for multiframe
Also test slice frame sorting.
1 parent 2527b1d commit 367076c

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

nibabel/nicom/tests/test_dicomwrappers.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -544,22 +544,40 @@ def test_data_fake(self):
544544
dw = MFW(fake_mf)
545545
# Fails - no shape
546546
assert_raises(didw.WrapperError, dw.get_data)
547-
# Set shape
547+
# Set shape by cheating
548548
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
550561
assert_raises(didw.WrapperError, dw.get_data)
551562
# Add data - 3D
552-
class Fake(dict): pass
553-
dw.dcm_data = Fake()
554563
data = np.arange(24).reshape((2, 3, 4))
555564
# 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)
557568
assert_array_equal(dw.get_data(), data)
558569
# 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)
563581

564582
def test__scale_data(self):
565583
# Test data scaling

0 commit comments

Comments
 (0)