dwifslpreproc Unhandled Python exception error


I’m extremely new to MRtrix and I’m trying to work my way through some basic tractography preprocessing steps. However, I ran into some unhandled python exceptions when trying to use dwifslpreproc that I couldn’t solve myself. Do anyone now why these occured (and how they can be resolved)?
OS: Ubuntu 18


karin@bionic-schnauzer:~/mri_testData/DICOM$ dwifslpreproc test_dwi.mif DWI_out.mif -rpe_none -pe_dir ap -readout_time 0.55
dwifslpreproc: Note that this script makes use of commands / algorithms that have relevant articles for citation; INCLUDING FROM EXTERNAL SOFTWARE PACKAGES. Please consult the help page (-help option) for more information.

dwifslpreproc: [ERROR] Unhandled Python exception:
dwifslpreproc: [ERROR] UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xe4 in position 630: invalid continuation byte
dwifslpreproc: [ERROR] Traceback:
dwifslpreproc: [ERROR] /home/karin/anaconda3/envs/old_mne/bin/dwifslpreproc:92 (in execute())
dwifslpreproc: [ERROR] image.check_3d_nonunity(path.from_user(app.ARGS.input, False))
dwifslpreproc: [ERROR] /home/karin/anaconda3/envs/old_mne/lib/mrtrix3/image.py:134 (in check_3d_nonunity())
dwifslpreproc: [ERROR] image_in = Header(image_in)
dwifslpreproc: [ERROR] /home/karin/anaconda3/envs/old_mne/lib/mrtrix3/image.py:46 (in init())
dwifslpreproc: [ERROR] data = json.loads(json_file.read().decode(‘utf-8’, errors=‘replace’))
dwifslpreproc: [ERROR] /home/karin/anaconda3/envs/old_mne/lib/python3.6/codecs.py:321 (in decode())
dwifslpreproc: [ERROR] (result, consumed) = self._buffer_decode(data, self.errors, final)

Thank you!

Welcome Karin!

It’s a fairly obtuse error, so definitely not easy to interpret if you’re not accustomed to such things.

What seems to be the problem is that within the header contents of file test_dwi.mif exists some non-text content that Python refuses to convert to text. It’s probably come from a DICOM header where e.g. a subject name has an accented character or something like that; we’ve made a number of modifications to try to make the software robust to such, but it seems you’ve come across a case we’ve not yet encountered.

What would help is if you could run:
mrinfo test_dwi.mif -json_all test_dwi.json
, and then upload file “test_dwi.json”. Don’t copy and paste the contents of the text file here, as that may obscure the origin of the fault; I think it should be possible to do a direct upload here just by dragging & dropping the file into the text box while writing a reply.


Ouch. My guess is the text fields in the DICOM were written in some European encoding (most likely
ISO-8859-1), where the additional non-ASCII characters are not compatible with UTF-8. We don’t perform conversions to UTF-8 within our DICOM import unfortunately – I’m not even sure how to determine the text encoding used within the DICOM headers, we’d have to research this to figure it out.

One option might be to modify our handling in the python scripts to also try reading with ISO-8859-1 encoding in case of failure with UTF-8…?

@karin_westin, maybe you could try modifying the problematic line in dwifslpreproc (line 92) to replace the 'utf-8' with 'iso-8859-1'…? It’s a long shot, but it might allow you to at least run the command for this one dataset…