Dcm2niix Node Nonzero Exit Code

nipype

#1

Hi, there. I’ve been unsuccessfully trying to use dcm2niix to convert a set of DICOM files to nifti. dcm2nii works without error, but when dcm2niix is used, I get the following output.

[MultiProc] Running 1 tasks, and 0 jobs ready. Free memory (GB): 105.29/113.29, Free processors: 7/8.
                     Currently running:
                       * converter.dcm2niix
180221-11:43:20,846 workflow WARNING:
	 [Node] Error on "converter.dcm2niix" (/home/jtfisher/projects/main/nipype/workingdir/converter/_subject_id_sub39/dcm2niix)

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-60-24e115ed6719> in <module>()
     27 
     28 args_dict = {'n_procs': 8}
---> 29 wf.run(plugin='MultiProc', plugin_args=args_dict)
     30 
     31 # Return the timing object

/usr/local/anaconda3/lib/python3.6/site-packages/nipype/pipeline/engine/workflows.py in run(self, plugin, plugin_args, updatehash)
    600         if str2bool(self.config['execution']['create_report']):
    601             self._write_report_info(self.base_dir, self.name, execgraph)
--> 602         runner.run(execgraph, updatehash=updatehash, config=self.config)
    603         datestr = datetime.utcnow().strftime('%Y%m%dT%H%M%S')
    604         if str2bool(self.config['execution']['write_provenance']):

/usr/local/anaconda3/lib/python3.6/site-packages/nipype/pipeline/plugins/base.py in run(self, graph, config, updatehash)
    166                         if result['traceback']:
    167                             notrun.append(
--> 168                                 self._clean_queue(jobid, graph, result=result))
    169                         else:
    170                             self._task_finished_cb(jobid)

/usr/local/anaconda3/lib/python3.6/site-packages/nipype/pipeline/plugins/base.py in _clean_queue(self, jobid, graph, result)
    225 
    226         if str2bool(self._config['execution']['stop_on_first_crash']):
--> 227             raise RuntimeError("".join(result['traceback']))
    228         crashfile = self._report_crash(self.procs[jobid], result=result)
    229         if jobid in self.mapnodesubids:

RuntimeError: Traceback (most recent call last):
  File "/usr/local/anaconda3/lib/python3.6/site-packages/nipype/pipeline/plugins/multiproc.py", line 68, in run_node
    result['result'] = node.run(updatehash=updatehash)
  File "/usr/local/anaconda3/lib/python3.6/site-packages/nipype/pipeline/engine/nodes.py", line 487, in run
    result = self._run_interface(execute=True)
  File "/usr/local/anaconda3/lib/python3.6/site-packages/nipype/pipeline/engine/nodes.py", line 571, in _run_interface
    return self._run_command(execute)
  File "/usr/local/anaconda3/lib/python3.6/site-packages/nipype/pipeline/engine/nodes.py", line 650, in _run_command
    result = self._interface.run(cwd=outdir)
  File "/usr/local/anaconda3/lib/python3.6/site-packages/nipype/interfaces/base/core.py", line 515, in run
    runtime = self._run_interface(runtime)
  File "/usr/local/anaconda3/lib/python3.6/site-packages/nipype/interfaces/dcm2nii.py", line 347, in _run_interface
    new_runtime = super(Dcm2niix, self)._run_interface(runtime)
  File "/usr/local/anaconda3/lib/python3.6/site-packages/nipype/interfaces/base/core.py", line 1022, in _run_interface
    self.raise_exception(runtime)
  File "/usr/local/anaconda3/lib/python3.6/site-packages/nipype/interfaces/base/core.py", line 959, in raise_exception
    ).format(**runtime.dictcopy()))
RuntimeError: Command:
dcm2niix -b y -z i -x n -t n -m n -f %t%p -o /home/jtfisher/projects/main/nipype/workingdir/converter/_subject_id_sub39/dcm2niix -s n -v n /home/jtfisher/projects/main/raw/study_20160913_161817.726000_13sep16_sub39_1230a
Standard output:
Chris Rorden's dcm2niiX version v1.0.20171215 GCC5.4.0 (64-bit Linux)
Found 4260 DICOM image(s)
slices stacked despite varying acquisition numbers (if this is not desired please recompile)
Convert 756 DICOM as /home/jtfisher/projects/main/nipype/workingdir/converter/_subject_id_sub39/dcm2niix/20160913161818cmrr_epi_mb_R013_Voice_M (104x104x72x756)
slices stacked despite varying acquisition numbers (if this is not desired please recompile)
Convert 1166 DICOM as /home/jtfisher/projects/main/nipype/workingdir/converter/_subject_id_sub39/dcm2niix/20160913161818cmrr_epi_mb_R013_Poll_Ad (104x104x72x1166)
slices stacked despite varying acquisition numbers (if this is not desired please recompile)
Convert 577 DICOM as /home/jtfisher/projects/main/nipype/workingdir/converter/_subject_id_sub39/dcm2niix/20160913161818cmrr_epi_mb_R013_MFTL_2 (104x104x72x577)
slices stacked despite varying acquisition numbers (if this is not desired please recompile)
Convert 573 DICOM as /home/jtfisher/projects/main/nipype/workingdir/converter/_subject_id_sub39/dcm2niix/20160913161818cmrr_epi_mb_R013_MFTL_1 (104x104x72x573)
slices not stacked: echo varies (TE 4.92, 7.38; echo 1, 2). Use 'merge 2D slices' option to force stacking
Dims 104 104 64 1 1
Warning: Interslice distance varies in this volume (incompatible with NIfTI format).
 Distance from first slice:
dx=[0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 34 36 38 40 42 44 46 48 50 54 56 58 60 62 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 100 102 104 106 112 114 116 118 120 122 124 126 128 134 136 138 140 142]
Convert 64 DICOM as /home/jtfisher/projects/main/nipype/workingdir/converter/_subject_id_sub39/dcm2niix/20160913161818gre_field_mapping_2mm (104x104x64x1)
slices stacked despite varying acquisition numbers (if this is not desired please recompile)
Convert 25 DICOM as /home/jtfisher/projects/main/nipype/workingdir/converter/_subject_id_sub39/dcm2niix/20160913161818cmrr_epi_mb_R013_Voice_Ma (104x104x72x25)
slices stacked despite varying acquisition numbers (if this is not desired please recompile)
Convert 578 DICOM as /home/jtfisher/projects/main/nipype/workingdir/converter/_subject_id_sub39/dcm2niix/20160913161818cmrr_epi_mb_R013_MFTL_3 (104x104x72x578)
Dims 256 256 176 1 1
Warning: Interslice distance varies in this volume (incompatible with NIfTI format).
 Distance from first slice:
dx=[0 0.94 1.88 2.82 3.76 4.7 5.64 6.58 7.52 8.46 9.4 10.34 11.28 12.22 13.16 14.1 15.04 15.98 16.92 17.86 18.8 19.74 20.68 21.62 22.56 23.5 24.44 25.38 27.26 28.2 29.14 30.08 31.02 31.96 33.84 34.78 35.72 36.66 37.6 39.48 40.42 41.36 44.18 45.12 47 47.94 48.88 49.82 50.76 53.58 55.46 56.4 57.34 60.16 61.1 62.04 62.98 63.92 64.86 65.8 66.74 67.68 68.62 69.56 70.5 71.44 72.38 74.26 75.2 76.14 77.08 78.02 78.96 79.9 80.84 81.78 82.72 84.6 85.54 87.42 88.36 89.3 90.24 91.18 92.12 93.06 94 94.94 95.88 96.82 97.76 98.7 100.58 101.52 103.4 104.34 105.28 107.16 109.04 109.98 111.86 112.8 113.74 114.68 115.62 117.5 118.44 119.38 120.32 121.26 122.2 125.02 125.96 126.9 127.84 129.72 131.6 132.54 133.48 134.42 136.3 137.24 138.18 141 141.94 142.88 143.82 144.76 145.7 146.64 147.58 148.52 149.46 150.4 153.22 154.16 155.1 156.04 156.98 157.92 158.86 159.8 160.74 161.68 162.62 163.56 165.44 166.38 167.32 168.26 169.2 170.14 171.08 172.02 172.96 174.84 175.78 176.72 177.66 178.6 179.54 180.48 181.42 182.36 183.3 185.18 186.12 187.06 188 188.94 189.88 190.82 191.76 192.7 193.64 194.58]
Convert 176 DICOM as /home/jtfisher/projects/main/nipype/workingdir/converter/_subject_id_sub39/dcm2niix/20160913161818t1_mprage_0.9mm (256x256x176x1)
Dims 104 104 57 1 1
Warning: Interslice distance varies in this volume (incompatible with NIfTI format).
 Distance from first slice:
dx=[0 2 4 6 8 10 12 16 20 22 24 30 32 34 36 38 40 42 48 50 54 56 58 60 62 64 66 68 70 72 76 78 80 84 88 92 94 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 132 134 138 140]
Convert 57 DICOM as /home/jtfisher/projects/main/nipype/workingdir/converter/_subject_id_sub39/dcm2niix/20160913161818gre_field_mapping_2mm_e2 (104x104x57x1)
Dims 256 256 172 1 1
Warning: Interslice distance varies in this volume (incompatible with NIfTI format).
 Distance from first slice:
dx=[0 0.94 1.88 2.82 3.76 4.7 5.64 6.58 8.46 9.4 10.34 12.22 13.16 14.1 15.04 15.98 16.92 17.86 18.8 19.74 20.68 21.62 22.56 23.5 24.44 25.38 26.32 27.26 28.2 29.14 31.02 31.96 32.9 34.78 36.66 38.54 39.48 40.42 41.36 42.3 43.24 44.18 46.06 47 47.94 48.88 49.82 50.76 51.7 52.64 53.58 54.52 55.46 56.4 57.34 59.22 60.16 61.1 62.04 62.98 64.86 66.74 68.62 69.56 70.5 71.44 72.38 73.32 74.26 77.08 78.02 78.96 80.84 81.78 82.72 83.66 84.6 85.54 86.48 87.42 88.36 89.3 90.24 91.18 92.12 93.06 94.94 95.88 98.7 99.64 100.58 101.52 103.4 104.34 105.28 106.22 107.16 109.04 109.98 110.92 112.8 113.74 114.68 115.62 116.56 117.5 118.44 119.38 120.32 122.2 123.14 124.08 125.02 125.96 127.84 128.78 129.72 130.66 131.6 136.3 137.24 138.18 140.06 141 141.94 142.88 143.82 144.76 145.7 147.58 148.52 150.4 151.34 152.28 154.16 155.1 156.04 157.92 158.86 159.8 160.74 162.62 164.5 166.38 167.32 168.26 169.2 170.14 171.08 172.02 172.96 173.9 174.84 175.78 176.72 177.66 178.6 179.54 180.48 181.42 183.3 184.24 185.18 186.12 187.06 188 188.94 189.88 190.82 192.7 193.64 194.58]
Convert 172 DICOM as /home/jtfisher/projects/main/nipype/workingdir/converter/_subject_id_sub39/dcm2niix/20160913161818t2w_space_0.9mm (256x256x172x1)
slices stacked despite varying acquisition numbers (if this is not desired please recompile)
Convert 45 DICOM as /home/jtfisher/projects/main/nipype/workingdir/converter/_subject_id_sub39/dcm2niix/20160913161818cmrr_epi_mb_R013_Voice_Mb (104x104x72x45)
slices not stacked: echo varies (TE 7.38, 4.92; echo 2, 1). Use 'merge 2D slices' option to force stacking
Dims 104 104 63 1 1
Warning: Interslice distance varies in this volume (incompatible with NIfTI format).
 Distance from first slice:
dx=[0 4 6 8 10 12 14 16 18 20 22 24 26 30 34 36 38 40 42 44 46 48 50 52 54 58 60 62 64 66 68 70 72 74 76 78 80 82 86 88 90 92 94 96 98 100 102 106 108 110 112 118 122 124 126 128 130 132 134 136 138 140 142]
Convert 63 DICOM as /home/jtfisher/projects/main/nipype/workingdir/converter/_subject_id_sub39/dcm2niix/20160913161818gre_field_mapping_2mm_e2a (104x104x63x1)
slices not stacked: orientation varies (localizer?) [1 0 0 0 1 0] != [0 1 0 0 0 -1]
Convert 1 DICOM as /home/jtfisher/projects/main/nipype/workingdir/converter/_subject_id_sub39/dcm2niix/20160913161818localizer (512x512x1x1)
Warning: Check that 2D images are not mirrored.
slices not stacked: orientation varies (localizer?) [0 1 0 0 0 -1] != [1 0 0 0 0 -1]
Convert 1 DICOM as /home/jtfisher/projects/main/nipype/workingdir/converter/_subject_id_sub39/dcm2niix/20160913161818localizera (512x512x1x1)
Warning: Check that 2D images are not mirrored.
Warning: Weird CSA 'ProtocolSliceNumber' (System/Miscellaneous/ImageNumbering reversed): VALIDATE SLICETIMING AND BVECS
Convert 1 DICOM as /home/jtfisher/projects/main/nipype/workingdir/converter/_subject_id_sub39/dcm2niix/20160913161818localizerb (512x512x1x1)
Warning: Check that 2D images are not mirrored.
Standard error:

Return code: 1

Ive tried suppressing exceptions using ignore_exception = True as it still seem to create the files correctly, but I get a warning that this functionality is deprecated in nipype 1.0.0.

There does not seem to be a crash file created either, so I’m unable to get any further.


#2

It seems that the dcm2niix return code is not zero. Might be worth investigating why and whether it’s safe to ignore it. All the warnings printed on standard output look rather concerning.


#3

Thanks for the reply! I agree that they are concerning–suggesting problems with the acquisition for this particular subject. It’s strange, though, that dcm2nii has no problem with the same DICOM files–the node completes without error when I use dcm2nii instead of dcm2niix. Dcm2niix also completes when I run it from the command line on the same files (although it still gives me the same warnings). Looking through some forums, it seems that these warnings come from dcm2niix incorrectly reading the DICOM headers whenever acquired with multiband. Is there a way to ignore the 1 thrown from dcm2niix in
Nipype and complete the conversion?


#4

If you think dcm2niix is incorrectly reading headers it might be worth opening an issue here: https://github.com/rordenlab/dcm2niix/issues

BTW dcm2niix is not crashing per se in this situation, but returning a non zero exit code (I believe intentionally) which triggers nipype to raise a warning. More on exit codes: https://shapeshed.com/unix-exit-codes/


#5

Thanks, Chris! I will open an issue with dcm2niix.


#6

Evidently this is a change with the latest version of dcm2niix. Whenever it fails to compile DICOMS into nii files because of varying slice timing it will exit with a non-zero code instead of performing the operation and continuing. When I downgraded to the version that is bundled with MriCroGL the dcm2niix node completed without issue. I would say this is probably a good use case for the ignore exceptions = True argument to the dcm2niix node but it’s deprecated in 1.0.0.

So if anyone else is having this problem and you are comfortable with dcm2niix carrying on despite it being cranky about varying slice times downgrading seems to do the trick.