Skip to content

Commit f83ed47

Browse files
Update get_csa_header to return none on CSAReadError
Some non-MRI dicom datasets have just strings in CSA Header tags. This causes the read on line 68 to throw an error because the string is not a CSA header. Unfortunately this throws out other packages such as dcmstack which use nibabel. The proposed fix returns none if a read error is encountered when such strings are parsed. It is possible such strings may pass the initial check for 0 < n_tags <=128 which throws the CSAReadError but fail later in which case the except block can be be modified to handle those exceptions as well.
1 parent 0f3048c commit f83ed47

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

nibabel/nicom/csareader.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,11 @@ def get_csa_header(dcm_data, csa_type='image'):
6565
element_no = section_start + element_offset
6666
try:
6767
tag = dcm_data[(0x29, element_no)]
68-
except KeyError:
68+
return read(tag.value)
69+
except (KeyError,CSAReadError):
6970
# The element could be missing due to anonymization
7071
return None
71-
return read(tag.value)
72+
7273

7374

7475
def read(csa_str):

0 commit comments

Comments
 (0)