diff --git a/CHANGELOG.md b/CHANGELOG.md index d2e6ce3..b91124c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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`) diff --git a/spec2nii/Siemens/rda.py b/spec2nii/Siemens/rda.py index a3cc25e..294948f 100644 --- a/spec2nii/Siemens/rda.py +++ b/spec2nii/Siemens/rda.py @@ -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)