Population_template error: population_template", line 442 TypeError: decode() takes no keyword arguments

Hi All,

I have created a fod_input and mask_input directory as recommended in the tutorial to then run population_template.

I get the following error;

File “/midas-data/software/mrtrix3_12.6.18/mrtrix3/bin/population_template”, line 442, in
run.command(‘mraverageheader -fill ’ + ’ ‘.join(input_filenames) + ’ - | mrresize - -voxel ‘+’,’.join(voxel_size)+’ average_header.mif’)
File “/midas-data/software/mrtrix3_12.6.18/mrtrix3/lib/mrtrix3/run.py”, line 197, in command
stderr_text = tempfiles[index][1].read().decode(‘utf-8’, errors=‘replace’)
TypeError: decode() takes no keyword arguments

I can’t figure out what this means or how to solve it. Any advice? (full text bellow) - Many thanks! Paul

population_template …/template/fod_input -mask_dir …/template/mask_input …/template/wmfod_template.mif -voxel_size 1.3
population_template: Generating a population-average template from 40 input images
population_template: SH series detected, performing FOD registration
population_template: initial alignment of images: mass
population_template: linear registration stages:
population_template: (00) rigid scale: 0.3000, niter: 100, lmax: 2
population_template: (01) rigid scale: 0.4000, niter: 100, lmax: 2
population_template: (02) rigid scale: 0.6000, niter: 100, lmax: 2
population_template: (03) rigid scale: 0.8000, niter: 100, lmax: 4
population_template: (04) rigid scale: 1.0000, niter: 100, lmax: 4
population_template: (05) rigid scale: 1.0000, niter: 100, lmax: 4
population_template: (06) affine scale: 0.3000, niter: 500, lmax: 2
population_template: (07) affine scale: 0.4000, niter: 500, lmax: 2
population_template: (08) affine scale: 0.6000, niter: 500, lmax: 2
population_template: (09) affine scale: 0.8000, niter: 500, lmax: 4
population_template: (10) affine scale: 1.0000, niter: 500, lmax: 4
population_template: (11) affine scale: 1.0000, niter: 500, lmax: 4
population_template: nonlinear registration stages:
population_template: (00) nonlinear scale: 0.3000, niter: 5, lmax: 2
population_template: (01) nonlinear scale: 0.4000, niter: 5, lmax: 2
population_template: (02) nonlinear scale: 0.5000, niter: 5, lmax: 2
population_template: (03) nonlinear scale: 0.6000, niter: 5, lmax: 2
population_template: (04) nonlinear scale: 0.7000, niter: 5, lmax: 2
population_template: (05) nonlinear scale: 0.8000, niter: 5, lmax: 2
population_template: (06) nonlinear scale: 0.9000, niter: 5, lmax: 2
population_template: (07) nonlinear scale: 1.0000, niter: 5, lmax: 2
population_template: (08) nonlinear scale: 1.0000, niter: 5, lmax: 4
population_template: (09) nonlinear scale: 1.0000, niter: 5, lmax: 4
population_template: (10) nonlinear scale: 1.0000, niter: 5, lmax: 4
population_template: (11) nonlinear scale: 1.0000, niter: 5, lmax: 4
population_template: (12) nonlinear scale: 1.0000, niter: 5, lmax: 4
population_template: (13) nonlinear scale: 1.0000, niter: 5, lmax: 4
population_template: (14) nonlinear scale: 1.0000, niter: 5, lmax: 4
population_template: (15) nonlinear scale: 1.0000, niter: 5, lmax: 4
population_template: Generated temporary directory: /media/toshiba/complete/outputs/2012/population_template-tmp-HQSEII/
population_template: Changing to temporary directory (/media/toshiba/complete/outputs/2012/population_template-tmp-HQSEII/)
population_template: Generating initial template
Command: mraverageheader -fill XXX - | mrresize - -voxel 1.3,1.3,1.3 average_header.mif
Traceback (most recent call last):
File “/midas-data/software/mrtrix3_12.6.18/mrtrix3/bin/population_template”, line 442, in
run.command(‘mraverageheader -fill ’ + ’ ‘.join(input_filenames) + ’ - | mrresize - -voxel ‘+’,’.join(voxel_size)+’ average_header.mif’)
File “/midas-data/software/mrtrix3_12.6.18/mrtrix3/lib/mrtrix3/run.py”, line 197, in command
stderr_text = tempfiles[index][1].read().decode(‘utf-8’, errors=‘replace’)
TypeError: decode() takes no keyword arguments

Thanks for posting, Paul, that’s potentially really useful information. Just quickly checking, it seems to me that this is related to the changes made in this commit: https://github.com/MRtrix3/mrtrix3/commit/724e91b71b95d185d1e6113909d5a623250b5613#diff-15ea8e46c5e64749b52b4dff228aec59 by Rob. @rsmith, what do you reckon?

Thanks Thijs. It might be worth mentioning that I am running on python 2.6.6 which I know is not the 2.7+> that is recommended. If that has anything to do with it.

Aha, yes, that seems to be part of the cause indeed. The decode(‘utf-8’, errors=‘replace’) bit doesn’t work on python 2.6: Python 2.6: encode() takes no keyword arguments - Stack Overflow

Coincidentally, other discussions ongoing about this bit: UnicodeDecodeError on .mif headers · Issue #1423 · MRtrix3/mrtrix3 · GitHub

Yes, the .decode() call was one of the major factors that led to MRtrix3’s Python requirement being increased to >=2.7. Unfortunately it seems a lot of HPC sysadmins refuse to update beyond 2.6…

While conceivably we could get around this with some Python trickery, 2.6 is exceptionally old, and there’s already a decent amount of gymnastics required to support both Python 2 and 3 in all of our scripts. It would at least be worth checking if the target system has Python3 installed: even an outdated version of Python3 will have the correct syntax.

Thanks Rob and Thijs. I have updated my python to 2.7 now and as expected the error does not recur. Looking forward to seeing the template in all its glory!

Best

Paul