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 10, 2023
1 parent 4cd3ec5 commit 9400963
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
This document contains the Spec2nii release history in reverse chronological order.

0.7.1 (WIP)
---------------------------------
- Fixed issue with RDA files having latin1 encoding. Thanks to gaunab on github. Fixes Issue #96.

0.7.0 (Saturday 5th August 2023)
--------------------------------
- Fixed a bug in Philips Classic DICOM orientations (supplementing the fixes to Enhanced DICOM in `0.6.11`)
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 9400963

Please sign in to comment.