calc_rf_center.py 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. from types import SimpleNamespace
  2. from typing import Tuple
  3. import numpy as np
  4. def calc_rf_center(rf: SimpleNamespace) -> Tuple[float, float]:
  5. """
  6. Calculate the time point of the effective rotation calculated as the peak of the radio-frequency amplitude for the
  7. shaped pulses and the center of the pulse for the block pulses. Zero padding in the radio-frequency pulse is
  8. considered as a part of the shape. Delay field of the radio-frequency object is not taken into account.
  9. Parameters
  10. ----------
  11. rf : SimpleNamespace
  12. Radio-frequency pulse event.
  13. Returns
  14. -------
  15. time_center : float
  16. Time point of the center of the radio-frequency pulse.
  17. id_center : float
  18. Corresponding position of `time_center` in the radio-frequency pulse's envelope.
  19. """
  20. # Detect the excitation peak; if i is a plateau take its center
  21. rf_max = np.max(np.abs(rf.signal))
  22. i_peak = np.where(np.abs(rf.signal) >= rf_max * 0.99999)[0]
  23. time_center = (rf.t[i_peak[0]] + rf.t[i_peak[-1]]) / 2
  24. id_center = i_peak[int(np.round((len(i_peak) - 1) / 2))]
  25. return time_center, id_center