fsleyes power spectrum DC 'bug'
Reported by @wclarke
As promised here is a description about the power spectrum issue. After looking into it the issue arises from the de-meaning step applied when normalisation is active.
Using the attached data I generate the spectrum by running this in python:
import nibabel as nib
import numpy as np
import matplotlib.pyplot as plt
data_file = 'wref.nii'
img = nib.load(data_file)
FID = img.get_fdata(dtype=np.complex64)
spectrum = np.fft.fftshift(np.fft.fft(FID[0,0,0,:]))
plt.figure(figsize=(15,8))
plt.plot(np.abs(spectrum),label='Magnitude')
plt.plot(np.real(spectrum),label='Real')
plt.plot(np.imag(spectrum),label='Imaginary')
plt.xlim([-200+2048,200+2048])
plt.legend()
plt.show()
But in Fsleyes it appears like this if normalise to unit variance is checked
If it isn’t checked then we get the right thing (from the MRS point of view):
This arises from the demeaning step on this line https://git.fmrib.ox.ac.uk/fsl/fsleyes/fsleyes/-/blob/master/fsleyes/plotting/powerspectrumseries.py#L62
I imagine that this normalisation is applied for a good reason for non-MRS data, and this is desired behaviour. If that’s the case then it can wait for me to get around to creating an MRS plugin which will set all these options appropriately. We now have an MRS data format with all the required meta-data stored in a NIFTI header extension, so setting all the options programmatically is now actually achievable.