make_adc.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. from types import SimpleNamespace
  2. from seqgen.pypulseq.opts import Opts
  3. def make_adc(
  4. num_samples: int,
  5. delay: float = 0,
  6. duration: float = 0,
  7. dwell: float = 0,
  8. freq_offset: float = 0,
  9. phase_offset: float = 0,
  10. system: Opts = Opts(),
  11. ) -> SimpleNamespace:
  12. """
  13. Create an ADC readout event.
  14. Parameters
  15. ----------
  16. num_samples: int
  17. Number of readout samples.
  18. system : Opts, default=Opts()
  19. System limits. Default is a system limits object initialised to default values.
  20. dwell : float, default=0
  21. ADC dead time in seconds (s) after sampling.
  22. duration : float, default=0
  23. Duration in seconds (s) of ADC readout event with `num_samples` number of samples.
  24. delay : float, default=0
  25. Delay in seconds (s) of ADC readout event.
  26. freq_offset : float, default=0
  27. Frequency offset of ADC readout event.
  28. phase_offset : float, default=0
  29. Phase offset of ADC readout event.
  30. Returns
  31. -------
  32. adc : SimpleNamespace
  33. ADC readout event.
  34. Raises
  35. ------
  36. ValueError
  37. If neither `dwell` nor `duration` are defined.
  38. """
  39. adc = SimpleNamespace()
  40. adc.type = "adc"
  41. adc.num_samples = num_samples
  42. adc.dwell = dwell
  43. adc.delay = delay
  44. adc.freq_offset = freq_offset
  45. adc.phase_offset = phase_offset
  46. adc.dead_time = system.adc_dead_time
  47. if (dwell == 0 and duration == 0) or (dwell > 0 and duration > 0):
  48. raise ValueError("Either dwell or duration must be defined")
  49. if duration > 0:
  50. adc.dwell = duration / num_samples
  51. if dwell > 0:
  52. adc.duration = dwell * num_samples
  53. if adc.dead_time > adc.delay:
  54. adc.delay = adc.dead_time
  55. return adc