Skip to content

Commit

Permalink
Update get_csa_header to return none on CSAReadError
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
parneshraniga authored Jan 3, 2017
1 parent 0f3048c commit f83ed47
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions nibabel/nicom/csareader.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ def get_csa_header(dcm_data, csa_type='image'):
element_no = section_start + element_offset
try:
tag = dcm_data[(0x29, element_no)]
except KeyError:
return read(tag.value)
except (KeyError,CSAReadError):
# The element could be missing due to anonymization
return None
return read(tag.value)



def read(csa_str):
Expand Down

0 comments on commit f83ed47

Please sign in to comment.