test_wpli.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. """ WPLI 单元测试 """
  2. import os
  3. from core.sig_chain.sig_reader import Reader
  4. from core.mi.eeg_wpli import Wpli
  5. TEST_DATA_PATH = "tests/data/"
  6. BDF_FILE_PATH = os.path.join(TEST_DATA_PATH, "eeg_raw_data.bdf")
  7. WPLI_FILE_PATH = os.path.join(TEST_DATA_PATH, "wpli.png")
  8. def setup_module():
  9. if not os.path.exists(TEST_DATA_PATH):
  10. os.makedirs(TEST_DATA_PATH)
  11. def teardown_module():
  12. if os.path.exists(WPLI_FILE_PATH):
  13. os.remove(WPLI_FILE_PATH)
  14. def test_main():
  15. # WPLI/CSP
  16. # 左右手
  17. ch_names = [
  18. "Fz", "Fp1", "F3", "F7", "C3", "T3", "T5", "P3", "O1", "Cz", "Oz", "Pz",
  19. "O2", "P4", "T6", "T4", "C4", "F8", "F4", "Fp2"
  20. ]
  21. reader = Reader()
  22. raw = reader.read(BDF_FILE_PATH, tuple(ch_names))
  23. raw.annotations.rename({
  24. "trainSuccess": "mi",
  25. "trainFailed": "mi",
  26. "restState": "rest"
  27. })
  28. wpli = Wpli()
  29. _, mi_epochs, _ = wpli.get_epochs(raw, tuple(ch_names))
  30. con_wpli, con_wpli_data = wpli.process(mi_epochs, raw.info["sfreq"])
  31. wpli.draw_image(con_wpli, con_wpli_data, save_path=WPLI_FILE_PATH)