From 32703b020fb44461088850eed09566827bdcb018 Mon Sep 17 00:00:00 2001 From: Chris Bridge Date: Thu, 1 Feb 2024 12:34:29 +0000 Subject: [PATCH] Add multiframe tests --- tests/test_multiframe.py | 27 +++++++++++++++++++++++++++ tests/test_spatial.py | 25 +++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 tests/test_multiframe.py diff --git a/tests/test_multiframe.py b/tests/test_multiframe.py new file mode 100644 index 00000000..e0927a79 --- /dev/null +++ b/tests/test_multiframe.py @@ -0,0 +1,27 @@ +"""Tests for the highdicom._multiframe module.""" +from pydicom import dcmread +from pydicom.data import get_testdata_file, get_testdata_files + +from highdicom._multiframe import MultiFrameDBManager + + +def test_slice_spacing(): + ct_multiframe = dcmread( + get_testdata_file('eCT_Supplemental.dcm') + ) + db = MultiFrameDBManager(ct_multiframe) + + assert db.get_slice_spacing() == 10.0 + +def test_slice_spacing_irregular(): + ct_multiframe = dcmread( + get_testdata_file('eCT_Supplemental.dcm') + ) + + # Mock some iregular spacings + ct_multiframe.PerFrameFunctionalGroupsSequence[0].\ + PlanePositionSequence[0].ImagePositionPatient = [1.0, 0.0, 0.0] + + db = MultiFrameDBManager(ct_multiframe) + + assert db.get_slice_spacing() is None diff --git a/tests/test_spatial.py b/tests/test_spatial.py index bce8d1f5..d1717c9b 100644 --- a/tests/test_spatial.py +++ b/tests/test_spatial.py @@ -1,4 +1,6 @@ import numpy as np +from pydicom import dcmread +from pydicom.data import get_testdata_file, get_testdata_files import pytest from highdicom.spatial import ( @@ -6,6 +8,7 @@ PixelToReferenceTransformer, ReferenceToImageTransformer, ReferenceToPixelTransformer, + get_series_slice_spacing, ) @@ -451,3 +454,25 @@ def test_map_reference_to_image_coordinate(params, inputs, expected_outputs): transform = ReferenceToImageTransformer(**params) outputs = transform(inputs) np.testing.assert_array_almost_equal(outputs, expected_outputs) + + +def test_get_series_slice_spacing_irregular(): + # A series of single frame CT images + ct_series = [ + dcmread(f) + for f in get_testdata_files('dicomdirtests/77654033/CT2/*') + ] + spacing = get_series_slice_spacing(ct_series) + assert spacing is None + + +def test_get_series_slice_spacing_regular(): + # Use a subset of this test series that does have regular spacing + ct_files = [ + get_testdata_file('dicomdirtests/77654033/CT2/17196'), + get_testdata_file('dicomdirtests/77654033/CT2/17136'), + get_testdata_file('dicomdirtests/77654033/CT2/17166'), + ] + ct_series = [dcmread(f) for f in ct_files] + spacing = get_series_slice_spacing(ct_series) + assert spacing == 1.25