make_trigger.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # inserted for trigger support by mveldmann
  2. from types import SimpleNamespace
  3. from seqgen.pypulseq.opts import Opts
  4. def make_trigger(
  5. channel: str, delay: float = 0, duration: float = 0, system: Opts = Opts()
  6. ) -> SimpleNamespace:
  7. """
  8. Create a trigger halt event for a synchronisation with an external signal from a given channel with an optional
  9. given delay prio to the sync and duration after the sync. Possible channel values: 'physio1','physio2'
  10. (Siemens specific).
  11. See also `pypulseq.Sequence.sequence.Sequence.add_block()`.
  12. Parameters
  13. ----------
  14. channel : str
  15. Must be one of 'physio1' or 'physio2'.
  16. delay : float, default=0
  17. Delay in seconds
  18. duration: float, default=0
  19. Duration in seconds.
  20. system : Opts, default=Opts()
  21. System limits.
  22. Returns
  23. -------
  24. trigger : SimpleNamespace
  25. Trigger event.
  26. Raises
  27. ------
  28. ValueError
  29. If invalid `channel` is passed. Must be one of 'physio1' or 'physio2'.
  30. """
  31. if channel not in ["physio1", "physio2"]:
  32. raise ValueError(
  33. f"Channel {channel} is invalid. Must be one of 'physio1' or 'physio2'."
  34. )
  35. trigger = SimpleNamespace()
  36. trigger.type = "trigger"
  37. trigger.channel = channel
  38. trigger.delay = delay
  39. trigger.duration = duration
  40. if trigger.duration <= system.grad_raster_time:
  41. trigger.duration = system.grad_raster_time
  42. return trigger