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

Using LCModel Basis Set: ValueError: could not convert string to float: 'badelt=-3.99999990e-04' #11

Closed weberam2 closed 2 years ago

weberam2 commented 2 years ago

Hello

I am trying to run

fsl_mrs --data processed/metab.nii.gz --basis ~/.lcmodel/basis-sets/3t/all/press_te35_3t_all_v3.basis --output svs --h2o processed/wref.nii.gz --tissue_frac segmentation.json --report

but am getting the following error

Traceback (most recent call last): File "/usr/local/fsl/fslpython/envs/fslpython/bin/fsl_mrs", line 420, in main() File "/usr/local/fsl/fslpython/envs/fslpython/bin/fsl_mrs", line 197, in main basis, names, basisheader = mrs_io.read_basis(args.basis) File "/usr/local/fsl/fslpython/envs/fslpython/lib/python3.8/site-packages/fsl_mrs/utils/mrs_io/main.py", line 98, in read_basis basis, names, header = lcm.readLCModelBasis(filename) File "/usr/local/fsl/fslpython/envs/fslpython/lib/python3.8/site-packages/fsl_mrs/utils/mrs_io/lcm_io.py", line 144, in readLCModelBasis header = unpackHeader(header) File "/usr/local/fsl/fslpython/envs/fslpython/lib/python3.8/site-packages/fsl_mrs/utils/mrs_io/lcm_io.py", line 180, in unpackHeader tidy_header['dwelltime'] = float(tidy(line).split()[-1]) ValueError: could not convert string to float: 'badelt=-3.99999990e-04'

I would simulate my own, but I really don't know how to write the .json for a 3T GE Discovery PRESS...

Thanks for any help or insight into what I am doing wrong :)

wtclarke commented 2 years ago

HI @weberam2

Could I just double check what version of fsl-mrs you are running? This can be done with fsl_mrs --version.

I have a memory of fixing this at some point, but it's possible it was a related issue.

I think as a work around you could add a space between the equals sign and the -3.999.... TO do this simply opent he .basis file in a text editor.

BW

Will

changc3 commented 2 years ago

Hi @wtclarke,

I also met the same error when I used LCModel Basis Set. My fsl-mrs version is 1.1.13+0.g612d091.dirty. I also added the a space between the equals sign and the -3.999 but unfortunately it did not work. Could I ask if there is any solution or update about this issue? Thank you very much.

BW Chang

wtclarke commented 2 years ago

@changc3 If you try converting the basis set using basis_tools convert my_lcm_basis.basis does that work?

It sounds like I need to fix up the file reader properly. Is there any chance you could send me your basis file as an example of one that was failing, so Ic an test against it?

Will

changc3 commented 2 years ago

Hi @wtclarke ,

Thank you for your advice. I tried with the " basis_tools convert my_lcm_basis.basis" but it still did not work. I am now using the press_te25_3t_v3 file downloaded from LCM websites (http://s-provencher.com/pub/LCModel/3t.zip)). Basically, if you don't add space between the equals sign and the -3.999 , both basis_tools and fsl_mrs --data commands gave the same error that could not convert string to float: 'badelt=-3.99999990e-04'. If you add the space between, you could run the basis tool convert to .json but the program will still give you the error as shown below when you run the fsl_mrs --data metab.nii.gz --basis fslbasis --output test no matter whether you use converted basis or the basis downloaded from LCModel websites. Thank you very much and let me know if you need me to provide further info.

Best, Chang

(fsl_mrs) [user1@cluster1]$ basis_tools convert press.basis home/user1/fslbasis (fsl_mrs) [user1@cluster1]$ fsl_mrs --data metab.nii.gz --basis fslbasis --output test Traceback (most recent call last): File "/home/user1/.conda/envs/fsl_mrs/lib/python3.8/site-packages/fsl_mrs/core/basis.py", line 317, in _resampled_basis basis = misc.ts_to_ts_ft(self._raw_fids, File "/home/user1/.conda/envs/fsl_mrs/lib/python3.8/site-packages/fsl_mrs/utils/misc.py", line 247, in ts_to_ts_ft raise InsufficentTimeCoverageError('Input data covers less time than is requested by interpolation.' fsl_mrs.utils.misc.InsufficentTimeCoverageError: Input data covers less time than is requested by interpolation. Change interpolation points or dwell time.

wtclarke commented 2 years ago

Right, I'll get on this and try and fix this up properly. Thanks for pointing out it doesn't work with the official test basis. That makes it very easy to test against.

wtclarke commented 2 years ago

Hi @changc3, do you know whether the data in press_te25_3t_v3 is good? It looks like junk if you simply read the points out from the basis file. The dwelltime (badelt) being negative also seems odd. A negative dwell time has no good physical meaning. The conversion now works on all the other example basis sets in that folder (ie. all with _v1, but not the press with _v3)

wtclarke commented 2 years ago

Just to note I can't seem to get anything out of this data with Osprey tools either.

changc3 commented 2 years ago

Hi @wtclarke ,

Thank you very much for your suggestion and checking. I am not sure if press_te25_3t_v3 is good but previously I have tried to modify badelt to positive value but it still did not work. I just tried with others with _v1 but the other error messages poped out (below). Could I ask if you have some verified basis set or examplePress.json for press sequence or potentially semi laser sequence that we could adapt with different TE? I am thinking maybe it would be easier for us to make sure it's not the basis issue downloaded from the LCModel websites. Let me know if you have other suggestions for how to move on. Thank you.

BW Chang

(fsl_mrs) [user1@cluster]$ fsl_mrs --data metab.nii.gz --basis gamma_press_te20_3t_v1.basis --output test3 Traceback (most recent call last): File "/home/user1/.conda/envs/fsl_mrs/bin/fsl_mrs", line 8, in sys.exit(main()) File "/home/user1/.conda/envs/fsl_mrs/lib/python3.8/site-packages/fsl_mrs/scripts/fsl_mrs.py", line 203, in main basis = mrs_io.read_basis(args.basis) File "/home/user1/.conda/envs/fsl_mrs/lib/python3.8/site-packages/fsl_mrs/utils/mrs_io/main.py", line 112, in read_basis basis, names, header = lcm.readLCModelBasis(filename) File "/home/user1/.conda/envs/fsl_mrs/lib/python3.8/site-packages/fsl_mrs/utils/mrs_io/lcm_io.py", line 122, in readLCModelBasis data[:, idx] = np.roll(data[:, idx], -shifts[idx]) IndexError: list index out of range

(fsl_mrs) [user1@cluster]$ basis_tools convert gamma_press_te20_3t_v1.basis home/user/test/fslbasis Traceback (most recent call last): File "/home/user1/.conda/envs/fsl_mrs/bin/basis_tools", line 8, in sys.exit(main()) File "/home/user1/.conda/envs/fsl_mrs/lib/python3.8/site-packages/fsl_mrs/scripts/basis_tools.py", line 166, in main args.func(args) File "/home/user1/.conda/envs/fsl_mrs/lib/python3.8/site-packages/fsl_mrs/scripts/basis_tools.py", line 204, in convert basis_tools.convert_lcm_basis(args.input, args.output) File "/home/user1/.conda/envs/fsl_mrs/lib/python3.8/site-packages/fsl_mrs/utils/basis_tools.py", line 39, in convert_lcm_basis basis = mrs_io.read_basis(path_to_basis) File "/home/user1/.conda/envs/fsl_mrs/lib/python3.8/site-packages/fsl_mrs/utils/mrs_io/main.py", line 112, in read_basis basis, names, header = lcm.readLCModelBasis(filename) File "/home/user1/.conda/envs/fsl_mrs/lib/python3.8/site-packages/fsl_mrs/utils/mrs_io/lcm_io.py", line 122, in readLCModelBasis data[:, idx] = np.roll(data[:, idx], -shifts[idx]) IndexError: list index out of range

wtclarke commented 2 years ago

With thanks to @schorschinho, I've now discovered that the negative dwell time indicates an encrypted basis set. I've made the decision to not handle these packaged basis sets as they are likely to be inappropriate for analysis of modern data (acquired with different sequences to that which these basis sets were designed for). The next version will throw a more helpful error. The IndexError: list index out of range error will be fixed though.

wtclarke commented 2 years ago

As per my comment above this should now be fixed in v1.1.14

changc3 commented 2 years ago

Thank you very much.