wtclarke / fsl_mrs

Mirror of the FSL-MRS gitlab repository
https://git.fmrib.ox.ac.uk/fsl/fsl_mrs
Other
14 stars 8 forks source link

nifti_mrs_proc slow ? #10

Closed tngrssl closed 2 years ago

tngrssl commented 2 years ago

Hi William, FSL-MRS developers,

I started playing with FSL-MRS and I would first like to thank you for this wonderful tool! :clap:

I am processing my MRSI data using the python package but I find it quite slow. Here is a code example with the example data:

import fsl_mrs.utils.mrs_io as mrs_io
from fsl_mrs.utils.preproc import nifti_mrs_proc

mrsi_data = mrs_io.read_FID("/path/to/fsl_mrs/example_usage/example_data/example_mrsi/mrsi.nii.gz")
mrsi_data = nifti_mrs_proc.apodize(mrsi_data, [60.0], figure=True)

After a few seconds, the figure is plotted and then it takes a bit more than 3 minutes to finish. This example is for an apodization but I have this issue with all other processing operations (truncate, fshift, etc.). See below the Spyder profiler results: image

It seems the method __expandCoverage of the fsl ImageWrapper class is responsible for this. I installed fsl_mrs in conda with python 3.9, Ubuntu 16.04, 8 x 1.9Ghz processor, 16GB memory. My questions: do you have the same execution times on your side? Is this normal? Or maybe it comes from my setup?

I can do more tests if needed.

Thanks! Tangi

wtclarke commented 2 years ago

Hi @tngrssl , thanks for the very detailed report. I had also noticed that preprocessing functions are incredibly slow when operating on MRSI data. Clearly the approach I've taken to iterate over voxels is a bad one from a speed point of view / I've misunderstood how the fslpy image class works. I'll add this to the list of things to sort in the next version.

wtclarke commented 2 years ago

Hi @tngrssl ,

Paul McCarthy has just published a new version of fslpy (3.9.0) that fixes this issue. Please run conda update -c conda-forge fslpy to get it.

For me this produces a ~100 times speed increase for some functions. I'll ensure that in the next version of fsl-mrs that this is the requested version in conda. Could you let me know if it works for you?

tngrssl commented 2 years ago

Hi @wtclarke ,

Thanks for the update. I just tried on a bunch of datasets and it is now super fast! :)

wtclarke commented 2 years ago

Great! I can't believe I dealt with this for so long. Real thanks go to @pauldmccarthy .