Skip to content

Commit

Permalink
Tweaks to DICOM error handling and directory input (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
wtclarke authored Feb 5, 2023
1 parent f39aacb commit c489e7a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
This document contains the Spec2nii release history in reverse chronological order.

0.6.2 (Saturday 4th February 2023)
0.6.2 (Sunday 5th February 2023)
----------------------------------
- Handle HYPER references in SPAR/SDAT pipeline
- Handle HURCULES/HERMES (smm_svs_herc) sequence in XA twix format.
- Changed behaviour of Siemens DICOM `spec2nii dicom` to recursively glob directory argument.
- Better error output when encountering MR Image SOPClassUID.

0.6.1 (Wednesday 18th January 2023)
-----------------------------------
Expand Down
29 changes: 23 additions & 6 deletions spec2nii/Siemens/dicomfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,19 @@ def xa_or_vx(img):
elif img.dcm_data.SOPClassUID == '1.2.840.10008.5.1.4.1.1.4.2':
return 'xa'
else:
raise IncompatibleSOPClassUID(
'spec2nii does not recognise this SOPClassUID '
f'{img.dcm_data.SOPClassUID}. This data was collected on a'
f' {img.dcm_data.SoftwareVersions} baseline scanner.'
' spec2nii is tested on VA-VE, and XA20 and XA30 DICOM files.')
if img.dcm_data.SOPClassUID == '1.2.840.10008.5.1.4.1.1.4':
raise IncompatibleSOPClassUID(
f'spec2nii detected SOPClassUID {img.dcm_data.SOPClassUID}.'
' This normaly contains MR imaging (not spectroscopy) data.'
' This data was collected on a'
f' {img.dcm_data.SoftwareVersions} baseline scanner.'
' spec2nii is tested on VA-VE, XA20, and XA30 DICOM files.')
else:
raise IncompatibleSOPClassUID(
'spec2nii does not recognise this SOPClassUID '
f'{img.dcm_data.SOPClassUID} as MRS data. This data was collected on a'
f' {img.dcm_data.SoftwareVersions} baseline scanner.'
' spec2nii is tested on VA-VE, XA20, and XA30 DICOM files.')


def svs_or_CSI(img):
Expand Down Expand Up @@ -89,7 +97,16 @@ def multi_file_dicom(files_in, fname_out, tag, verbose):

img = nibabel.nicom.dicomwrappers.wrapper_from_file(fn)

mrs_type = svs_or_CSI(img)
try:
mrs_type = svs_or_CSI(img)
except IncompatibleSOPClassUID as exc:
if len(files_in) == 1:
raise exc
else:
print(f'Skipping {fn}.')
print('Raised IncompatibleSOPClassUID error. Moving to next file.')
print(f'Message: {str(exc)}\n')
continue

if mrs_type == 'SVS':
specDataCmplx, orientation, dwelltime, meta_obj = process_siemens_svs(img, verbose=verbose)
Expand Down
6 changes: 3 additions & 3 deletions spec2nii/spec2nii.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,9 @@ def dicom(self, args):
path_in = Path(args.file)
if path_in.is_dir():
# Look for typical dicom file extensions
files_in = sorted(path_in.glob('*.IMA')) + \
sorted(path_in.glob('*.ima')) + \
sorted(path_in.glob('*.dcm'))
files_in = sorted(path_in.rglob('*.IMA')) + \
sorted(path_in.rglob('*.ima')) + \
sorted(path_in.rglob('*.dcm'))

# If none found look for all files
if len(files_in) == 0:
Expand Down

0 comments on commit c489e7a

Please sign in to comment.