Skip to content

Commit

Permalink
Include potential fix for a decoding issuereported. Awaiting test data.
Browse files Browse the repository at this point in the history
  • Loading branch information
wtclarke committed Oct 12, 2023
1 parent ba20108 commit b955c62
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ This document contains the Spec2nii release history in reverse chronological ord
--------------------------------
- The --anon flag can be passed with any call to anonymise after writing files.
- The Siemens enhanced dicom filetype pathway now handles CSI data.
- Fixed issue with RDA files having latin1 encoding. Thanks to gaunab on github. Fixes Issue #96.

0.7.0 (Saturday 5th August 2023)
--------------------------------
Expand Down
37 changes: 26 additions & 11 deletions spec2nii/Siemens/rda.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,33 @@ def convert_rda(rda_path, fname_out, verbose):

with open(rda_path, 'rb') as fp:
for line in fp:
if hdr_st.search(line.decode()):
pass
# print('header found')
elif hdr_end.search(line.decode()):
# print('header end')
break
else:
match = hdr_val.search(line.decode())
if len(match.groups()) < 2:
hdr[match[1]] = None
try:
if hdr_st.search(line.decode()):
pass
# print('header found')
elif hdr_end.search(line.decode()):
# print('header end')
break
else:
match = hdr_val.search(line.decode())
if len(match.groups()) < 2:
hdr[match[1]] = None
else:
hdr[match[1]] = match[2]
except UnicodeDecodeError:
print('Trying latin-1 encoding.')
if hdr_st.search(line.decode('latin-1')):
pass
# print('header found')
elif hdr_end.search(line.decode('latin-1')):
# print('header end')
break
else:
hdr[match[1]] = match[2]
match = hdr_val.search(line.decode('latin-1'))
if len(match.groups()) < 2:
hdr[match[1]] = None
else:
hdr[match[1]] = match[2]
if verbose:
print(hdr)

Expand Down

0 comments on commit b955c62

Please sign in to comment.