Skip to content

Commit

Permalink
TST: Expand test coverage for multiframe dicom shape determination
Browse files Browse the repository at this point in the history
  • Loading branch information
moloney authored and effigies committed Jul 25, 2024
1 parent 3f30f8e commit b6de200
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion nibabel/nicom/tests/test_dicomwrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,6 @@ def __init__(self, div, sid, ipp, iop):
frame_slc_indices = np.array(div_seq)[:, slice_dim]
uniq_slc_indices = np.unique(frame_slc_indices)
n_slices = len(uniq_slc_indices)
assert num_of_frames % n_slices == 0
iop_seq = [(0.0, 1.0, 0.0, 1.0, 0.0, 0.0) for _ in range(num_of_frames)]
if ipp_seq is None:
slc_locs = np.linspace(-1.0, 1.0, n_slices)
Expand Down Expand Up @@ -579,6 +578,17 @@ def test_shape(self):
div_seq = ((1, 1, 0), (1, 2, 0), (1, 1, 3), (1, 2, 3))
fake_mf.update(fake_shape_dependents(div_seq, sid_dim=0))
assert MFW(fake_mf).image_shape == (32, 64, 2, 2)
# Check number of IPP vals match the number of slices or we raise
frames = fake_mf['PerFrameFunctionalGroupsSequence']
for frame in frames[1:]:
frame.PlanePositionSequence = frames[0].PlanePositionSequence[:]
with pytest.raises(didw.WrapperError):
MFW(fake_mf).image_shape
# Check we raise on missing slices
div_seq = ((1, 1, 0), (1, 2, 0), (1, 1, 1))
fake_mf.update(fake_shape_dependents(div_seq, sid_dim=0))
with pytest.raises(didw.WrapperError):
MFW(fake_mf).image_shape
# check 3D shape when there is no StackID index
div_seq = ((1,), (2,), (3,), (4,))
sid_seq = (1, 1, 1, 1)
Expand Down Expand Up @@ -614,6 +624,11 @@ def test_shape(self):
div_seq = ((1, 1, 1), (2, 1, 1), (1, 1, 2), (2, 1, 2), (1, 1, 3), (2, 1, 3))
fake_mf.update(fake_shape_dependents(div_seq, sid_dim=1))
assert MFW(fake_mf).image_shape == (32, 64, 2, 3)
# Check non-singular dimension preceding slice dim raises
div_seq = ((1, 1, 1), (1, 2, 1), (1, 1, 2), (1, 2, 2), (1, 1, 3), (1, 2, 3))
fake_mf.update(fake_shape_dependents(div_seq, sid_dim=0, slice_dim=2))
with pytest.raises(didw.WrapperError):
MFW(fake_mf).image_shape
# Test with combo indices, here with the last two needing to be combined into
# a single index corresponding to [(1, 1), (1, 1), (2, 1), (2, 1), (2, 2), (2, 2)]
div_seq = (
Expand Down Expand Up @@ -655,6 +670,22 @@ def test_shape(self):
)
fake_mf.update(fake_shape_dependents(div_seq, sid_dim=0))
assert MFW(fake_mf).image_shape == (32, 64, 2, 3, 2)
# Check we only allow one extra spatial dimension with unique val per frame
div_seq = (
(1, 1, 1, 6),
(1, 2, 2, 5),
(1, 1, 3, 4),
(1, 2, 4, 3),
(1, 1, 5, 2),
(1, 2, 6, 1),
)
fake_mf.update(fake_shape_dependents(div_seq, sid_dim=0))
with pytest.raises(didw.WrapperError):
MFW(fake_mf).image_shape
# Check that having unique value per frame works with single volume
div_seq = ((1, 1, 1), (1, 2, 2), (1, 3, 3))
fake_mf.update(fake_shape_dependents(div_seq, sid_dim=0))
assert MFW(fake_mf).image_shape == (32, 64, 3)

def test_iop(self):
# Test Image orient patient for multiframe
Expand Down

0 comments on commit b6de200

Please sign in to comment.