epdat_3 = epdat_3[:,mask_trials_3,:] print('Total Trials Left: ' + str(epdat.shape[1])) print('Total Trials Left_3: ' + str(epdat_3.shape[1])) Tot_trials = epdat.shape[1] + epdat_3.shape[1] plt.figure() plt.plot(Peak2Peak.T) plt.title(subject + ' Tot trials:' + str(Tot_trials)) # plt.figure() # plt.plot(Peak2Peak_3.T) #%% Correlation Analysis Ht_12 = mseqXcorr(epdat,mseq[0,:]) Ht_3 = mseqXcorr(epdat_3,mseq_shift[0,:]) Ht_epochs_12, t_epochs = mseqXcorrEpochs_fft(epdat,mseq[0,:],fs) Ht_epochs_3, t_epochs = mseqXcorrEpochs_fft(epdat_3,mseq_shift[0,:],fs) Ht_epochs = np.concatenate([Ht_epochs_12,Ht_epochs_3],axis=1) Ht = Ht_12 * epdat.shape[1]/Tot_trials + Ht_3 * epdat_3.shape[1]/Tot_trials #%% Plot Ht # if ch_picks.size == 31: # sbp = [5,3] # sbp2 = [4,4]
ch_maxAmp = Peak2Peak.mean(axis=1).argmax() # plt.figure() # plt.plot(Peak2Peak.T) # plt.figure() # plt.plot(Peak2Peak[:,mask_trials].T) # plt.figure() # plt.plot(Peak2Peak[np.delete(ch_picks,ch_maxAmp),:].T) #%% Correlation Analysis Htnf = [] Ht = mseqXcorr(epdat, mseq[0, :]) for nf in range(num_nfs): print('On nf:' + str(nf)) resp = epdat inv_inds = np.random.permutation( epdat.shape[1])[:round(epdat.shape[1] / 2)] resp[:, inv_inds, :] = -resp[:, inv_inds, :] Ht_nf = mseqXcorr(resp, mseq[0, :]) Htnf.append(Ht_nf) #%% Plot Ht # if ch_picks.size == 31: # sbp = [5,3] # sbp2 = [4,4]
with open(os.path.join(data_loc, Subject + '_DynBin.pickle'), 'rb') as f: IAC_epochs, ITD_epochs = pickle.load(f) #%% Extract epochs when stim is on t = IAC_epochs.times fs = IAC_epochs.info['sfreq'] t1 = np.where(t >= 0)[0][0] t2 = t1 + Mseq.size + int(np.round(0.4 * fs)) t = t[t1:t2] t = np.concatenate((-t[-int(np.round(0.4 * fs)):0:-1], t[:-1])) ch_picks = np.arange(32) IAC_ep = IAC_epochs.get_data()[:, ch_picks, t1:t2].transpose(1, 0, 2) #ITD_ep = ITD_epochs.get_data()[:,ch_picks,t1:t2].transpose(1,0,2) IAC_Ht = mseqXcorr(IAC_ep, Mseq[:, 0]) #IAC_Ht = IAC_Ht[:,np.where(t>=0)[0][0]:] #%% Plot stuff IAC_evoked = IAC_epochs.average() fig = mne.viz.plot_evoked_topo(IAC_evoked, legend=False) plt.savefig(os.path.join(fig_path, 'IAC_evkd_topo.svg'), format='svg') times_plot = (t > 0) & (t < 0.5) IAC_evoked.data = IAC_Ht[:, times_plot] IAC_evoked.times = t[times_plot] mne.viz.plot_evoked_topo(IAC_evoked, legend=False) plt.savefig(os.path.join(fig_path, 'IAC_Ht_topo.svg'), format='svg')
#%% Remove epochs with large deflections Reject_Thresh=150e-6 Peak2Peak = epdat.max(axis=2) - epdat.min(axis=2) mask_trials = np.all(Peak2Peak < Reject_Thresh,axis=0) print('rejected ' + str(epdat.shape[1] - sum(mask_trials)) + ' trials due to P2P') epdat = epdat[:,mask_trials,:] print('Total Trials Left: ' + str(epdat.shape[1])) Tot_trials = epdat.shape[1] plt.figure() plt.plot(Peak2Peak.T) #%% Correlation Analysis Ht = mseqXcorr(epdat,mseq[0,:]) #%% Plot Ht if ch_picks.size == 31: sbp = [5,3] sbp2 = [4,4] elif ch_picks.size == 32: sbp = [4,4] sbp2 = [4,4] elif ch_picks.size == 30: sbp = [5,3] sbp2 = [5,3]
Tot_trials[m] = epdat[m].shape[1] plt.figure() plt.plot(Peak2Peak.T) #%% Correlation Analysis Ht = [] Htnf = [] Tot_trials = np.zeros([len(mseq)]) # do cross corr for m in range(len(epdat)): print('On mseq # ' + str(m + 1)) Tot_trials[m] = epdat[m].shape[1] Ht_m = mseqXcorr(epdat[m], mseq[m][0, :]) Ht.append(Ht_m) for nf in range(num_nfs): resp = epdat[m] inv_inds = np.random.permutation( epdat[m].shape[1])[:round(epdat[m].shape[1] / 2)] resp[:, inv_inds, :] = -resp[:, inv_inds, :] Ht_nf = mseqXcorr(resp, mseq[m][0, :]) #%% Plot Ht if ch_picks.size == 31: sbp = [5, 3] sbp2 = [4, 4] elif ch_picks.size == 32: sbp = [4, 4]
print('Total IAC trials: ' + str(IAC_ep.shape[1])) Tot_trials_IAC = IAC_ep.shape[1] Peak2Peak = ITD_ep.max(axis=2) - ITD_ep.min(axis=2) mask_trials = np.all(Peak2Peak < reject_thresh, axis=0) print('rejected ' + str(ITD_ep.shape[1] - sum(mask_trials)) + ' ITD trials due to P2P') ITD_ep = ITD_ep[:, mask_trials, :] print('Total ITD trials: ' + str(ITD_ep.shape[1])) Tot_trials_ITD = ITD_ep.shape[1] #%% Calculate Ht IAC_Ht = mseqXcorr(IAC_ep, Mseq[:, 0]) ITD_Ht = mseqXcorr(ITD_ep, Mseq[:, 0]) #%% Calculate Noise Floors IAC_Htnf = [] ITD_Htnf = [] for nf in range(Num_noiseFloors): IAC_nf = IAC_ep.copy() ITD_nf = ITD_ep.copy() IACrnd_inds = np.random.permutation( IAC_ep.shape[1])[:round(IAC_ep.shape[1] / 2)] ITDrnd_inds = np.random.permutation( ITD_ep.shape[1])[:round(ITD_ep.shape[1] / 2)] IAC_nf[:, IACrnd_inds, :] = -IAC_nf[:, IACrnd_inds, :] ITD_nf[:, ITDrnd_inds, :] = -ITD_nf[:, ITDrnd_inds, :]
# plt.figure() # plt.plot(Peak2Peak.T) #%% correlation analysis Ht = [] Htnf = [] # do cross corr for m in range(len(epdat)): print('On mseq # ' + str(m+1)) # resp_m = epdat[m].mean(axis=1) Ht_m = mseqXcorr(epdat[m],mseq[0,:]) Ht.append(Ht_m) #%% Plot Ht if ch_picks.size == 31: sbp = [5,3] sbp2 = [4,4] elif ch_picks.size == 32: sbp = [4,4] sbp2 = [4,4] elif ch_picks.size == 30: sbp = [5,3] sbp2 = [5,3]
mask_trials = np.all(Peak2Peak < Reject_Thresh, axis=0) print('rejected ' + str(epdat[cond].shape[1] - sum(mask_trials)) + ' trials due to P2P') epdat[cond] = epdat[cond][:, mask_trials, :] print('Total Trials Left: ' + str(epdat[cond].shape[1])) Tot_trials.append(epdat[cond].shape[1]) plt.figure() plt.plot(Peak2Peak.T) plt.title(cond) #%% Correlation analysis Htnf = [] Ht = [] for cond in range(2): Ht.append(mseqXcorr(epdat[cond], mseq[0, :])) Htnf_nf = [] for nf in range(num_nfs): print('On nf:' + str(nf)) resp = epdat[cond] inv_inds = np.random.permutation( epdat[cond].shape[1])[:round(epdat[cond].shape[1] / 2)] resp[:, inv_inds, :] = -resp[:, inv_inds, :] Ht_nf = mseqXcorr(resp, mseq[0, :]) Htnf_nf.append(Ht_nf) Htnf.append(Htnf_nf) #%% Plot Ht if ch_picks.size == 31:
Peak2Peak = epdat[ep].max(axis=2) - epdat[ep].min(axis=2) mask_trials = np.all(Peak2Peak < Reject_Thresh, axis=0) print('rejected ' + str(epdat[ep].shape[1] - sum(mask_trials)) + ' trials due to P2P') epdat[ep] = epdat[ep][:, mask_trials, :] print('Total Trials Left: ' + str(epdat[ep].shape[1])) Tot_trials[ep] = epdat[ep].shape[1] plt.figure() plt.plot(Peak2Peak.T) #%% Correlation Analysis Ht = [] for ep in range(3): Ht.append(mseqXcorr(epdat[ep], mseq[0, :])) #%% Plot Ht if ch_picks.size == 31: sbp = [5, 3] sbp2 = [4, 4] elif ch_picks.size == 32: sbp = [4, 4] sbp2 = [4, 4] elif ch_picks.size == 30: sbp = [5, 3] sbp2 = [5, 3] fig, axs = plt.subplots(sbp[0], sbp[1], sharex=True, gridspec_kw=None) for ep in range(3):