Open yarikoptic opened 1 year ago
IIRC, dcm2niix uses (used?) 1 return codes for warnings (but conversion still occurred), and 2+ for serious problems where conversion was not possible.
might be... from https://github.com/rordenlab/dcm2niix/issues/733#issuecomment-1646261249 by @neurolabusc
Exit code 0 is for success, exit code 1 is the undefined error. Other exit codes are for clearly defined errors.
so I guess I will quickly send a PR.
IIRC, dcm2niix uses (used?) 1 return codes for warnings (but conversion still occurred), and 2+ for serious problems where conversion was not possible.
seems to be not the case: when we took a philips dicoms series and removed only 10 (out of 60) of the last dynamic via
/bin/ls -1 *dcm | sort -n --key 3 -t- | tail -n 10 | xargs rm
dcm2niix v1.0.20220720
exited with 1 and no .nii.gz was produced:
❯ dcm2niix -z y -b y *dcm && echo allgood || echo "error $?"
Chris Rorden's dcm2niiX version v1.0.20220720 (JP2:OpenJPEG) GCC13.2.0 x86-64 (64-bit Linux)
Warning: only processing last of 22970 input files (recompile with 'myEnableMultipleInputs' to recursively process multiple files)
Found 22970 DICOM file(s)
DICOM images may be missing, expected 60 spatial locations per volume, but found 22970 slices.
Slice positions repeated, but number of slices (22970) not divisible by number of repeats (383): missing images?
Hint: expected 60 locations
Error: Check sorted order: 4D dataset has 1 volumes, but volume index ranges from 1..383
Warning: Interslice distance varies in this volume (incompatible with NIfTI format).
Unable to equalize slice distances: slice order not consistently ascending.
First spatial position repeated 383 times
Error: Recompiling with '-DmyInstanceNumberOrderIsNotSpatial' might help.
dcm2niix -z y -b y *dcm 4.66s user 0.39s system 99% cpu 5.059 total
error 1
❯ lst
total 4
lrwxrwxrwx 1 yoh yoh 124 Dec 7 13:30 1.3.46.670589.11.23033.5.0.6668.2017120710301462010-701-22921-1ls1fpe.dcm -> .git/annex/objects/4v/qk/MD5E-s27668--8c4ab9ec8852113d3b502df2cfac43d0.dcm/MD5E-s27668--8c4ab9ec8852113d3b502df2cfac43d0.dcm*
...
To clarify, dcm2niix returns a 0 on success, and non-zero for failure. The error codes are here:
You can see that removing a slice does cause an error (exit 1). In a situation like this, dcm2niix will return exit 10 if the DICOM files explicitly report the number of volumes in the series, but 1 if it is unclear if this was intended.
git clone git@github.com:neurolabusc/dcm_qa_philips.git
cd dcm_qa_philips/In/Bangalore_2008/dwi_no-phi
rm IM_2040
dcm2niix -f %s ./
Chris Rorden's dcm2niiX version v1.0.20231111 Clang14.0.3 ARM (64-bit MacOS)
Found 2039 DICOM file(s)
DICOM images may be missing, expected 60 spatial locations per volume, but found 2039 slices.
Slice positions repeated, but number of slices (2039) not divisible by number of repeats (34): missing images?
...
$ echo $?
$ 1
Removing an entire volume will typically not generate an error, as most DICOM files do not explicitly report the number of volumes expected in the series. One would expect identical DICOMs for a series with 59 volumes as from a series with 60 volumes where the sequence was aborted before the last volume was acquired.
the problem here is that we have behavior of dcm2niix depending on when/how operator interrupted the scan -- if the full dynamic was acquired, (but not all dynamics), dcm2niix issues just an Error to stderr but completes the conversion and exits with 0. So, once in 60 (numbers of slices) cases we would succeed when otherwise would fail.
@yarikoptic dcm2niix is limited to information from the files it is provided. I suggest you work with your Philips clinical scientist to see if the number of volumes can be included in future DICOMs. Happy to update dcm2niix if this information is encoded.
Summary
Originally observed by @dnkennedy while running
heudiconv
on what appears to be incomplete series. then reproduced on some shorter case of 3 slices dicoms picked up from 10k of them (can't share, didn't find any public ones).Actual behavior
The point is that if we have
reproducing execution with nipype:
which produces
so -- it runs, dcm2niix exits with 1, nipype does not fail it, as it does e.g. when dcm2niix exits with 2:
Expected behavior
have an exception similar to when exits with code 2
How to replicate the behavior
see above by BYOBD (bring your own broken dicom)