test_sigpy.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. # sms - check MB
  2. # slr - check slice profile
  3. import unittest
  4. import numpy as np
  5. import sigpy.mri.rf as rf
  6. from pypulseq.make_sigpy_pulse import sigpy_n_seq
  7. from pypulseq.opts import Opts
  8. from pypulseq.sigpy_pulse_opts import SigpyPulseOpts
  9. class TestSigpyPulseMethods(unittest.TestCase):
  10. def test_slr(self):
  11. print("Testing SLR design")
  12. time_bw_product = 4
  13. slice_thickness = 3e-3 # Slice thickness
  14. flip_angle = np.pi / 2
  15. # Set system limits
  16. system = Opts(
  17. max_grad=32,
  18. grad_unit="mT/m",
  19. max_slew=130,
  20. slew_unit="T/m/s",
  21. rf_ringdown_time=30e-6,
  22. rf_dead_time=100e-6,
  23. )
  24. pulse_cfg = SigpyPulseOpts(
  25. pulse_type="slr",
  26. ptype="st",
  27. ftype="ls",
  28. d1=0.01,
  29. d2=0.01,
  30. cancel_alpha_phs=False,
  31. n_bands=3,
  32. band_sep=20,
  33. phs_0_pt="None",
  34. )
  35. rfp, gz, _, pulse = sigpy_n_seq(
  36. flip_angle=flip_angle,
  37. system=system,
  38. duration=3e-3,
  39. slice_thickness=slice_thickness,
  40. time_bw_product=4,
  41. return_gz=True,
  42. pulse_cfg=pulse_cfg,
  43. )
  44. [a, b] = rf.sim.abrm(
  45. pulse,
  46. np.arange(
  47. -20 * time_bw_product, 20 * time_bw_product, 40 * time_bw_product / 2000
  48. ),
  49. True,
  50. )
  51. Mxy = 2 * np.multiply(np.conj(a), b)
  52. # pl.LinePlot(Mxy)
  53. # print(np.sum(np.abs(Mxy)))
  54. # peaks, dict = sis.find_peaks(np.abs(Mxy),threshold=0.5, plateau_size=40)
  55. plateau_widths = np.sum(np.abs(Mxy) > 0.8)
  56. self.assertTrue(29, plateau_widths)
  57. def test_sms(self):
  58. print("Testing SMS design")
  59. time_bw_product = 4
  60. slice_thickness = 3e-3 # Slice thickness
  61. flip_angle = np.pi / 2
  62. n_bands = 3
  63. # Set system limits
  64. system = Opts(
  65. max_grad=32,
  66. grad_unit="mT/m",
  67. max_slew=130,
  68. slew_unit="T/m/s",
  69. rf_ringdown_time=30e-6,
  70. rf_dead_time=100e-6,
  71. )
  72. pulse_cfg = SigpyPulseOpts(
  73. pulse_type="sms",
  74. ptype="st",
  75. ftype="ls",
  76. d1=0.01,
  77. d2=0.01,
  78. cancel_alpha_phs=False,
  79. n_bands=n_bands,
  80. band_sep=20,
  81. phs_0_pt="None",
  82. )
  83. rfp, gz, _, pulse = sigpy_n_seq(
  84. flip_angle=flip_angle,
  85. system=system,
  86. duration=3e-3,
  87. slice_thickness=slice_thickness,
  88. time_bw_product=4,
  89. return_gz=True,
  90. pulse_cfg=pulse_cfg,
  91. )
  92. [a, b] = rf.sim.abrm(
  93. pulse,
  94. np.arange(
  95. -20 * time_bw_product, 20 * time_bw_product, 40 * time_bw_product / 2000
  96. ),
  97. True,
  98. )
  99. Mxy = 2 * np.multiply(np.conj(a), b)
  100. # pl.LinePlot(Mxy)
  101. # print(np.sum(np.abs(Mxy)))
  102. # peaks, dict = sis.find_peaks(np.abs(Mxy),threshold=0.5, plateau_size=40)
  103. plateau_widths = np.sum(np.abs(Mxy) > 0.8)
  104. self.assertEqual(
  105. 29 * n_bands, plateau_widths
  106. ) # if slr has 29 > 0.8, then sms with MB = n_bands
  107. if __name__ == "__main__":
  108. unittest.main()