Mrcalc: [ERROR] error converting string "-"

i was trying to perform the 5ttgen on T1w_acpc_dc_restore_brain.nii.gz and got the below error.

 Command: mrmath mesh2pve_L_Accu.mif mesh2pve_R_Accu.mif mesh2pve_L_Caud.mif mesh2pve_R_Caud.mif mesh2pve_L_Pall.mif mesh2pve_R_Pall.mif mesh2pve_L_Puta.mif mesh2pve_R_Puta.mif mesh2pve_L_Thal.mif mesh2pve_R_Thal.mif sum - | mrcalc - 1.0 -min all_sgms.mif
5ttgen: 
5ttgen: [ERROR] Command failed: mrmath mesh2pve_L_Accu.mif mesh2pve_R_Accu.mif mesh2pve_L_Caud.mif mesh2pve_R_Caud.mif mesh2pve_L_Pall.mif mesh2pve_R_Pall.mif mesh2pve_L_Puta.mif mesh2pve_R_Puta.mif mesh2pve_L_Thal.mif mesh2pve_R_Thal.mif sum - | mrcalc - 1.0 -min all_sgms.mif
5ttgen: Output of failed command:
mrcalc: [ERROR] error converting string "-"

thanks

Hi @Sarbani,

Itā€™s a little cryptic, but I think whatā€™s happened is that mrmath has crashed silently, and so the subsequent mrcalc call is unable to read the piped image file that itā€™s expecting from a preceding command.

Generally when these scripts stumble for whatever reason, itā€™s a good idea to go into the temporary directory where the script has been generating its files, and try running the failed command manually. That may give some clue; for instance some error messages may not be passed correctly from the command back to the script and so cannot be displayed, but will appear when you run the command manually.

You can also try checking your disk usage, in case you happened to run out of storage space at this point in the script (in a coming update there should be more useful error messages when such things occur).

Cheers
Rob

Hi @rsmith

I have tried the below things but still I am receiving the error :frowning:

koushik@koushik-DQ67SW:/tmp/5ttgen-tmp-CTJYI1$ mrmath mesh2pve_L_Accu.mif mesh2pve_R_Accu.mif mesh2pve_L_Caud.mif mesh2pve_R_Caud.mif mesh2pve_L_Pall.mif mesh2pve_R_Pall.mif mesh2pve_L_Puta.mif mesh2pve_R_Puta.mif mesh2pve_L_Thal.mif mesh2pve_R_Thal.mif sum - | mrcalc - 1.0 -min all_sgms.mif
mrmath: [100%] computing sum across 10 images
mrcalc: [ERROR] error converting string "-"
koushik@koushik-DQ67SW:/tmp/5ttgen-tmp-CTJYI1$ mrmath mesh2pve_L_Accu.mif mesh2pve_R_Accu.mif mesh2pve_L_Caud.mif mesh2pve_R_Caud.mif mesh2pve_L_Pall.mif mesh2pve_R_Pall.mif mesh2pve_L_Puta.mif mesh2pve_R_Puta.mif mesh2pve_L_Thal.mif mesh2pve_R_Thal.mif sum - | mrcalc - 1 -min all_sgms.mif
mrmath: [100%] computing sum across 10 images
mrcalc: [ERROR] error converting string "-"
koushik@koushik-DQ67SW:/tmp/5ttgen-tmp-CTJYI1$ mrmath mesh2pve_L_Accu.mif mesh2pve_R_Accu.mif mesh2pve_L_Caud.mif mesh2pve_R_Caud.mif mesh2pve_L_Pall.mif mesh2pve_R_Pall.mif mesh2pve_L_Puta.mif mesh2pve_R_Puta.mif mesh2pve_L_Thal.mif mesh2pve_R_Thal.mif sum a | mrcalc a 1.0 -min all_sgms.mif
mrcalc: [ERROR] error converting string "a"
mrmath: [100%] computing sum across 10 images
mrmath: [ERROR] unknown format for image "a" (no file extension specified)
mrmath: [ERROR] error creating image "a"
koushik@koushik-DQ67SW:/tmp/5ttgen-tmp-CTJYI1$ mrmath mesh2pve_L_Accu.mif mesh2pve_R_Accu.mif mesh2pve_L_Caud.mif mesh2pve_R_Caud.mif mesh2pve_L_Pall.mif mesh2pve_R_Pall.mif mesh2pve_L_Puta.mif mesh2pve_R_Puta.mif mesh2pve_L_Thal.mif mesh2pve_R_Thal.mif sum a.mif
mrmath: [100%] computing sum across 10 images
SRDB: fsbuf.f_type = ef53
DBSR: delayed_writeback = 0
koushik@koushik-DQ67SW:/tmp/5ttgen-tmp-CTJYI1$ mrcalc a.mif 1.0 -min all_sgms.mif
SRDB: fsbuf.f_type = ef53
DBSR: delayed_writeback = 0
mrcalc: [100%] computing: min (a.mif, 1)
koushik@koushik-DQ67SW:/tmp/5ttgen-tmp-CTJYI1$ mrmath mesh2pve_L_Accu.mif mesh2pve_R_Accu.mif mesh2pve_L_Caud.mif mesh2pve_R_Caud.mif mesh2pve_L_Pall.mif mesh2pve_R_Pall.mif mesh2pve_L_Puta.mif mesh2pve_R_Puta.mif mesh2pve_L_Thal.mif mesh2pve_R_Thal.mif sum b.mif | mrcalc b.mif 1.0 -min all_sgms.mif
mrcalc: [ERROR] error converting string "b.mif"
mrmath: [100%] computing sum across 10 images
koushik@koushik-DQ67SW:/tmp/5ttgen-tmp-CTJYI1$ mrmath mesh2pve_L_Accu.mif mesh2pve_R_Accu.mif mesh2pve_L_Caud.mif mesh2pve_R_Caud.mif mesh2pve_L_Pall.mif mesh2pve_R_Pall.mif mesh2pve_L_Puta.mif mesh2pve_R_Puta.mif mesh2pve_L_Thal.mif mesh2pve_R_Thal.mif sum b.mif | mrcalc b.mif '1.0' -min all_sgms.mif
mrcalc: [ERROR] output file "all_sgms.mif" already exists (use -force option to force overwrite)
mrcalc: [ERROR] error creating image "all_sgms.mif"
mrmath: [100%] computing sum across 10 images
mrmath: [ERROR] output file "b.mif" already exists (use -force option to force overwrite)
mrmath: [ERROR] error creating image "b.mif"
koushik@koushik-DQ67SW:/tmp/5ttgen-tmp-CTJYI1$ mrmath mesh2pve_L_Accu.mif mesh2pve_R_Accu.mif mesh2pve_L_Caud.mif mesh2pve_R_Caud.mif mesh2pve_L_Pall.mif mesh2pve_R_Pall.mif mesh2pve_L_Puta.mif mesh2pve_R_Puta.mif mesh2pve_L_Thal.mif mesh2pve_R_Thal.mif sum c.mif | mrcalc c.mif '1.0' -min all_sgms1.mif
mrcalc: [ERROR] error converting string "c.mif"
mrmath: [100%] computing sum across 10 images
koushik@koushik-DQ67SW:/tmp/5ttgen-tmp-CTJYI1$ 

Regards
Sarbani

OK, so two separate points to make on this one.

Firstly, when the troublesome command is executed properly as two separate steps, they proceed without error:

koushik@koushik-DQ67SW:/tmp/5ttgen-tmp-CTJYI1$ mrmath mesh2pve_L_Accu.mif mesh2pve_R_Accu.mif mesh2pve_L_Caud.mif mesh2pve_R_Caud.mif mesh2pve_L_Pall.mif mesh2pve_R_Pall.mif mesh2pve_L_Puta.mif mesh2pve_R_Puta.mif mesh2pve_L_Thal.mif mesh2pve_R_Thal.mif sum a.mif
koushik@koushik-DQ67SW:/tmp/5ttgen-tmp-CTJYI1$ mrcalc a.mif 1.0 -min all_sgms.mif

This suggests that thereā€™s nothing fundamentally wrong with the commands or your system. The next test to perform after this would be to run the same command, but making use of piping as is done in the 5ttgen script:

koushik@koushik-DQ67SW:/tmp/5ttgen-tmp-CTJYI1$ mrmath mesh2pve_L_Accu.mif mesh2pve_R_Accu.mif mesh2pve_L_Caud.mif mesh2pve_R_Caud.mif mesh2pve_L_Pall.mif mesh2pve_R_Pall.mif mesh2pve_L_Puta.mif mesh2pve_R_Puta.mif mesh2pve_L_Thal.mif mesh2pve_R_Thal.mif sum - | mrcalc - 1.0 -min all_sgms.mif

If this fails, but the commands are successful when split across multiple lines, this would suggest that wherever your system is writing the temporary piped images to has run out of disk storage space.

Secondly, I would have another read of the Unix pipelines tutorial to fully come to grips with its usage in MRtrix3. Commands like this are doomed to fail:

koushik@koushik-DQ67SW:/tmp/5ttgen-tmp-CTJYI1$ mrmath mesh2pve_* sum b.mif | mrcalc b.mif 1.0 -min all_sgms.mif

In its typical usage (e.g. see second terminal example above), mrcalc waits for mrmath to complete, as it sees the ā€˜-ā€™ symbol where it expects to see an input image, and therefore waits until the path to this temporary image is received via its stdin before proceeding; mrmath completes its duties, generates its output in a temporary image, and writes the path to this temporary image to its stdout, where it is subsequently received by mrcalc. However in your example, both mrmath and mrcalc proceed instantly, and so mrcalc fails instantly because it expects to see an input image called ā€˜b.mifā€™ despite the fact that mrmath has not yet created it.

Edit: OK, looks like the command with the piping was the first thing you tested:

koushik@koushik-DQ67SW:/tmp/5ttgen-tmp-CTJYI1$ mrmath mesh2pve_L_Accu.mif mesh2pve_R_Accu.mif mesh2pve_L_Caud.mif mesh2pve_R_Caud.mif mesh2pve_L_Pall.mif mesh2pve_R_Pall.mif mesh2pve_L_Puta.mif mesh2pve_R_Puta.mif mesh2pve_L_Thal.mif mesh2pve_R_Thal.mif sum - | mrcalc - 1.0 -min all_sgms.mif
mrmath: [100%] computing sum across 10 images
mrcalc: [ERROR] error converting string "-"

Iā€™d have expected this to give more useful informationā€¦ Are you working over e.g. an ssh connection? Nevertheless, the fact that two separate commands works but piping does not indicates a problem with the location being used for temporary image piping. Iā€™d run the piped command with the -debug option (both for mrmath and mrcalc), that should tell you where the temporary piped image is (supposed to be) going. You can then check your disk space there.

Cheers
Rob

Dear MRtrix3 Experts,

I understand that this thread is old however my current query pertains to this issue.

When I ran the following command:

5ttgen fsl T1.coreg.nii 5tt_act.mif ā€“force

I received the following error:

5ttgen: [ERROR] Command failed: mrmath mesh2pve_L_Accu.mif mesh2pve_R_Accu.mif mesh2pve_L_Caud.mif mesh2pve_R_Caud.mif mesh2pve_L_Pall.mif mesh2pve_R_Pall.mif mesh2pve_L_Puta.mif mesh2pve_R_Puta.mif mesh2pve_L_Thal.mif mesh2pve_R_Thal.mif sum - | mrcalc - 1.0 -min all_sgms.mif (fsl.py:193)
5ttgen: Output of failed command:
mrmath: computing sum across 10 imagesā€¦ [==========]
mrmath: [ERROR] error creating temporary file in current working directory: Permission denied
mrmath: [ERROR] error creating image ā€œ-ā€
mrcalc: [ERROR] error converting string ā€œ-ā€

I read this thread to resolve the issue with our IT team. I can confirm that separate commands work and piping is the issue so we checked permissions and rebooted the server to bring it to a stable stage. Despite our efforts, I still receive the above error. This is the case for dwipreproc, dwi2response, etc. commands as well.

$ dwipreproc dwi_denoised_cropped.mif dwi_preprocessed.mif -pe_dir AP -rpe_pair -se_epi b0s.mif
dwipreproc:
dwipreproc: 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.
dwipreproc:
dwipreproc: Generated temporary directory: /ibscratch/users/uqisaham/CAI_imaging/files_relevant_to_analysis/mrtrix3_Preprocessed_Data/Troubleshooting/S06_KC-3T/HARDI/dwipreproc-tmp-TM5L2I/
Command: mrconvert /ibscratch/users/uqisaham/CAI_imaging/files_relevant_to_analysis/mrtrix3_Preprocessed_Data/Troubleshooting/S06_KC-3T/HARDI/dwi_denoised_cropped.mif /ibscratch/users/uqisaham/CAI_imaging/files_relevant_to_analysis/mrtrix3_Preprocessed_Data/Troubleshooting/S06_KC-3T/HARDI/dwipreproc-tmp-TM5L2I/dwi.mif
Command: mrconvert /ibscratch/users/uqisaham/CAI_imaging/files_relevant_to_analysis/mrtrix3_Preprocessed_Data/Troubleshooting/S06_KC-3T/HARDI/b0s.mif /ibscratch/users/uqisaham/CAI_imaging/files_relevant_to_analysis/mrtrix3_Preprocessed_Data/Troubleshooting/S06_KC-3T/HARDI/dwipreproc-tmp-TM5L2I/topup_in.mif
dwipreproc: Changing to temporary directory (/ibscratch/users/uqisaham/CAI_imaging/files_relevant_to_analysis/mrtrix3_Preprocessed_Data/Troubleshooting/S06_KC-3T/HARDI/dwipreproc-tmp-TM5L2I/)
Command: mrinfo dwi.mif -export_grad_mrtrix grad.b
Command: mrconvert topup_in.mif topup_in.nii -import_pe_table topup_manual_pe_scheme.txt -stride -1,+2,+3,+4 -export_pe_table topup_datain.txt
Command: topup --imain=topup_in.nii --datain=topup_datain.txt --out=field --fout=field_map.nii.gz --config=/clusterdata/apps/fsl/etc/flirtsch/b02b0.cnf
Command: mrinfo dwi.mif -export_pe_eddy applytopup_config.txt applytopup_indices.txt
Command: dwiextract dwi.mif -pe 0,-1,0,0.0464 dwi_pe_1.nii
Command: applytopup --imain=dwi_pe_1.nii --datain=applytopup_config.txt --inindex=1 --topup=field --out=dwi_post_topup.nii.gz --method=jac
Command: mrconvert dwi_post_topup.nii.gz -grad grad.b - | dwi2mask - - | maskfilter - dilate - | mrconvert - mask.nii -datatype float32 -stride -1,+2,+3
dwipreproc:
dwipreproc: [ERROR] Command failed: mrconvert dwi_post_topup.nii.gz -grad grad.b - | dwi2mask - - | maskfilter - dilate - | mrconvert - mask.nii -datatype float32 -stride -1,+2,+3 (dwipreproc:453)
dwipreproc: Output of failed command:
mrconvert: uncompressing image ā€œdwi_post_topup.nii.gzā€ā€¦ [=================================================]
mrconvert: [ERROR] error creating temporary file in current working directory: Permission denied
mrconvert: [ERROR] error creating image ā€œ-ā€
dwi2mask: [ERROR] no filename supplied to standard input (broken pipe?)
dwi2mask: [ERROR] error opening image ā€œ-ā€
maskfilter: [ERROR] no filename supplied to standard input (broken pipe?)
maskfilter: [ERROR] error opening image ā€œ-ā€
mrconvert: [ERROR] no filename supplied to standard input (broken pipe?)
mrconvert: [ERROR] error opening image ā€œ-ā€
dwipreproc: Changing back to original directory (/ibscratch/users/uqisaham/CAI_imaging/files_relevant_to_analysis/mrtrix3_Preprocessed_Data/Troubleshooting/S06_KC-3T/HARDI)
dwipreproc: Script failed while executing the command: mrconvert dwi_post_topup.nii.gz -grad grad.b - | dwi2mask - - | maskfilter - dilate - | mrconvert - mask.nii -datatype float32 -stride -1,+2,+3
dwipreproc: For debugging, inspect contents of temporary directory: /ibscratch/users/uqisaham/CAI_imaging/files_relevant_to_analysis/mrtrix3_Preprocessed_Data/Troubleshooting/S06_KC-3T/HARDI/dwipreproc-tmp-TM5L2I/

Our IT team have asked that I consult you because they canā€™t identify the issue from their end.

Your support in this matter is appreciated!
Ishani

Dear Ishani,
My issue was resolved when I freed up some disk space.
If you run the piped command with -debug option, that should tell you where the temporary image files are getting stored.
Check that disk space and if require free up the space, may be your issue will be resolved.
Regards
Sarbani

As @rsmith mentioned in a previous post, it would really be worth having a quick look through how MRtrix3 handles pipes. The main thing there is that it involves writing images to a temporary location, and passing the filename only to the next command. In your output, itā€™s clear that one of the commands is failing to write to that temporary storage location:

and also for your dwipreproc call:

And furthermore, it seems to be related to permissions in both cases (at least thatā€™s what the OS reports as the reason for the failure).

You should be able to drill down into the problem by looking at the temporary folder that dwipreproc created to stores its temporary outputs:

Maybe you can try creating a file in that folder, e.g.:

$ cd /ibscratch/users/uqisaham/CAI_imaging/files_relevant_to_analysis/mrtrix3_Preprocessed_Data/Troubleshooting/S06_KC-3T/HARDI/dwipreproc-tmp-TM5L2I/
$ touch some_file

See if that works? Also check whether there is enough free space at that location, as suggested by @Sarbani:

$ df -h  /ibscratch/users/uqisaham/CAI_imaging/files_relevant_to_analysis/mrtrix3_Preprocessed_Data/Troubleshooting/S06_KC-3T/HARDI/dwipreproc-tmp-TM5L2I/

Assuming you do genuinely have a permissions problem, check what permissions that temporary folder was created with:

ls -ld  /ibscratch/users/uqisaham/CAI_imaging/files_relevant_to_analysis/mrtrix3_Preprocessed_Data/Troubleshooting/S06_KC-3T/HARDI/dwipreproc-tmp-TM5L2I/

and check that you are the owner and have write and execute permissions (see here for details on permissions). If you donā€™t, it might be worth getting your sysadmins to check your umask settings (which determines the default permissions for new files).

Other than that, Iā€™m out of ideasā€¦

Thank you very much @jdtournier and @Sarbani!

Iā€™ve passed your solutions on to our IT team and will update this when I hear back from them.

Ishani

You should be able to drill down into the problem by looking at the temporary folder that dwipreproc created to stores its temporary outputs

Maybe you can try creating a file in that folder:

Important clarification here: The location of the temporary directory generated by a Python script, and the location used by MRtrix3 for storing piped images, are independent - even in the instance where piping is performed within a script.

By default, script temporary directories are generated in the current working directory, and can be manipulated via the -tempdir command-line option and the ScriptTmpDir configuration file entry. Piped images, on the other hand, go to /tmp/ by default, and can be manipulated using the TmpFileDir configuration file entry.

Only the latter of these two is causing an issue in your instance: you donā€™t have write access to /tmp/.

Yes, I was trying to take that into account. The error message is very specific though (emphasis mine):

error creating temporary file in current working directory: Permission denied

I would have hoped this was accurateā€¦?

error creating temporary file in current working directory: Permission denied

Thatā€™d be a red herring I reckon.

OK. Yep, youā€™re right. I guess weā€™d best fix that error message thenā€¦

Thank you @jdtournier and @rsmith!

To resolve the issue, I specified a ā€œTmpFileDir:ā€ directory in a separate user defined config file (.mrtrix.conf), to ensure that MRtrix3 applications would run.

Thanks very much for your time and assistance!
Ishani

1 Like