make_label.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. from types import SimpleNamespace
  2. from typing import Union
  3. from seqgen.pypulseq.supported_labels_rf_use import get_supported_labels
  4. def make_label(
  5. label: str, type: str, value: Union[bool, float, int]
  6. ) -> SimpleNamespace:
  7. """
  8. Create an ADC Label.
  9. Parameters
  10. ----------
  11. type : str
  12. Label type. Must be one of 'SET' or 'INC'.
  13. label : str
  14. Must be one of 'SLC', 'SEG', 'REP', 'AVG', 'SET', 'ECO', 'PHS', 'LIN', 'PAR', 'NAV', 'REV', or 'SMS'.
  15. value : bool, float or int
  16. Label value.
  17. Returns
  18. -------
  19. out : SimpleNamespace
  20. Label object.
  21. Raises
  22. ------
  23. ValueError
  24. If a valid `label` was not passed. Must be one of 'SLC', 'SEG', 'REP', 'AVG', 'SET', 'ECO', 'PHS', 'LIN', 'PAR',
  25. NAV', 'REV', or 'SMS'.
  26. If a valid `type` was not passed. Must be one of 'SET' or 'INC'.
  27. If `value` was not a valid numerical or logical value.
  28. """
  29. arr_supported_labels = get_supported_labels()
  30. if label not in arr_supported_labels:
  31. raise ValueError(
  32. "Invalid label. Must be one of 'SLC', 'SEG', 'REP', 'AVG', 'SET', 'ECO', 'PHS', 'LIN', 'PAR', "
  33. "NAV', 'REV', or 'SMS'."
  34. )
  35. if type not in ["SET", "INC"]:
  36. raise ValueError("Invalid type. Must be one of 'SET' or 'INC'.")
  37. if not isinstance(value, (bool, float, int)):
  38. raise ValueError("Must supply a valid numerical or logical value.")
  39. out = SimpleNamespace()
  40. if type == "SET":
  41. out.type = "labelset"
  42. elif type == "INC":
  43. out.type = "labelinc"
  44. out.label = label
  45. out.value = value
  46. return out