Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nibabel-data/nitest-dicom
3 changes: 2 additions & 1 deletion nibabel/nicom/csareader.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def read(csa_str):
csa_dict['n_tags'], csa_dict['check'] = up_str.unpack('2I')
if not 0 < csa_dict['n_tags'] <= MAX_CSA_ITEMS:
raise CSAReadError('Number of tags `t` should be '
'0 < t <= %d' % MAX_CSA_ITEMS)
'0 < t <= %d. Instead found %d tags.'
% (MAX_CSA_ITEMS, csa_dict['n_tags']))
for tag_no in range(csa_dict['n_tags']):
name, vm, vr, syngodt, n_items, last3 = \
up_str.unpack('64si4s3i')
Expand Down
8 changes: 7 additions & 1 deletion nibabel/nicom/dicomwrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@ def wrapper_from_data(dcm_data):
return MultiframeWrapper(dcm_data)
# Check for Siemens DICOM format types
# Only Siemens will have data for the CSA header
csa = csar.get_csa_header(dcm_data)
try:
csa = csar.get_csa_header(dcm_data)
except csar.CSAReadError as e:
warnings.warn('Error while attempting to read CSA header: ' +
str(e.args) +
'\n Ignoring Siemens private (CSA) header info.')
csa = None
if csa is None:
return Wrapper(dcm_data)
if csar.is_mosaic(csa):
Expand Down
11 changes: 10 additions & 1 deletion nibabel/nicom/tests/test_dicomwrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from nose.tools import (assert_true, assert_false, assert_equal,
assert_not_equal, assert_raises)

from numpy.testing import assert_array_equal, assert_array_almost_equal
from numpy.testing import assert_array_equal, assert_array_almost_equal, assert_warns
from ...tests.nibabel_data import get_nibabel_data, needs_nibabel_data

IO_DATA_PATH = pjoin(dirname(__file__), 'data')
Expand All @@ -39,6 +39,8 @@
DATA_FILE_EMPTY_ST = pjoin(IO_DATA_PATH, 'slicethickness_empty_string.dcm')
DATA_FILE_4D_DERIVED = pjoin(get_nibabel_data(), 'nitest-dicom',
'4d_multiframe_with_derived.dcm')
DATA_FILE_CT = pjoin(get_nibabel_data(), 'nitest-dicom',
'siemens_ct_header_csa.dcm')

# This affine from our converted image was shown to match our image spatially
# with an image from SPM DICOM conversion. We checked the matching with SPM
Expand Down Expand Up @@ -633,6 +635,13 @@ def test_data_derived_shape(self):
dw = didw.wrapper_from_file(DATA_FILE_4D_DERIVED)
assert_equal(dw.image_shape, (96, 96, 60, 33))

@dicom_test
@needs_nibabel_data('nitest-dicom')
def test_data_unreadable_private_headers(self):
# Test CT image with unreadable CSA tags
dw = assert_warns(UserWarning, didw.wrapper_from_file, DATA_FILE_CT)
assert_equal(dw.image_shape, (512, 571))

@dicom_test
def test_data_fake(self):
# Test algorithm for get_data
Expand Down