imr-framework / pypulseq

Pulseq in Python
https://pypulseq.readthedocs.io
GNU Affero General Public License v3.0
111 stars 58 forks source link

Added gradient spectrum calculations #170

Closed FrankZijlstra closed 3 months ago

FrankZijlstra commented 4 months ago

This PR adds the gradient spectrum calculation as available in MATLAB Pulseq: https://github.com/pulseq/pulseq/blob/master/matlab/demoUnsorted/gradSpectrum.m

The implementation provides a fair number of parameters to control how the calculation is actually done (as we're not entirely sure what is the best way to go about this). The defaults should be sufficient to avoid peaks in the spectrum at the acoustic resonances of your scanner (and avoid damaging the gradient coils).

Basic usage (will plot the spectrums and also return them):

seq.calculate_gradient_spectrum()

Or including plotting the acoustic resonance ranges from a Siemens .asc file:

from pypulseq.utils.siemens.readasc import readasc
from pypulseq.utils.siemens.asc_to_hw import asc_to_acoustic_resonances

asc = readasc(asc_name)
seq.calculate_gradient_spectrum(acoustic_resonances=asc_to_acoustic_resonances(asc[0]))
FrankZijlstra commented 3 months ago

Python output for seq.calculate_gradient_spectrum(max_frequency=10000, combine_mode='rss') (parameters to be compatible with MATLAB defaults): image

MATLAB output: image

The different Y-scale is due to scipy's spectrogram function using different units than the computations in the MATLAB script. For now the Y-scale is arbitrary anyway, until we can figure out reasonable limits for acoustic resonances.