imr-framework / pypulseq

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

Reworked piecewise polynomial implementation in Sequence to use scipy's PPoly #140

Closed FrankZijlstra closed 8 months ago

FrankZijlstra commented 8 months ago

This implements calculate_kspacePP using scipy's PPoly object, which behaves very similar to the Matlab implementation. This is obviously much cleaner, and also much faster. A helper function get_gradients is also available to immediately get access to the waveforms in PPoly format. I renamed the function to calculate_kspace, because this function was no longer functional, and not intended to be used anymore anyway. I added a deprecation warning for calculate_kspacePP, but this function could also just be removed altogether. This also resolves #107.

Furthermore, I split waveforms_and_times into three functions: waveforms, adc_times, and rf_times. This allows efficient access to for example only the excitation times (e.g. when only calculating TE/TR). waveforms_and_times remains compatible with the previous implementation, but rf_times returns excitation/refocusing times and frequency/phase in separate arrays (instead of the non-intuitive tfp_ variables).

Further small changes:

sravan953 commented 8 months ago

Thanks for this! I spent a little time on the calculate k-space function but could not get the Scipy version to behave as expected. I ended up translating the MATLAB function to make it work, but that ended up being slow. Glad you got this to work!