예제 #1
0
import matplotlib.pyplot as plt
"""
for every subject make a plot of histograms of sharpness of peaks and troughs
"""
data_folder = os.path.join(SAVE_PATH_DATA_BAROW, 'analysis')

# read all files in the data folder
file_list = [
    f for f in os.listdir(data_folder)
    if f.endswith('beta.p') and f.startswith('subject')
]

# for every subject file
for sub, sub_file in enumerate(file_list):
    # load data
    d = ut.load_data_analysis(sub_file, data_folder=data_folder)
    frequ_range = d['frequ_range']
    print('analysing subject file {}'.format(sub_file))

    plt.figure(figsize=(10, 5))
    plt.subplot(1, 3, 1)
    plt.ylabel('cycle count')

    condition_order = ['rest', 'stim', 'poststim']
    conditions = d['conditions']
    # for all three conditions
    for i in range(len(conditions)):
        condition = condition_order[i]
        print('Condition {}'.format(condition))
        n_bins = 30
예제 #2
0
import os
import matplotlib.pyplot as plt
import numpy as np
import utils as ut
from definitions import SAVE_PATH_FIGURES
"""
Plot figure figure 1A from the Neumann et al 2017 paper manuscript: the average psd over subjects
as well as the histogram over psd peaks in beta and in theta range 
"""

# load data
suffix = '_linear_search_and_amp'
data = ut.load_data_analysis('psd_maxamp_theta_beta{}.p'.format(suffix))
# now make a plot of all selected channels and the histogram over peaks
frequs = data['frequs']

mask = ut.get_array_mask(frequs > 4, frequs < 40)
plt.figure(figsize=(7, 5))
# plot individual stectra
# plt.plot(frequs[mask], data['psd_beta'][:, mask].T, linewidth=.7, color='C1', alpha=.5)
# plt.plot(frequs[mask], data['psd_theta'][:, mask].T, linewidth=.7, color='C4', alpha=.5)

# plot std envelope
joined_psd_mean = np.mean(np.vstack((data['psd_theta'], data['psd_beta'])),
                          axis=0)
se = ut.standard_error(np.vstack((data['psd_theta'], data['psd_beta'])),
                       axis=0)
plt.fill_between(frequs[mask],
                 joined_psd_mean[mask] + se[mask],
                 joined_psd_mean[mask] - se[mask],
                 alpha=.2,
import os
import matplotlib.pyplot as plt
import numpy as np
import utils as ut
from definitions import SAVE_PATH_FIGURES
"""
Plot the mean coherence over subjects. select for every subject the channel with the largest amplitude in coherence. 
"""

# load data
suffix = ''
window_length = 1024
data = ut.load_data_analysis('coh_icoh_allsubjects_w{}_{}.p'.format(
    window_length, suffix))
# now make a plot of all selected channels and the histogram over peaks
f = data['frequs']
mask = ut.get_array_mask(f > 1, f < 30)
coh_mat = data['coh_mat'][:, :, mask]
icoh_mat = data['icoh_mat'][:, :, mask]
n_subjects, n_channels, n_frequ_samples = coh_mat.shape

max_coh_channels = np.zeros((n_subjects, n_frequ_samples))
max_icoh_channels = np.zeros((n_subjects, n_frequ_samples))

for subject_idx in range(n_subjects):
    # select the channel with the largest coherence
    channel_idx = np.argmax(np.max(coh_mat[subject_idx, ], axis=1))

    max_coh_channels[subject_idx, ] = coh_mat[subject_idx, channel_idx, :]
    max_icoh_channels[subject_idx, ] = icoh_mat[subject_idx, channel_idx, :]
import os
import matplotlib.pyplot as plt
import numpy as np
import utils as ut
from definitions import SAVE_PATH_FIGURES, SAVE_PATH_DATA, DATA_PATH

data_folder = os.path.join(SAVE_PATH_DATA, 'stn')
save_folder = os.path.join(SAVE_PATH_FIGURES, 'stn')
filename = 'stn_data_sharpness_over_epochs.p'

data_dict = ut.load_data_analysis(filename, data_folder)
n_subject = len(data_dict.keys())
n_channels = 6

# make one big figure with channels subplot showing the esr and rdsr over condition for all subjects
plt.figure(figsize=(15, 8))

# for every subject, select the channel with the largest difference in esr
esr_over_conditions = np.zeros((n_subject, 2))
rdsr_over_conditions = np.zeros((n_subject, 2))

esr_over_channels = np.zeros((n_subject, 6, 2))
rdsr_over_channels = np.zeros((n_subject, 6, 2))
esr_over_channels_std = np.zeros((n_subject, 6, 2))
rdsr_over_channels_std = np.zeros((n_subject, 6, 2))

band_idx = 0
bands = [[11, 22], [18, 32]]
band_strings = ['low_beta', 'high_beta']

for subject_idx, subject_dict in enumerate(data_dict.values()):