mfroeling / QMRITools

Processing and visualization tools for quantitative MRI data
https://QMRITools.com
BSD 3-Clause "New" or "Revised" License
61 stars 17 forks source link

Registration Failing due to StringForm #13

Closed emathew4 closed 2 years ago

emathew4 commented 2 years ago

Describe the bug

Very similar to Issue #10, but affects (at least) both macOS and Windows The Register* family of functions fails with an import error. The file result-3D.nii.gz is not created in the temporary directory due to an error with StringForm.

To Reproduce Steps to reproduce the behavior:

  1. Open the demo.nb file and initialize.
  2. Scroll to the Registration using Elastix section and import the data.
  3. Continue evaluating the code cells under Affine Transformation until you get to RegisterData which will fail with an error.

System Information :

dataR

There is an "out of range" error appearing regarding StringForm which did not appear in Issue #10. This seems to be the issue and would explain why the error occurs across multiple OS.

mfroeling commented 2 years ago

Hi, As i also said in Issue #10 i dont have acces to a mac system to test. This error is usually due to elastix did not run which can have 2 reasons. The elastix application was not found or elastix did not finisch.

Can you check if the elastix aplication for mac is present in your paclet folder.

SystemOpen[First[PacletFind["QMRITools"]]["Location"]]

If you run the code with the follwing addition you will get some information i can use to understand what goes wrong.

Unprotect[QMRITools`ElastixTools`$debugElastix]

QMRITools`ElastixTools`$debugElastix = True;

dataR = RegisterData[{dataS, mask, vox}, {dataT, vox}, DeleteTempDirectory -> False, Iterations -> 250, MethodReg -> "affine", NumberSamples -> 2000, Resolutions -> 1];

SystemOpen[FileNameJoin[{$TemporaryDirectory, "QMRIToolsReg"}]]

Setting the debugElastix parameter prints the commandline command excecuted by mathematica to run elastix.

for windows it looks something like this.

command

if it ran correctly the temp folder should contain the following files. The elastix.log will show what went wrong (if it even exists)

outfolder

emathew4 commented 2 years ago

You are correct, it seems there is a problem with finding elastix. I did confirm the elastix application is present in the paclet folder. Here is the output from a Windows system using the debugElastix parameter

elastixerror

I think the problem occurs when installing using PacletInstall instead of a manual installation. When checking where FindElastix searches for elastix, it looks within the Applications folder of $UserBaseDirectory and $BaseDirectory; if using PacletInstall, the paclet will be installed to $UserBasePacletsDirectory (which by default is in the Paclets subdirectory of $UserBaseDirectory, leaving the Applications folder empty).

Copying the QMRITools folder into the Applications folder seems to be a simple solution! Alternatively, modifying the FindElastix tool to check the Paclets subdirectory (or wherever elastix is located) also works.

Thank you for the help, and many thanks for the great package!

mfroeling commented 2 years ago

Great you got it figured out. I never use the paclets myself and indeed the function FindElastix does not work correctly in that case. Im currently refactoring the paclet such that it better works with Mathematica 13. One of the things is better defining the dependencies. I'll try to find some time to rewrite the FindElasix and related functions (FindTransformix and FindDcm2Nii) such the work as they should.

I will let you know when it is solved. Thanks for the feedback!

mfroeling commented 2 years ago

@emathew4 Hi, i have uploaded a new release 2.7.3. This should fix your issue. The applications are now defined in the PacletInfo.wl ->Extentions -> Asset.

Locations of the executables can now be obtained directly from the pacletObject or with the new function GetAssetLocation[] (e.g. GetAssetLocation["Elastix"]). Would you be able to verify if RegisterData works now if the paclet is installed via PacletInstall["QMRITools-2.7.3.paclet"]? I have tested this on Windows and there it seems to work.

In[4]:= GetAssetLocation["Elastix"]

Out[4]= "..\\Paclets\\Repository\\QMRITools-2.7.3\\Applications\\Windows-x86-64\\elastix.exe"

emathew4 commented 2 years ago

RegisterData does work correctly now! TransformData seems to have an issue however.

Screen Shot 2022-02-02 at 10 47 22 AM

This seems unrelated to the Elastix/RegisterData issue as the path to Transformix is correct and it seems that one of the other command line inputs is empty. I checked using the previous Paclet release (2.6.4) and this error occurs there as well (after adjusting the Elastix path for RegisterData), so it is not due to the most recent changes.

mfroeling commented 2 years ago

Hi great to hear the functions are working now. Thanks for the feedback.

The issue here is not a bug but me beeing lazy and nog doing proper error catching and reporting. Im almost sure it is because the directory specified in TransformData is no the same as used in RegisterData.

tempfolder

TransformData looks in the specified folder for the latest "TransformParameters.x.txt" file. So if it looks in the wrong directory or RegisterData is called without the optionDeleteTempDirectory->False it cannot find the -tp file.

options

Hope this solves your issue if not let me know and ill dive into it.

emathew4 commented 2 years ago

You're right, it was just due to a different directory being specified. It looks like everything is working now. Thank you again for all the help!

mfroeling commented 2 years ago

No problem, have fun with the toolbox and if you need any help regarding other toolbox-related things or features feel free to contact me.