utils.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. """想象运动工具类
  2. """
  3. from enum import Enum
  4. from core.sig_chain.device.connector_interface import Device
  5. class Mark(Enum):
  6. REST = "rest"
  7. MI = "mi"
  8. class SelectedChannel():
  9. def get_channel_names(self, position:str):
  10. if position == "左手":
  11. return self.left_hand_channel
  12. elif position == "右手":
  13. return self.right_hand_channel
  14. else:
  15. return self.foot_channel
  16. def get_channel_ids(self, position:str, channel_labels: list):
  17. selected = []
  18. if position == "左手":
  19. selected = self.left_hand_channel
  20. elif position == "右手":
  21. selected = self.right_hand_channel
  22. else:
  23. selected = self.foot_channel
  24. try:
  25. selected_ids = [channel_labels.index(item) for item in selected]
  26. return selected_ids
  27. except ValueError as exc:
  28. # pylint: disable=line-too-long
  29. raise Exception(
  30. f"Some selected channel({selected}) missing in input channel({channel_labels})"
  31. ) from exc
  32. # pylint: enable=line-too-long
  33. class SelectedCspChannel(SelectedChannel):
  34. def __init__(self, device: Device):
  35. if device == Device.NEO:
  36. self.left_hand_channel = ["C4", "FC4", "CP2", "CP6"]
  37. self.right_hand_channel = ["C3", "FC3", "CP5", "CP1"]
  38. else:
  39. self.left_hand_channel = [
  40. "Fz", "F4", "F8", "Cz", "C4", "T4", "Pz", "P4", "T6"
  41. ]
  42. self.right_hand_channel = [
  43. "F7", "F3", "Fz", "T3", "C3", "Cz", "T5", "P3", "Pz"
  44. ]
  45. self.foot_channel = [
  46. "F3", "Fz", "F4", "C3", "Cz", "C4", "P3", "Pz", "P4"
  47. ]
  48. class SelectedCspPlotChannel(SelectedChannel):
  49. def __init__(self, device: Device):
  50. if device == Device.NEO:
  51. self.left_hand_channel = [
  52. "C3", "FC3", "CP5", "CP1", "C4", "FC4", "CP2", "CP6"
  53. ]
  54. self.right_hand_channel = self.left_hand_channel
  55. else:
  56. self.left_hand_channel = [
  57. "T6", "P4", "Pz", "F8", "F4", "Fp1", "Cz", "F7", "F3", "C3",
  58. "T3", "Oz", "O1", "O2", "Fz", "C4", "T4", "Fp2", "T5", "P3"
  59. ]
  60. self.right_hand_channel = self.left_hand_channel
  61. self.foot_channel = self.left_hand_channel
  62. class SelectedPsdChannel(SelectedChannel):
  63. def __init__(self, device: Device):
  64. self.left_hand_channel = ["C4"]
  65. self.right_hand_channel = ["C3"]
  66. if device != Device.NEO:
  67. self.foot_channel = ["Cz"]
  68. class SelectedPsdPlotChannel(SelectedChannel):
  69. def __init__(self, device: Device):
  70. channels = ["C3","C4"]
  71. self.left_hand_channel = channels
  72. self.right_hand_channel = channels
  73. if device != Device.NEO:
  74. self.foot_channel = ["C3", "Cz", "C4"]
  75. class SelectedErdsChannel(SelectedChannel):
  76. def __init__(self, device: Device):
  77. self.left_hand_channel = ["C3", "C4"]
  78. self.right_hand_channel = ["C3", "C4"]
  79. if device != Device.NEO:
  80. self.foot_channel = ["C3", "Cz", "C4"]
  81. class SelectedWpliChannel(SelectedChannel):
  82. def __init__(self, device: Device):
  83. if device == Device.NEO:
  84. self.left_hand_channel = [
  85. "C3", "FC3", "CP5", "CP1", "C4", "FC4", "CP2", "CP6"
  86. ]
  87. else:
  88. self.left_hand_channel = [
  89. "T6", "P4", "Pz", "F8", "F4", "Fp1", "Cz", "F7", "F3", "C3",
  90. "T3", "Oz", "O1", "O2", "Fz", "C4", "T4", "Fp2", "T5", "P3"
  91. ]
  92. self.right_hand_channel = self.left_hand_channel
  93. self.foot_channel = self.left_hand_channel