diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e75b23..84797b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) -------------------------------- 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)