Heudiconv fails to parse some Heidelberg DICOMs #5

Open
opened 2025-05-07 15:48:26 +00:00 by msz · 1 comment
Member

Heudiconv fails to parse some of the DICOMs from the Heidelberg phantom dataset while grouping them.

Traceback
❱ heudiconv --files phantom-mri-dicom-heidelberg/Test -o Nifti --heuristic convertall -c none --bids --minmeta --overwrite
WARNING: Could not check for version updates: Connection to server could not be made
INFO: Running heudiconv version 1.3.3 latest Unknown
INFO: Analyzing 1118 dicoms
Traceback (most recent call last):
  File "/home/mszczepanik/.virtualenvs/trr-dicom-bids-utils/lib/python3.11/site-packages/nibabel/nicom/dicomwrappers.py", line 749, in image_shape
    [frame.FrameContentSequence[0].DimensionIndexValues for frame in self.frames]
  File "/home/mszczepanik/.virtualenvs/trr-dicom-bids-utils/lib/python3.11/site-packages/nibabel/nicom/dicomwrappers.py", line 749, in <listcomp>
    [frame.FrameContentSequence[0].DimensionIndexValues for frame in self.frames]
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mszczepanik/.virtualenvs/trr-dicom-bids-utils/lib/python3.11/site-packages/pydicom/dataset.py", line 918, in __getattr__
    return object.__getattribute__(self, name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Dataset' object has no attribute 'DimensionIndexValues'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/mszczepanik/.virtualenvs/trr-dicom-bids-utils/bin/heudiconv", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/mszczepanik/.virtualenvs/trr-dicom-bids-utils/lib/python3.11/site-packages/heudiconv/cli/run.py", line 30, in main
    workflow(**kwargs)
  File "/home/mszczepanik/.virtualenvs/trr-dicom-bids-utils/lib/python3.11/site-packages/heudiconv/main.py", line 410, in workflow
    study_sessions = get_study_sessions(
                     ^^^^^^^^^^^^^^^^^^^
  File "/home/mszczepanik/.virtualenvs/trr-dicom-bids-utils/lib/python3.11/site-packages/heudiconv/parser.py", line 240, in get_study_sessions
    seqinfo_dict = group_dicoms_into_seqinfos(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mszczepanik/.virtualenvs/trr-dicom-bids-utils/lib/python3.11/site-packages/heudiconv/dicoms.py", line 338, in group_dicoms_into_seqinfos
    mwinfo = validate_dicom(filename, dcmfilter)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mszczepanik/.virtualenvs/trr-dicom-bids-utils/lib/python3.11/site-packages/heudiconv/dicoms.py", line 175, in validate_dicom
    del mw.series_signature[sig]
        ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/functools.py", line 1001, in __get__
    val = self.func(instance)
          ^^^^^^^^^^^^^^^^^^^
  File "/home/mszczepanik/.virtualenvs/trr-dicom-bids-utils/lib/python3.11/site-packages/nibabel/nicom/dicomwrappers.py", line 886, in series_signature
    signature['image_shape'] = (self.image_shape, eq)
                                ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/functools.py", line 1001, in __get__
    val = self.func(instance)
          ^^^^^^^^^^^^^^^^^^^
  File "/home/mszczepanik/.virtualenvs/trr-dicom-bids-utils/lib/python3.11/site-packages/nibabel/nicom/dicomwrappers.py", line 752, in image_shape
    raise WrapperError("Can't find frame 'DimensionIndexValues'")
nibabel.nicom.dicomwrappers.WrapperError: Can't find frame 'DimensionIndexValues'

Looking at the traceback, the error comes from Heudiconv's dicoms.validate_dicom, and can be further narrowed down to nibabel.nicom.dicomwrapper -- creating a wrapper object (MultiframeWrapper) for a "problematic" file and accessing its series_signature or image_shape property reproduces the error:

Minimal reproducer
>>> import nibabel.nicom.dicomwrappers as dw
<stdin>:1: UserWarning: The DICOM readers are highly experimental, unstable, and only work for Siemens time-series at the moment
Please use with caution.  We would be grateful for your help in improving them
>>> mw = dw.wrapper_from_file("Test_TRR_Q01.MR.Psychiatrie_lau.20.32.2025.02.28.11.22.51.644.36442971.dcm")
>>> mw
<nibabel.nicom.dicomwrappers.MultiframeWrapper object at 0x7f72bf704090>
>>> mw.image_shape
Traceback (most recent call last):
  File "/home/mszczepanik/.virtualenvs/trr-dicom-bids-utils/lib/python3.11/site-packages/nibabel/nicom/dicomwrappers.py", line 749, in image_shape
    [frame.FrameContentSequence[0].DimensionIndexValues for frame in self.frames]
  File "/home/mszczepanik/.virtualenvs/trr-dicom-bids-utils/lib/python3.11/site-packages/nibabel/nicom/dicomwrappers.py", line 749, in <listcomp>
    [frame.FrameContentSequence[0].DimensionIndexValues for frame in self.frames]
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mszczepanik/.virtualenvs/trr-dicom-bids-utils/lib/python3.11/site-packages/pydicom/dataset.py", line 918, in __getattr__
    return object.__getattribute__(self, name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Dataset' object has no attribute 'DimensionIndexValues'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.11/functools.py", line 1001, in __get__
    val = self.func(instance)
          ^^^^^^^^^^^^^^^^^^^
  File "/home/mszczepanik/.virtualenvs/trr-dicom-bids-utils/lib/python3.11/site-packages/nibabel/nicom/dicomwrappers.py", line 752, in image_shape
    raise WrapperError("Can't find frame 'DimensionIndexValues'")
nibabel.nicom.dicomwrappers.WrapperError: Can't find frame 'DimensionIndexValues'

Looping through the files and catching these errors shows that the problem affects 189 out of 1118 DICOM files from the dataset -- those with names containing Psychiatrie_lau.[15-20]. These appear to be diffusion images.

These files are readable for pydicom or dicom-dump, but indeed some dimension information seems to be missing compared to other files. For example, this compares a file that causes Heudiconv errors with another one that parses correctly:

❱ dicom-dump Test_TRR_Q01.MR.Psychiatrie_lau.20.32.2025.02.28.11.22.51.644.36442971.dcm | rg DimensionIndex
Test_TRR_Q01.MR.Psychiatrie_lau.20.32.2025.02.28.11.22.51.644.36442971.dcm:
(0020,9222) DimensionIndexSequence       SQ (0 Items)

❱ dicom-dump Test_TRR_Q01.MR.Psychiatrie_lau.14.100.2025.02.28.11.22.51.644.36439363.dcm | rg DimensionIndex
Test_TRR_Q01.MR.Psychiatrie_lau.14.100.2025.02.28.11.22.51.644.36439363.dcm:
(0020,9222) DimensionIndexSequence       SQ (3 Items)
      (0020,9165) DimensionIndexPointer        AT (1,  4 bytes): (0020,9056)
      (0020,9165) DimensionIndexPointer        AT (1,  4 bytes): (0020,9057)
      (0020,9165) DimensionIndexPointer        AT (1,  4 bytes): (0020,9128)
            (0020,9157) DimensionIndexValues         UL (3, 12 bytes): [1, 1, 100]
            (0020,9157) DimensionIndexValues         UL (3, 12 bytes): [1, 2, 100]
            (0020,9157) DimensionIndexValues         UL (3, 12 bytes): [1, 3, 100]
...
            (0020,9157) DimensionIndexValues         UL (3, 12 bytes): [1, 72, 100]

Is there anything special about these images? They seem to be enhanced / multiframe DICOMs from Siemens. Is there a more precise name? Should this be reported upstream (to nibabel), or is it a problem with the acquisition?

Heudiconv fails to parse some of the DICOMs from the [Heidelberg phantom dataset](https://hub.trr379.de/q01/phantom-mri-dicom-heidelberg) while grouping them. <details> <summary>Traceback</summary> ``` ❱ heudiconv --files phantom-mri-dicom-heidelberg/Test -o Nifti --heuristic convertall -c none --bids --minmeta --overwrite WARNING: Could not check for version updates: Connection to server could not be made INFO: Running heudiconv version 1.3.3 latest Unknown INFO: Analyzing 1118 dicoms Traceback (most recent call last): File "/home/mszczepanik/.virtualenvs/trr-dicom-bids-utils/lib/python3.11/site-packages/nibabel/nicom/dicomwrappers.py", line 749, in image_shape [frame.FrameContentSequence[0].DimensionIndexValues for frame in self.frames] File "/home/mszczepanik/.virtualenvs/trr-dicom-bids-utils/lib/python3.11/site-packages/nibabel/nicom/dicomwrappers.py", line 749, in <listcomp> [frame.FrameContentSequence[0].DimensionIndexValues for frame in self.frames] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/mszczepanik/.virtualenvs/trr-dicom-bids-utils/lib/python3.11/site-packages/pydicom/dataset.py", line 918, in __getattr__ return object.__getattribute__(self, name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'Dataset' object has no attribute 'DimensionIndexValues' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/mszczepanik/.virtualenvs/trr-dicom-bids-utils/bin/heudiconv", line 8, in <module> sys.exit(main()) ^^^^^^ File "/home/mszczepanik/.virtualenvs/trr-dicom-bids-utils/lib/python3.11/site-packages/heudiconv/cli/run.py", line 30, in main workflow(**kwargs) File "/home/mszczepanik/.virtualenvs/trr-dicom-bids-utils/lib/python3.11/site-packages/heudiconv/main.py", line 410, in workflow study_sessions = get_study_sessions( ^^^^^^^^^^^^^^^^^^^ File "/home/mszczepanik/.virtualenvs/trr-dicom-bids-utils/lib/python3.11/site-packages/heudiconv/parser.py", line 240, in get_study_sessions seqinfo_dict = group_dicoms_into_seqinfos( ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/mszczepanik/.virtualenvs/trr-dicom-bids-utils/lib/python3.11/site-packages/heudiconv/dicoms.py", line 338, in group_dicoms_into_seqinfos mwinfo = validate_dicom(filename, dcmfilter) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/mszczepanik/.virtualenvs/trr-dicom-bids-utils/lib/python3.11/site-packages/heudiconv/dicoms.py", line 175, in validate_dicom del mw.series_signature[sig] ^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/functools.py", line 1001, in __get__ val = self.func(instance) ^^^^^^^^^^^^^^^^^^^ File "/home/mszczepanik/.virtualenvs/trr-dicom-bids-utils/lib/python3.11/site-packages/nibabel/nicom/dicomwrappers.py", line 886, in series_signature signature['image_shape'] = (self.image_shape, eq) ^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/functools.py", line 1001, in __get__ val = self.func(instance) ^^^^^^^^^^^^^^^^^^^ File "/home/mszczepanik/.virtualenvs/trr-dicom-bids-utils/lib/python3.11/site-packages/nibabel/nicom/dicomwrappers.py", line 752, in image_shape raise WrapperError("Can't find frame 'DimensionIndexValues'") nibabel.nicom.dicomwrappers.WrapperError: Can't find frame 'DimensionIndexValues' ``` </details> Looking at the traceback, the error comes from Heudiconv's `dicoms.validate_dicom`, and can be further narrowed down to `nibabel.nicom.dicomwrapper` -- creating a wrapper object (`MultiframeWrapper`) for a "problematic" file and accessing its `series_signature` or `image_shape` property reproduces the error: <details> <summary>Minimal reproducer</summary> ``` >>> import nibabel.nicom.dicomwrappers as dw <stdin>:1: UserWarning: The DICOM readers are highly experimental, unstable, and only work for Siemens time-series at the moment Please use with caution. We would be grateful for your help in improving them >>> mw = dw.wrapper_from_file("Test_TRR_Q01.MR.Psychiatrie_lau.20.32.2025.02.28.11.22.51.644.36442971.dcm") >>> mw <nibabel.nicom.dicomwrappers.MultiframeWrapper object at 0x7f72bf704090> >>> mw.image_shape Traceback (most recent call last): File "/home/mszczepanik/.virtualenvs/trr-dicom-bids-utils/lib/python3.11/site-packages/nibabel/nicom/dicomwrappers.py", line 749, in image_shape [frame.FrameContentSequence[0].DimensionIndexValues for frame in self.frames] File "/home/mszczepanik/.virtualenvs/trr-dicom-bids-utils/lib/python3.11/site-packages/nibabel/nicom/dicomwrappers.py", line 749, in <listcomp> [frame.FrameContentSequence[0].DimensionIndexValues for frame in self.frames] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/mszczepanik/.virtualenvs/trr-dicom-bids-utils/lib/python3.11/site-packages/pydicom/dataset.py", line 918, in __getattr__ return object.__getattribute__(self, name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'Dataset' object has no attribute 'DimensionIndexValues' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python3.11/functools.py", line 1001, in __get__ val = self.func(instance) ^^^^^^^^^^^^^^^^^^^ File "/home/mszczepanik/.virtualenvs/trr-dicom-bids-utils/lib/python3.11/site-packages/nibabel/nicom/dicomwrappers.py", line 752, in image_shape raise WrapperError("Can't find frame 'DimensionIndexValues'") nibabel.nicom.dicomwrappers.WrapperError: Can't find frame 'DimensionIndexValues' ``` </details> Looping through the files and catching these errors shows that the problem affects 189 out of 1118 DICOM files from the dataset -- those with names containing `Psychiatrie_lau.[15-20]`. These appear to be diffusion images. These files are readable for pydicom or [dicom-dump](https://github.com/Enet4/dicom-rs), but indeed some dimension information seems to be missing compared to other files. For example, this compares a file that causes Heudiconv errors with another one that parses correctly: ``` ❱ dicom-dump Test_TRR_Q01.MR.Psychiatrie_lau.20.32.2025.02.28.11.22.51.644.36442971.dcm | rg DimensionIndex Test_TRR_Q01.MR.Psychiatrie_lau.20.32.2025.02.28.11.22.51.644.36442971.dcm: (0020,9222) DimensionIndexSequence SQ (0 Items) ❱ dicom-dump Test_TRR_Q01.MR.Psychiatrie_lau.14.100.2025.02.28.11.22.51.644.36439363.dcm | rg DimensionIndex Test_TRR_Q01.MR.Psychiatrie_lau.14.100.2025.02.28.11.22.51.644.36439363.dcm: (0020,9222) DimensionIndexSequence SQ (3 Items) (0020,9165) DimensionIndexPointer AT (1, 4 bytes): (0020,9056) (0020,9165) DimensionIndexPointer AT (1, 4 bytes): (0020,9057) (0020,9165) DimensionIndexPointer AT (1, 4 bytes): (0020,9128) (0020,9157) DimensionIndexValues UL (3, 12 bytes): [1, 1, 100] (0020,9157) DimensionIndexValues UL (3, 12 bytes): [1, 2, 100] (0020,9157) DimensionIndexValues UL (3, 12 bytes): [1, 3, 100] ... (0020,9157) DimensionIndexValues UL (3, 12 bytes): [1, 72, 100] ``` Is there anything special about these images? They seem to be enhanced / multiframe DICOMs from Siemens. Is there a more precise name? Should this be reported upstream (to nibabel), or is it a problem with the acquisition?
Author
Member

Trying to use dcm2niix directly on these files (specifically, Psychiatrie_lau.20.*) I obtain a conversion (.nii.gz, .json, .bval, .bvec) but for each DICOM file there is a warning, "MOSAIC but number of slices not specified", plus a general warning about slice timing. I am not sure if the sidecar json is complete.

(...)
Warning: 0008,0008=MOSAIC but number of slices not specified: /tmp/lau20/Test_TRR_Q01.MR.Psychiatrie_lau.20.25.2025.02.28.11.22.51.644.36442894.dcm
Warning: Slice timing appears corrupted (range 30182.5..30182.5, TR=2744 ms)
Convert 104 DICOM as /tmp/hdc/lau20_diff_advanced_1p5mm_SMS4_AP_20250228100909_20 (140x140x100x104)
Conversion required 0.838347 seconds (0.838213 for core code).

I am unable to judge if these warnings can be safely ignored or not, but they are consistent with the earlier suggestion that something is missing from the headers.

Trying to use dcm2niix directly on these files (specifically, `Psychiatrie_lau.20.*`) I obtain a conversion (.nii.gz, .json, .bval, .bvec) but for each DICOM file there is a warning, "MOSAIC but number of slices not specified", plus a general warning about slice timing. I am not sure if the sidecar json is complete. ``` (...) Warning: 0008,0008=MOSAIC but number of slices not specified: /tmp/lau20/Test_TRR_Q01.MR.Psychiatrie_lau.20.25.2025.02.28.11.22.51.644.36442894.dcm Warning: Slice timing appears corrupted (range 30182.5..30182.5, TR=2744 ms) Convert 104 DICOM as /tmp/hdc/lau20_diff_advanced_1p5mm_SMS4_AP_20250228100909_20 (140x140x100x104) Conversion required 0.838347 seconds (0.838213 for core code). ``` I am unable to judge if these warnings can be safely ignored or not, but they are consistent with the earlier suggestion that *something* is missing from the headers.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
q02/phantom-mri-bids#5
No description provided.