File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -63,8 +63,10 @@ def get_csa_header(dcm_data, csa_type='image'):
63
63
if section_start is None :
64
64
return None
65
65
element_no = section_start + element_offset
66
- # Assume tag exists
67
- tag = dcm_data [(0x29 , element_no )]
66
+ try :
67
+ tag = dcm_data [(0x29 , element_no )]
68
+ except KeyError :
69
+ return None
68
70
return read (tag .value )
69
71
70
72
Original file line number Diff line number Diff line change 1
1
""" Testing Siemens CSA header reader
2
2
"""
3
3
from os .path import join as pjoin
4
+ from copy import deepcopy
4
5
import gzip
5
6
6
7
import numpy as np
13
14
14
15
from .test_dicomwrappers import (have_dicom , dicom_test ,
15
16
IO_DATA_PATH , DATA , DATA_FILE )
17
+ if have_dicom :
18
+ from .test_dicomwrappers import pydicom
16
19
17
20
CSA2_B0 = open (pjoin (IO_DATA_PATH , 'csa2_b0.bin' ), 'rb' ).read ()
18
21
CSA2_B1000 = open (pjoin (IO_DATA_PATH , 'csa2_b1000.bin' ), 'rb' ).read ()
@@ -128,3 +131,15 @@ def test_ice_dims():
128
131
assert_equal (csa .get_ice_dims (csa_info ),
129
132
ex_dims )
130
133
assert_equal (csa .get_ice_dims ({}), None )
134
+
135
+
136
+ @dicom_test
137
+ def test_missing_csa_elem ():
138
+ # Test that we get None instead of raising an Exception when the file has
139
+ # the PrivateCreator element for the CSA dict but not the element with the
140
+ # actual CSA header (perhaps due to anonymization)
141
+ dcm = deepcopy (DATA )
142
+ csa_tag = pydicom .tag .Tag (0x29 , 0x1010 )
143
+ del dcm [csa_tag ]
144
+ hdr = csa .get_csa_header (dcm , 'image' )
145
+ assert_equal (hdr , None )
You can’t perform that action at this time.
0 commit comments