diff --git a/.gitmodules b/.gitmodules index cdcef650f1..20e97c2ebb 100644 --- a/.gitmodules +++ b/.gitmodules @@ -19,3 +19,6 @@ [submodule "nibabel-data/nitest-dicom"] path = nibabel-data/nitest-dicom url = https://github.com/effigies/nitest-dicom +[submodule "nibabel-data/dcm_qa_xa30"] + path = nibabel-data/dcm_qa_xa30 + url = https://github.com/neurolabusc/dcm_qa_xa30.git diff --git a/nibabel-data/dcm_qa_xa30 b/nibabel-data/dcm_qa_xa30 new file mode 160000 index 0000000000..89b2509218 --- /dev/null +++ b/nibabel-data/dcm_qa_xa30 @@ -0,0 +1 @@ +Subproject commit 89b2509218a6dd021c5d40ddaf2a017ac1bacafc diff --git a/nibabel/nicom/dicomwrappers.py b/nibabel/nicom/dicomwrappers.py index 42d4b1413f..5ff4f33052 100755 --- a/nibabel/nicom/dicomwrappers.py +++ b/nibabel/nicom/dicomwrappers.py @@ -509,11 +509,14 @@ def image_shape(self): if hasattr(first_frame, 'get') and first_frame.get([0x18, 0x9117]): # DWI image may include derived isotropic, ADC or trace volume try: - self.frames = pydicom.Sequence( + anisotropic = pydicom.Sequence( frame for frame in self.frames if frame.MRDiffusionSequence[0].DiffusionDirectionality != 'ISOTROPIC' ) + # Image contains DWI volumes followed by derived images; remove derived images + if len(anisotropic) != 0: + self.frames = anisotropic except IndexError: # Sequence tag is found but missing items! raise WrapperError('Diffusion file missing information') diff --git a/nibabel/nicom/tests/test_dicomwrappers.py b/nibabel/nicom/tests/test_dicomwrappers.py index 083357537e..5c29349362 100755 --- a/nibabel/nicom/tests/test_dicomwrappers.py +++ b/nibabel/nicom/tests/test_dicomwrappers.py @@ -35,6 +35,11 @@ DATA_FILE_EMPTY_ST = pjoin(IO_DATA_PATH, 'slicethickness_empty_string.dcm') DATA_FILE_4D_DERIVED = pjoin(get_nibabel_data(), 'nitest-dicom', '4d_multiframe_with_derived.dcm') DATA_FILE_CT = pjoin(get_nibabel_data(), 'nitest-dicom', 'siemens_ct_header_csa.dcm') +DATA_FILE_SIEMENS_TRACE = pjoin( + get_nibabel_data(), + 'dcm_qa_xa30', + 'In/20_DWI_dir80_AP/0001_1.3.12.2.1107.5.2.43.67093.2022071112140611403312307.dcm', +) # This affine from our converted image was shown to match our image spatially # with an image from SPM DICOM conversion. We checked the matching with SPM @@ -656,6 +661,13 @@ def test_data_derived_shape(self): with pytest.warns(UserWarning, match='Derived images found and removed'): assert dw.image_shape == (96, 96, 60, 33) + @dicom_test + @needs_nibabel_data('dcm_qa_xa30') + def test_data_trace(self): + # Test that a standalone trace volume is found and not dropped + dw = didw.wrapper_from_file(DATA_FILE_SIEMENS_TRACE) + assert dw.image_shape == (72, 72, 39, 1) + @dicom_test @needs_nibabel_data('nitest-dicom') def test_data_unreadable_private_headers(self):