Skip to content

Commit b7a3e96

Browse files
committed
ignore the CSA string if it can't be read
1 parent b46efa3 commit b7a3e96

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

nibabel/nicom/csareader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def read(csa_str):
100100
csa_dict['n_tags'], csa_dict['check'] = up_str.unpack('2I')
101101
if not 0 < csa_dict['n_tags'] <= MAX_CSA_ITEMS:
102102
raise CSAReadError('Number of tags `t` should be '
103-
'0 < t <= %d' % MAX_CSA_ITEMS)
103+
'0 < t <= %d. Instead found %d tags.' % (MAX_CSA_ITEMS, csa_dict['n_tags']))
104104
for tag_no in range(csa_dict['n_tags']):
105105
name, vm, vr, syngodt, n_items, last3 = \
106106
up_str.unpack('64si4s3i')

nibabel/nicom/dicomwrappers.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,12 @@ def wrapper_from_data(dcm_data):
7979
return MultiframeWrapper(dcm_data)
8080
# Check for Siemens DICOM format types
8181
# Only Siemens will have data for the CSA header
82-
csa = csar.get_csa_header(dcm_data)
82+
try:
83+
csa = csar.get_csa_header(dcm_data)
84+
except csar.CSAReadError as e:
85+
warnings.warn('Error while attempting to read CSA header: '+
86+
str(e.args) + '\n ignoring Siemens private (CSA) header info.')
87+
csa = None
8388
if csa is None:
8489
return Wrapper(dcm_data)
8590
if csar.is_mosaic(csa):

0 commit comments

Comments
 (0)