else: band = None file_list = os.listdir(DATA_PATH) n_patients = 27 n_electrodes = 153 # subject counters i_subjects = 0 i_channels = 0 for file in file_list: if file.startswith('spmeeg_'): print('Processing file: {}'.format(file)) d = ut.load_data_spm(file) fs = d['fsample'][0][0] channels = d['chanlabels'][0] # make new dict subject_dict = dict(channels=channels, phase={}, fs=fs, sharpness={}, steepness={}, subject_number=int(file[7:-4])) # for every lfp channel for i, lfp in enumerate(d['data']): current_channel = channels[i][0]
import matplotlib.pyplot as plt import numpy as np from definitions import SAVE_PATH_FIGURES, DATA_PATH from utils import load_data_spm, band_pass_filter file_list = os.listdir(DATA_PATH) i_subjects = 0 i_channels = 0 band = [13, 30] for f in file_list: if f.startswith('spmeeg_'): d = load_data_spm(f) fs = d['fsample'][0][0] dt = 1 / fs t = np.arange(0, d['data'].shape[1] * dt, dt) channel_labels = d['chanlabels'][0] plt.figure(figsize=(10, 5)) for i, lfp in enumerate(d['data']): # remove 50Hz noise or band pass filter lfp_clean = band_pass_filter(lfp, band=band, fs=fs) # lfp_clean = remove_50_noise(lfp, fs) plt.subplot(3, 2, i + 1) plt.plot(t[::200], lfp_clean[::200], linewidth=.7) plt.legend() plt.title('LFP channel {}'.format(channel_labels[i])) if not (i == 4 or i == 5):
band = np.array([4., 12.]) elif frequ_range == 'beta': band = np.array([12., 30.]) else: band = None # amount of time to be considered seconds = 5 seconds_str = '{}'.format(seconds) # for every subject file for sub, sub_file in enumerate(file_list): subject_number = int(sub_file[7:-4]) if subject_number > 0: # load data d = ut.load_data_spm(sub_file, data_folder=data_folder) fs = d['fsample'][0][0] channels = d['chanlabels'][0] print('analysing subject file {}'.format(sub_file)) # make new dict subject_dict = dict(lfp_band={}, channels=channels, phase={}, fs=fs) plt.figure(figsize=(10, 7)) for chan_idx, chan in enumerate(channels): # mean center lfp = d['data'][chan_idx] - d['data'][chan_idx].mean() # filter around the theta peak lfp_band = ut.band_pass_filter(lfp,
import matplotlib.pyplot as plt import numpy as np import os from definitions import SAVE_PATH_FIGURES from utils import load_data_spm, get_array_mask, band_pass_filter filename = 'spmeeg_19.mat' channel_name = 'GPiR23' d = load_data_spm(filename) fs = d['fsample'][0][0] lfp = None for idx, str in enumerate(d['chanlabels'][0]): if str[0] == channel_name: lfp = d['data'][idx] if lfp is None: raise ValueError( 'Could not find the specified channel in the data file: {}'.format( channel_name)) # remove mean lfp = lfp - np.mean(lfp) # filter in theta range: lfp_filt = band_pass_filter(y=lfp, fs=fs, band=[4, 12], plot_response=False) # construct the time vector dt = 1 / fs t = np.arange(0, d['data'].shape[1] * dt, dt)
n_electrodes = 153 max_amp_psds_theta = np.zeros((n_patients, n_frequ_samples)) max_amp_peak_frequency_theta = np.zeros(n_patients) max_amp_psds_beta = np.zeros((n_patients, n_frequ_samples)) max_amp_peak_frequency_beta = np.zeros(n_patients) theta_peaks = np.zeros(n_electrodes) beta_peaks = np.zeros(n_electrodes) # there are supposed to be 153 channels frequs = None # subject counters subject_idx = 0 electrode_idx = 0 for f in file_list: if f.startswith('spmeeg_'): d = ut.load_data_spm(f) fs = d['fsample'][0][0] chanlabels = d['chanlabels'][0] # prelocate amp arrays for saving the peak amp of every channel n_channels = d['data'].shape[0] beta_amp = np.zeros(n_channels) theta_amp = np.zeros(n_channels) psds = np.zeros((n_channels, n_frequ_samples)) theta_peak_frequency = np.zeros(n_channels) beta_peak_frequency = np.zeros(n_channels) plt.figure(figsize=(10, 5)) for channel_idx, lfp in enumerate(d['data']): # remove 50Hz noise lfp_clean = lfp
import matplotlib.pyplot as plt import numpy as np import os from definitions import SAVE_PATH_FIGURES from utils import load_data_spm, get_array_mask, band_pass_filter subject_number = 3 filename = 'spmeeg_{}.mat'.format(subject_number) channel_name = 'GPiL23' d = load_data_spm(filename, data_folder='/Users/Jan/Dropbox/Master/LR_Kuehn/data/dystonia_rest/for_python') fs = d['fsample'][0][0] lfp = None for idx, str in enumerate(d['chanlabels'][0]): if str[0] == channel_name: lfp = d['data'][idx] if lfp is None: raise ValueError('Could not find the specified channel in the data file: {}'.format(channel_name)) # remove mean lfp = lfp - np.mean(lfp) # filter in theta range: band = [4, 40] lfp_filt = band_pass_filter(y=lfp, fs=fs, band=band, plot_response=False) # construct the time vector dt = 1 / fs t = np.arange(0, d['data'].shape[1] * dt, dt)
n_subjects = 16 suffix = '' for sub in np.arange(1, n_subjects + 1): # save all data of current subject in dict subject_dict = dict(filenames={}, lfp={}, fs={}, conditions={}, chanlabels={}, time={}, id={}) plt.figure(figsize=(7, 5)) plot_idx = 1 for f in file_list: # process only the current subject if f.startswith('spmeeg_{}_'.format(sub)) and not f.startswith('spmeeg_{}_d'.format(sub)): current_file_name = f[:-4] print('plotting from {}'.format(f)) d = ut.load_data_spm(f, data_folder=DATA_PATH_BAROW) fs = d['fsample'][0][0] chanlabels = d['chanlabels'][0][0] condition = d['condition_str'][0] # save data subject_dict['lfp'][condition] = d['data'][0, :] subject_dict['filenames'][condition] = current_file_name subject_dict['fs'][condition] = fs subject_dict['conditions'][condition] = condition subject_dict['id'][condition] = d['subject_id'][0] subject_dict['chanlabels'][condition] = chanlabels[0] subject_dict['number'] = sub # downsample to make plotting faster down_factor = 300