core.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. """
  2. Author: linxiaohong linxiaohong@neuracle.cn
  3. Date: 2023-07-17 14:14:20
  4. LastEditors: linxiaohong linxiaohong@neuracle.cn
  5. LastEditTime: 2023-07-19 14:02:01
  6. FilePath: Albatross/backend/tests/utils/core.py
  7. Description: tests/core 中的测试共用的工具函数
  8. Copyright (c) 2023 by Neuracle, All Rights Reserved.
  9. """
  10. import mne
  11. def get_epochs(raw, picks, event_name=None, tmin=0, tmax=1):
  12. events, event_id = mne.events_from_annotations(raw)
  13. if event_name is None:
  14. event_id_pick = event_id
  15. else:
  16. event_id_pick = {event_name: event_id[event_name]}
  17. epochs = mne.Epochs(raw,
  18. events,
  19. event_id_pick,
  20. tmin,
  21. tmax,
  22. picks=picks,
  23. baseline=None,
  24. preload=True)
  25. return epochs
  26. def crop_by_annotation(raw, annot):
  27. onset = annot["onset"] - raw.first_time
  28. if -raw.info["sfreq"] / 2 < onset < 0:
  29. onset = 0
  30. raw_crop = raw.copy().crop(onset, onset + annot["duration"])
  31. return raw_crop