Skip to content

Commit b6de200

Browse files
moloneyeffigies
authored andcommitted
TST: Expand test coverage for multiframe dicom shape determination
1 parent 3f30f8e commit b6de200

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

nibabel/nicom/tests/test_dicomwrappers.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,6 @@ def __init__(self, div, sid, ipp, iop):
473473
frame_slc_indices = np.array(div_seq)[:, slice_dim]
474474
uniq_slc_indices = np.unique(frame_slc_indices)
475475
n_slices = len(uniq_slc_indices)
476-
assert num_of_frames % n_slices == 0
477476
iop_seq = [(0.0, 1.0, 0.0, 1.0, 0.0, 0.0) for _ in range(num_of_frames)]
478477
if ipp_seq is None:
479478
slc_locs = np.linspace(-1.0, 1.0, n_slices)
@@ -579,6 +578,17 @@ def test_shape(self):
579578
div_seq = ((1, 1, 0), (1, 2, 0), (1, 1, 3), (1, 2, 3))
580579
fake_mf.update(fake_shape_dependents(div_seq, sid_dim=0))
581580
assert MFW(fake_mf).image_shape == (32, 64, 2, 2)
581+
# Check number of IPP vals match the number of slices or we raise
582+
frames = fake_mf['PerFrameFunctionalGroupsSequence']
583+
for frame in frames[1:]:
584+
frame.PlanePositionSequence = frames[0].PlanePositionSequence[:]
585+
with pytest.raises(didw.WrapperError):
586+
MFW(fake_mf).image_shape
587+
# Check we raise on missing slices
588+
div_seq = ((1, 1, 0), (1, 2, 0), (1, 1, 1))
589+
fake_mf.update(fake_shape_dependents(div_seq, sid_dim=0))
590+
with pytest.raises(didw.WrapperError):
591+
MFW(fake_mf).image_shape
582592
# check 3D shape when there is no StackID index
583593
div_seq = ((1,), (2,), (3,), (4,))
584594
sid_seq = (1, 1, 1, 1)
@@ -614,6 +624,11 @@ def test_shape(self):
614624
div_seq = ((1, 1, 1), (2, 1, 1), (1, 1, 2), (2, 1, 2), (1, 1, 3), (2, 1, 3))
615625
fake_mf.update(fake_shape_dependents(div_seq, sid_dim=1))
616626
assert MFW(fake_mf).image_shape == (32, 64, 2, 3)
627+
# Check non-singular dimension preceding slice dim raises
628+
div_seq = ((1, 1, 1), (1, 2, 1), (1, 1, 2), (1, 2, 2), (1, 1, 3), (1, 2, 3))
629+
fake_mf.update(fake_shape_dependents(div_seq, sid_dim=0, slice_dim=2))
630+
with pytest.raises(didw.WrapperError):
631+
MFW(fake_mf).image_shape
617632
# Test with combo indices, here with the last two needing to be combined into
618633
# a single index corresponding to [(1, 1), (1, 1), (2, 1), (2, 1), (2, 2), (2, 2)]
619634
div_seq = (
@@ -655,6 +670,22 @@ def test_shape(self):
655670
)
656671
fake_mf.update(fake_shape_dependents(div_seq, sid_dim=0))
657672
assert MFW(fake_mf).image_shape == (32, 64, 2, 3, 2)
673+
# Check we only allow one extra spatial dimension with unique val per frame
674+
div_seq = (
675+
(1, 1, 1, 6),
676+
(1, 2, 2, 5),
677+
(1, 1, 3, 4),
678+
(1, 2, 4, 3),
679+
(1, 1, 5, 2),
680+
(1, 2, 6, 1),
681+
)
682+
fake_mf.update(fake_shape_dependents(div_seq, sid_dim=0))
683+
with pytest.raises(didw.WrapperError):
684+
MFW(fake_mf).image_shape
685+
# Check that having unique value per frame works with single volume
686+
div_seq = ((1, 1, 1), (1, 2, 2), (1, 3, 3))
687+
fake_mf.update(fake_shape_dependents(div_seq, sid_dim=0))
688+
assert MFW(fake_mf).image_shape == (32, 64, 3)
658689

659690
def test_iop(self):
660691
# Test Image orient patient for multiframe

0 commit comments

Comments
 (0)