Calculate MTR divide by zero error


#1

Hi Julien,

I ran into the following problem while trying to calculate MTR. The MT-on and and MT-off_reg file look great - and overlay perfectly. See error below - any advice?

thanks-


Spinal Cord Toolbox (dev)

Compute MTR…
/mnt/workspace/sct_dev/scripts/sct_compute_mtr.py:63: RuntimeWarning: divide by zero encountered in true_divide
data_mtr = 100 * (data_mt0 - data_mt1) / data_mt0
/mnt/workspace/sct_dev/scripts/sct_compute_mtr.py:63: RuntimeWarning: invalid value encountered in true_divide
data_mtr = 100 * (data_mt0 - data_mt1) / data_mt0


#2

Hi David,

The MT0 likely has a “nan” value. However it’s only a warning (not an error), so you should get an output mtr file. Do you get one?


#3

Thanks Julien -
Yes - I do get an output mtr file - but when I try to view it - it looks as if there is no data there.

so… I tried to extract the metrics using the following command - and got the error listed below:

sct_extract_metric -i mtr.nii.gz -l 50 -vert 3:4

which gives the following error:

Spinal Cord Toolbox (dev)

Traceback (most recent call last):

File "/mnt/workspace/sct_dev/scripts/sct_extract_metric.py", line 425, in <module>

perlevel=perlevel, verbose=verbose, combine_labels=combine_labels)

File "/mnt/workspace/sct_dev/scripts/sct_extract_metric.py", line 299, in main

raise RuntimeError(path_label + ’ does not exist’)

RuntimeError: label/atlas does not exist


#4

Hi David,

so, the fact that the output mtr file is empty (you meant: only zeros, right?) is indeed worrisome. Would you be able to send me the mt1 & mt0 so I can try to investigate.

As for the error with sct_extract_metric, this is due to the fact that by default, the flag -f is set to ./label/atlas, which is created by the function sct_warp_template. It seems like you did not run this function, hence the error. In order to specify your own mask to use with sct_extract_metric, you will need to use the flag -f. Example:

sct_extract_metric -i mtr.nii.gz -f my_mask.nii.gz

Hope that clarifies things :slight_smile:
Julien


#5

Thanks -

correct - I did not run sct_warp_template. I’m having a bit of trouble here too -

where does the input file warp_template2mt.nii.gz come from? does this come from the sct_register_multimodal script? or do I have to run sct_register_to_template on the mt files?


#6

There need to be at least one instance of sct_register_to_template in order to get a warping field that brings a subject to/from the PAM50 template.

The most popular scenario, also exemplified in the batch_processing.sh script, is that sct_register_to_template is run on the anatomical image (e.g. T2w), and then sct_register_multimodal is run with -initwarp flag, between the template (in the anat space) and the MT image.

The second scenario, exemplified in p74 of the Beijing’19 SCT course bypasses the registration to an anatomical image. In that case, sct_register_to_template is applied directly to the metric (e.g., mt1.nii.gz).


#7

Regarding the other issue (wrong MTR calculation), the mtr output is not empty, however some values are wrongly calculated. This seems related to a bug in the division of integer. An issue has been opened here and will be addressed with top priority.

Thank you very much for reporting this issue.


#8

Thanks again Julien -
indeed - I ran sct_register_multimodal with -initwarp flag

is it correct to then run as follows:
sct_warp_template -d mt1.nii.gz -w warp_template2anat.nii.gz

?


#9

no it is not correct, because warp_template2anat.nii.gz represents the warping field template–>anat. You want to use the template–>mt warping field which is generated by sct_register_multimodal. It should have a name like warp_PAM50_t22mt1.nii.gz (or something like that, depending on your input file names).

This is illustrated here in the example batch_processing.sh file. Note the previous lines, where the warping field is renamed (for clarity).