Jeremiah_

mne

Mar 16th, 2020
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.99 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Mon Mar 16 11:06:18 2020
  4.  
  5. @author: J. Abreu
  6.  
  7. """
  8.  
  9. #%% importings
  10. import numpy as np
  11. import mne
  12. import os
  13.  
  14. mne.set_log_level('WARNING')
  15. mne.utils.set_config('MNE_USE_CUDA', 'true')
  16. #mne.io.Raw.set_montage(montage='standard_1020')
  17. #%%
  18. def read_edf(path='D:/Jeremias/Datasets/tuh_mixed'):
  19.     raw_list = []
  20.    
  21.     for file in os.listdir(path):
  22.         if os.path.isfile(os.path.join(path, file)) and os.path.join(path, file)[-3:] == 'edf':
  23.             raw_list.append(mne.io.read_raw_edf(os.path.join(path, file)))
  24.     return raw_list
  25. #%%
  26. def sum_events(raw_list):
  27.     if type(raw_list) == list:
  28.         sum = 0
  29.         for raw in raw_list:
  30.             sum += len(raw.info['events'])
  31.         print(sum)
  32.     elif type(raw_list) == mne.io.edf.edf.RawEDF:
  33.         print(len(raw_list.info['events']))
  34.     else:
  35.         print('type of file not accepted! only list of io.edf.edf.RawEDF ' \
  36.               + 'or a single io.edf.edf.RawEDF file')
  37.  
  38. #%%
  39. def get_annotation_file(raw=None):
  40.     if raw is None:
  41.         print('no file name')
  42.         return
  43.    
  44.     try:
  45.         path = raw._filenames[0][:-9] + '.txt'
  46.         with open(path, 'r') as f:
  47.             txt = f.read()
  48.            
  49.         print(txt)
  50.     except:
  51.         raise FileNotFoundError('verify if the file name is correct')
  52. #%% set standard montage
  53. #montage = mne.channels.make_standard_montage('stardad_1020')
  54. #raw.set_montage(montage, raise_if_subset=False, verbose=False)
  55.  
  56. #%%
  57. def viz(raw):
  58.     montage = mne.channels.make_standard_montage('standard_1020')
  59.     raw.set_montage(montage, raise_if_subset=False, verbose=False)
  60.    
  61.     print('number of events: ', len(raw.info['events']))
  62.    
  63.     events = mne.make_fixed_length_events(raw, first_samp=True)
  64.     picks = mne.pick_types(raw.info, meg=False, eeg=True)
  65.    
  66.     baseline = (None, 0)
  67.    
  68.     epochs = mne.Epochs(raw, events, event_id=1, picks=picks, preload=True)
  69.     evoked = epochs.average()
  70.     evoked.plot()
Advertisement
Add Comment
Please, Sign In to add comment