Fixed some smaller things

This commit is contained in:
2021-03-28 04:46:37 +02:00
parent 3b837869fe
commit c86d46f447
13 changed files with 80 additions and 26 deletions

View File

@@ -111,6 +111,7 @@ def decoding(dataset, filename, compute_metric=True, mask=None):
if times is None:
times = epochs.times
np.save('cached_data/decoding_data/' + filename, metric)
metric = np.asarray(metric)
else:
# Dummy time which is created according to epoch.times
times = np.linspace(-0.09960938, 1, 1127)
@@ -128,7 +129,7 @@ def decoding(dataset, filename, compute_metric=True, mask=None):
# Compute the permutation tests
for t in range(len(metric[0][index:])):
score_t = np.asarray(metric[:, t + index])
p = permutation_test(baseline, score_t, 1000)
p = permutation_test(baseline, score_t, 100)
p_values.append(p)
if t % 50 == 0:
print(str(t) + " Out of " + str(len(metric[0][index:])))
@@ -140,7 +141,7 @@ def decoding(dataset, filename, compute_metric=True, mask=None):
plt.show()
def create_tfr(raw, condition, freqs, n_cycles, response='induced', baseline=None):
def create_tfr(raw, condition, freqs, n_cycles, response='induced', baseline=None, plot=False):
"""
Compute the time frequency representation (TFR) of data for a given condition via morlet wavelets
:param raw: the data
@@ -166,10 +167,11 @@ def create_tfr(raw, condition, freqs, n_cycles, response='induced', baseline=Non
power_total = tfr_morlet(epochs, freqs=freqs, n_cycles=n_cycles, return_itc=False, n_jobs=4)
power_induced = tfr_morlet(epochs.subtract_evoked(), freqs=freqs, n_cycles=n_cycles, return_itc=False, n_jobs=4)
power = mne.combine_evoked([power_total, power_induced], weights=[1, -1])
# power.plot(picks='P7')
if plot: power.plot(picks='P7')
power.apply_baseline(mode='ratio', baseline=baseline)
# plot_oscillation_bands(power)
# power.plot(picks='P7')
if plot:
plot_oscillation_bands(power)
power.plot(picks='P7')
return power
@@ -184,7 +186,7 @@ def time_frequency(dataset, filename, compute_tfr=True):
"""
# Parameters
# Frequency space (from, to, steps) -> Control frequency resolution : Between num=50-80 good for 1-50Hz
# freqs = np.linspace(0.1, 50, num=50) #
# freqs = np.linspace(0.1, 50, num=50) # Use this for linear space scaling
freqs = np.logspace(*np.log10([0.1, 50]), num=50)
# Number of cycles -> Controls time resolution ? At ~freqs/2 good for high frequency resolution
n_cycles = freqs / 2 # 1 for high time resolution & freq smoothing, freqs/2 for high freq resolution & time smooth
@@ -224,8 +226,8 @@ def time_frequency(dataset, filename, compute_tfr=True):
cond2 = np.load('cached_data/tf_data/' + filename + '_cond2.npy', allow_pickle=True).tolist()
if times is None:
times = cond1[0].times
# mne.grand_average(cond1).plot(picks=['P7'], vmin=-3, vmax=3, title='Grand Average P7')
# mne.grand_average(cond2).plot(picks=['P7'], vmin=-3, vmax=3, title='Grand Average P7')
mne.grand_average(cond1).plot(picks=['P7'], vmin=-3, vmax=3, title='Grand Average P7')
mne.grand_average(cond2).plot(picks=['P7'], vmin=-3, vmax=3, title='Grand Average P7')
plot_oscillation_bands(mne.grand_average(cond1))
plot_oscillation_bands(mne.grand_average(cond2))
F, clusters, cluster_p_values, h0 = mne.stats.permutation_cluster_test(
@@ -237,6 +239,5 @@ def time_frequency(dataset, filename, compute_tfr=True):
if __name__ == '__main__':
mne.set_log_level(verbose=VERBOSE_LEVEL)
ds = 'N170'
# decoding(ds, 'faces_vs_cars_100iters', False)
# time_frequency(ds, 'face_intact_vs_all_0.1_50hz_ncf2', False)
time_frequency(ds, 'face_intact_vs_all_0.1_50hz_ncf2', False)
decoding(ds, 'faces_vs_cars', True)
time_frequency(ds, 'face_intact_vs_all_0.1_50hz_ncf2', True)