make_digital_output_pulse.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from types import SimpleNamespace
  2. from seqgen.pypulseq.opts import Opts
  3. def make_digital_output_pulse(
  4. channel: str, delay: float = 0, duration: float = 4e-3, system: Opts = Opts()
  5. ) -> SimpleNamespace:
  6. """
  7. Create a digital output pulse event a.k.a. trigger. Creates an output trigger event on a given channel with optional
  8. given delay and duration.
  9. Parameters
  10. ----------
  11. channel : str
  12. Must be one of 'osc0','osc1', or 'ext1'.
  13. delay : float, default=0
  14. Delay in seconds (s).
  15. duration : float, default=4e-3
  16. Duration of trigger event in seconds (s).
  17. system : Opts, default=Opts()
  18. System limits.
  19. Returns
  20. ------
  21. trig : SimpleNamespace
  22. Trigger event.
  23. Raises
  24. ------
  25. ValueError
  26. If `channel` is invalid. Must be one of 'osc0','osc1', or 'ext1'.
  27. """
  28. if channel not in ["osc0", "osc1", "ext1"]:
  29. raise ValueError(
  30. f"Channel {channel} is invalid. Must be one of 'osc0','osc1', or 'ext1'."
  31. )
  32. trig = SimpleNamespace()
  33. trig.type = "output"
  34. trig.channel = channel
  35. trig.delay = delay
  36. trig.duration = duration
  37. if trig.duration <= system.grad_raster_time:
  38. trig.duration = system.grad_raster_time
  39. return trig