From b7a3e96e4ebc5392cc43b0b3f70fde0187d02cc0 Mon Sep 17 00:00:00 2001 From: Henry Braun Date: Tue, 17 Sep 2019 10:48:07 -0500 Subject: [PATCH 1/7] ignore the CSA string if it can't be read --- nibabel/nicom/csareader.py | 2 +- nibabel/nicom/dicomwrappers.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/nibabel/nicom/csareader.py b/nibabel/nicom/csareader.py index de2b5dbb1a..9efc5fe12f 100644 --- a/nibabel/nicom/csareader.py +++ b/nibabel/nicom/csareader.py @@ -100,7 +100,7 @@ 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') diff --git a/nibabel/nicom/dicomwrappers.py b/nibabel/nicom/dicomwrappers.py index cd0c1daf67..d9076eaf68 100755 --- a/nibabel/nicom/dicomwrappers.py +++ b/nibabel/nicom/dicomwrappers.py @@ -79,7 +79,12 @@ 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): From 664d05faea3042e9ac7babd502095c5c38c58d4b Mon Sep 17 00:00:00 2001 From: Henry Braun Date: Wed, 18 Sep 2019 11:02:25 -0500 Subject: [PATCH 2/7] fix a typo --- nibabel/nicom/dicomwrappers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nibabel/nicom/dicomwrappers.py b/nibabel/nicom/dicomwrappers.py index d9076eaf68..2bd3345366 100755 --- a/nibabel/nicom/dicomwrappers.py +++ b/nibabel/nicom/dicomwrappers.py @@ -83,7 +83,7 @@ def wrapper_from_data(dcm_data): 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.') + str(e.args) + '\n Ignoring Siemens private (CSA) header info.') csa = None if csa is None: return Wrapper(dcm_data) From e9b9a1081f94ed7163edf15e109663cab6925264 Mon Sep 17 00:00:00 2001 From: Henry Braun Date: Tue, 24 Sep 2019 17:00:56 -0500 Subject: [PATCH 3/7] autopep8 dicomwrappers.py --- nibabel/nicom/dicomwrappers.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/nibabel/nicom/dicomwrappers.py b/nibabel/nicom/dicomwrappers.py index 9038c96a12..6263c8a6f1 100755 --- a/nibabel/nicom/dicomwrappers.py +++ b/nibabel/nicom/dicomwrappers.py @@ -80,11 +80,12 @@ 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 - try: + 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.') + 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) From 7c84be6845ac42dee6cb48b3e4ed6355c353f71e Mon Sep 17 00:00:00 2001 From: Henry Braun Date: Tue, 24 Sep 2019 17:11:16 -0500 Subject: [PATCH 4/7] fix pep8 problems --- nibabel/nicom/csareader.py | 3 ++- nibabel/nicom/dicomwrappers.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/nibabel/nicom/csareader.py b/nibabel/nicom/csareader.py index 9efc5fe12f..86c51302e3 100644 --- a/nibabel/nicom/csareader.py +++ b/nibabel/nicom/csareader.py @@ -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. Instead found %d tags.' % (MAX_CSA_ITEMS, csa_dict['n_tags'])) + '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') diff --git a/nibabel/nicom/dicomwrappers.py b/nibabel/nicom/dicomwrappers.py index 6263c8a6f1..f37d0323a8 100755 --- a/nibabel/nicom/dicomwrappers.py +++ b/nibabel/nicom/dicomwrappers.py @@ -84,7 +84,7 @@ def wrapper_from_data(dcm_data): csa = csar.get_csa_header(dcm_data) except csar.CSAReadError as e: warnings.warn('Error while attempting to read CSA header: ' + - str(e.args) + + str(e.args) + '\n Ignoring Siemens private (CSA) header info.') csa = None if csa is None: From 3efe193a29709444184c265b1575f4216e5cb1a0 Mon Sep 17 00:00:00 2001 From: Henry Braun Date: Tue, 24 Sep 2019 17:14:08 -0500 Subject: [PATCH 5/7] fix pep8 problems --- nibabel/nicom/csareader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nibabel/nicom/csareader.py b/nibabel/nicom/csareader.py index 86c51302e3..1764e2878c 100644 --- a/nibabel/nicom/csareader.py +++ b/nibabel/nicom/csareader.py @@ -100,7 +100,7 @@ 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. Instead found %d tags.' + '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 = \ From 5b008b609bc18aeeb614d9158504e46539c87d07 Mon Sep 17 00:00:00 2001 From: "Christopher J. Markiewicz" Date: Sun, 10 Nov 2019 17:21:32 -0500 Subject: [PATCH 6/7] MNT: Update nitest-dicom pin --- nibabel-data/nitest-dicom | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nibabel-data/nitest-dicom b/nibabel-data/nitest-dicom index ff6844f3a5..2246c92726 160000 --- a/nibabel-data/nitest-dicom +++ b/nibabel-data/nitest-dicom @@ -1 +1 @@ -Subproject commit ff6844f3a5ef79974c5809a79314c98fd81693cf +Subproject commit 2246c9272658693c02810836bdf820c1c6607624 From bebaf9c13edec33a7784372d1e0ccef40f8549a3 Mon Sep 17 00:00:00 2001 From: "Christopher J. Markiewicz" Date: Sun, 10 Nov 2019 17:34:22 -0500 Subject: [PATCH 7/7] TEST: Basic tests for CT DICOM image --- nibabel/nicom/tests/test_dicomwrappers.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/nibabel/nicom/tests/test_dicomwrappers.py b/nibabel/nicom/tests/test_dicomwrappers.py index 1ebf464d0e..c78249c381 100755 --- a/nibabel/nicom/tests/test_dicomwrappers.py +++ b/nibabel/nicom/tests/test_dicomwrappers.py @@ -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') @@ -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 @@ -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