def plot_probheatmaps(probabilityArray, fsds, skip, threshold=0.5, smoothing=20, channel1=0, channel2=1): fig, ax = plt.subplots(3, 2, figsize=(10, 10), dpi=300) windows, nchan = probabilityArray.shape thresholded = copy.deepcopy(probabilityArray) thresholded[thresholded > threshold] = 1 thresholded[thresholded <= threshold] = 0 w = int(smoothing * fsds / skip) mvgAvg = np.zeros(shape=(windows - w + 1, nchan)) for c in range(nchan): mvgAvg[:, c] = echobase.movingaverage(probabilityArray[:, c], w) mvgAvgThreshold = copy.deepcopy(mvgAvg) mvgAvgThreshold[mvgAvgThreshold > threshold] = 1 mvgAvgThreshold[mvgAvgThreshold <= threshold] = 0 sns.lineplot(x=range(windows), y=probabilityArray[:, channel1], ci=None, ax=ax[0, 0]) sns.lineplot(x=range(windows), y=probabilityArray[:, channel2], ci=None, ax=ax[0, 1]) sns.heatmap(probabilityArray.T, ax=ax[1, 0]) sns.heatmap(thresholded.T, ax=ax[1, 1]) sns.heatmap(mvgAvg.T, ax=ax[2, 0]) sns.heatmap(mvgAvgThreshold.T, ax=ax[2, 1])
def plot_heatmapSingleThreshold(probabilityArray, fsds, skip, figsize=(5, 2.5), threshold=0.5, smoothing=20, vmax=1.1, cmapName="Blues"): fig, ax = plt.subplots(1, 1, figsize=figsize, dpi=300) windows, nchan = probabilityArray.shape thresholded = copy.deepcopy(probabilityArray) thresholded[thresholded > threshold] = 1 thresholded[thresholded <= threshold] = 0 w = int(smoothing * fsds / skip) mvgAvg = np.zeros(shape=(windows - w + 1, nchan)) for c in range(nchan): mvgAvg[:, c] = echobase.movingaverage(probabilityArray[:, c], w) mvgAvgThreshold = copy.deepcopy(mvgAvg) mvgAvgThreshold[mvgAvgThreshold > threshold] = 1 mvgAvgThreshold[mvgAvgThreshold <= threshold] = 0 cmap = plt.cm.get_cmap(cmapName) sns.heatmap(mvgAvgThreshold.T, cmap=cmap, ax=ax, cbar=False, xticklabels=False, yticklabels=False, vmax=vmax)
def plot_singleProbability(probabilityArray, fsds, skip, channel=1, startInd=0, stopInd=None, smoothing=20, vmin=-0.2, vmax=1.2): windows, nchan = probabilityArray.shape if stopInd == None: stopInd = windows smoothing = smoothing w = int(smoothing * fsds / skip) mvgAvg = np.zeros(shape=(windows - w + 1, nchan)) for c in range(nchan): mvgAvg[:, c] = echobase.movingaverage(probabilityArray[:, c], w) y = mvgAvg[startInd:stopInd, channel] x = range(len(y)) y2 = -0.05 fig, ax = plt.subplots(1, 1, figsize=(10, 2), dpi=300) sns.lineplot(x=x, y=y, ci=None, ax=ax, alpha=0) interpolate = interp1d(np.array(x), np.array(x)) xnew = interpolate(np.arange(0, len(x) - 1, 1)) interpolate = interp1d(np.array(x), y) ynew = interpolate(np.arange(0, len(x) - 1, 1)) Z = np.linspace(0, 1, len(xnew)) normalize = colors.Normalize(vmin=vmin, vmax=vmax) cmap = plt.cm.get_cmap('Blues') df = pd.DataFrame({'x': xnew, 'y1': ynew, 'z': Z}) xcolor = df['x'].values y1color = df['y1'].values zcolor = df['z'].values for ii in range(len(df['x'].values) - 1): plt.fill_between(x=[xcolor[ii], xcolor[(ii + 1)]], y1=[y1color[ii], y1color[ii + 1]], y2=y2, color=cmap(normalize(zcolor[ii]))) ax.set(yticks=[]) ax.set(xticks=[]) ax.set_ylim([y2, 1]) sns.despine(bottom=True, left=True)
probWN = np.zeros(shape=(windows, len(c))) probCNN = np.zeros(shape=(windows, len(c))) probLSTM = np.zeros(shape=(windows, len(c))) for ch in range(len(c)): print(ch) ch_pred = data_scalerDSPlot_X[:, :, ch].reshape(windows, time_step, 1) probWN[:, ch] = modelWN.predict(ch_pred, verbose=1)[:, 1] probCNN[:, ch] = modelCNN.predict(ch_pred, verbose=1)[:, 1] probLSTM[:, ch] = modelLSTM.predict(ch_pred, verbose=1)[:, 1] smoothing = 20 w = int(smoothing * fsds / skip) mvgAvg = np.zeros(shape=(windows - w + 1, len(c))) for ch in range(len(c)): mvgAvg[:, ch] = echobase.movingaverage(probWN[:, ch], w) #Calculate Raw Features linelength, linelengthNorm = echobase.lineLengthOfArray(data_scalerDSPlot_X) #%% generate example EEG fnameFig = os.path.join(pathFigureOverview, "exampleEEGspread.png") DataJson.plot_eeg(data_scaler[int(ictalStartIndex - 1 * fs_plot):int(ictalStopIndex + 2 * fs_plot), c], fs_plot, nchan=None, dpi=300, aspect=30, height=0.5,
sns.heatmap(lineLength_arr.T, ax=ax[1, 0]) THRESHOLD_LL = 0.7 SMOOTHING = 20 #in seconds lineLength_arr_threshold = copy.deepcopy(lineLength_arr) lineLength_arr_threshold[lineLength_arr_threshold > THRESHOLD_LL] = 1 lineLength_arr_threshold[lineLength_arr_threshold <= THRESHOLD_LL] = 0 sns.heatmap(lineLength_arr_threshold.T, ax=ax[1, 1]) w = int(SMOOTHING * fsds / skip) lineLength_arr_movingAvg = np.zeros(shape=(windows - w + 1, nchan)) for c in range(nchan): lineLength_arr_movingAvg[:, c] = echobase.movingaverage( lineLength_arr[:, c], w) sns.heatmap(lineLength_arr_movingAvg.T, ax=ax[2, 0]) lineLength_arr_movingAvg_threshold = copy.deepcopy(lineLength_arr_movingAvg) lineLength_arr_movingAvg_threshold[ lineLength_arr_movingAvg_threshold > THRESHOLD_LL] = 1 lineLength_arr_movingAvg_threshold[ lineLength_arr_movingAvg_threshold <= THRESHOLD_LL] = 0 sns.heatmap(lineLength_arr_movingAvg_threshold.T, ax=ax[2, 1]) #sns.heatmap(SC, square=True) #sns.heatmap(SC_hat, square=True)