openmrslab / suspect

MRS processing tools
https://suspect.readthedocs.io/en/latest/
MIT License
31 stars 23 forks source link

frequency axis inverted #154

Open dj136 opened 3 years ago

dj136 commented 3 years ago

When applying "plt.plot(data.frequency_axis(), data.spectrum().real)" the frequency axis is inverted so that the fat peak is to the right of the center at 220Hz (at 1.5T) instead of -220 Hz. The spectrometer is set to water protons so the water peak is at the center frequency (0Hz) but the fat peak should resonate below the center frequency at -220 Hz.

data.frequency_axis_ppm() on the other hand assigns the center frequency correctly to 4,7ppm and the fat peak is also at the correct position (1,3ppm).

Should the function def frequency_axis(self) which gives an array of frequencies in Hertz ranging from -sw/2 to sw/2 ( return numpy.linspace(-self.sw / 2, self.sw / 2, self.np, endpoint=False)) changed to return numpy.linspace(self.sw / 2, -self.sw / 2, self.np, endpoint=False) in order for data.frequency_axis() to place the fat peak at the correct position at -220 Hz instead if 220Hz?

bennyrowland commented 3 years ago

Hi @dj136, thanks for pointing this out. I always use the ppm scale and hadn't particularly thought about the sign of the Hertz scale, but of course the fat peak should resonate at a lower frequency than water. I think that originally it was signed the way it is so that it would plot with the peaks in order without having to reverse the axis, but that is not a good reason. Would you like to create a pull request to make the change? I think your proposed edit in the core is correct, but it will also have consequences for calculating the ppm axis which is a derived quantity.