wtclarke / fsl_mrs

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

When DIM_COIL is equal to 1, `mrs_tools vis` throws an error #27

Closed Microdeep-ZL closed 1 week ago

Microdeep-ZL commented 1 week ago

Hi,

NIfTI-MRS standard allows DIM_COIL to be 1, but mrs_tools vis will throw an error because coil_cov is a scalar rather than a matrix, which makes the code block below fail:

combinedc_obj[idx] = preproc.combine_FIDs(
    list(main.T),
    'svd',
    do_prewhiten=not no_prewhiten,
    cov=coil_cov) # coil_cov is a scalar
(fslmrs) nmr@IMC-SPD-2203281:~/Projects/NIfTI_MRS_converter$ mrs_tools info output/NSPECT.nii.gz 
File NSPECT.nii.gz (/home/nmr/Projects/NIfTI_MRS_converter/output)
NIfTI-MRS version 0.9
Data shape (1, 1, 1, 2048, 1, 10)
Dimension tags: ['DIM_COIL', 'DIM_DYN', None]
Spectrometer Frequency: 100.679124582065 MHz
Dwelltime (Spectral bandwidth): 1.250E-04 s (8000 Hz)
Nucleus: 13C
Field Strength: 9.40 T

(fslmrs) nmr@IMC-SPD-2203281:~/Projects/NIfTI_MRS_converter$ mrs_tools vis output/NSPECT.nii.gz 
Performing coil combination
/home/nmr/.conda/envs/fslmrs/lib/python3.12/site-packages/fsl_mrs/utils/preproc/combine.py:48: UserWarning:

You may not have enough samples to accurately estimate the noise covariance, 10^5 samples recommended.

Traceback (most recent call last):
  File "/home/nmr/.conda/envs/fslmrs/bin/mrs_tools", line 10, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/nmr/.conda/envs/fslmrs/lib/python3.12/site-packages/mrs_tools/__init__.py", line 159, in main
    args.func(args)
  File "/home/nmr/.conda/envs/fslmrs/lib/python3.12/site-packages/mrs_tools/__init__.py", line 236, in vis
    fig = data.plot(
          ^^^^^^^^^^
  File "/home/nmr/.conda/envs/fslmrs/lib/python3.12/site-packages/nifti_mrs/nifti_mrs.py", line 671, in plot
    return vis_nifti_mrs(
           ^^^^^^^^^^^^^^
  File "/home/nmr/.conda/envs/fslmrs/lib/python3.12/site-packages/nifti_mrs/vis.py", line 29, in vis_nifti_mrs
    data = nifti_mrs_proc.coilcombine(data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nmr/.conda/envs/fslmrs/lib/python3.12/site-packages/fsl_mrs/utils/preproc/nifti_mrs_proc.py", line 181, in coilcombine
    combinedc_obj[idx] = preproc.combine_FIDs(
                         ^^^^^^^^^^^^^^^^^^^^^
  File "/home/nmr/.conda/envs/fslmrs/lib/python3.12/site-packages/fsl_mrs/utils/preproc/combine.py", line 186, in combine_FIDs
    FIDlist, pre_w_mat, cov = prewhiten(FIDlist, C=cov)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nmr/.conda/envs/fslmrs/lib/python3.12/site-packages/fsl_mrs/utils/preproc/combine.py", line 77, in prewhiten
    D, V = np.linalg.eigh(C, UPLO='U')  # UPLO = 'U' to match matlab implementation
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/nmr/.conda/envs/fslmrs/lib/python3.12/site-packages/numpy/linalg/_linalg.py", line 1634, in eigh
    _assert_stacked_2d(a)
  File "/home/nmr/.conda/envs/fslmrs/lib/python3.12/site-packages/numpy/linalg/_linalg.py", line 195, in _assert_stacked_2d
    raise LinAlgError('%d-dimensional array given. Array must be '
numpy.linalg.LinAlgError: 0-dimensional array given. Array must be at least two-dimensional
Microdeep-ZL commented 1 week ago

Hi,

Sorry to open an issue too early. I've found the way to correct it. And it's not in this repository, but in nifti_mrs_tools I'll submit a pull request there