def coh_palm(p0_ind, p1_ind, t_para, tSeq, varSeq, tL): t_start = t_para[0] t_end = t_para[1] t_delta = t_para[2] fs = 1 / t_delta # sampling frequency t_num = int((t_end - t_start) / t_delta + 1) t_seq = np.linspace(t_start, t_end, t_num) u0 = varSeq[:, p0_ind[2], p0_ind[1], p0_ind[0]] u1 = varSeq[:, p1_ind[2], p1_ind[1], p1_ind[0]] f0 = interp1d(tSeq, u0, kind='linear', fill_value='extrapolate') f1 = interp1d(tSeq, u1, kind='linear', fill_value='extrapolate') u0_ = f0(t_seq) u1_ = f1(t_seq) segNum = tL * fs freq, coh, co_coh, phase = funcs.coherence(u0_, u1_, fs, segNum) return t_seq, u0_, u1_, freq, coh, co_coh, phase
def coh_sowfa(p0_ind, p1_ind, xNum, yNum, t_para, tSeq, varSeq, tL): """ Calculate coherence, co-coherence, phase based on interpolated data INPUT p0_ind: indice of the probe0 p1_ind: indice of the probe1 xNum: length of xSeq yNum: length of ySeq t_para: parameters of the interpolated time array, tuple, (start time, end time, time step) tSeq: original time array varSeq: variable array tL: length of subsegment (s) OUTPUT t_seq: interpolated time array u0_: 1st velocity array u1_: 2nd velocity array freq: frequency array coh: coherence array co_coh: co-coh array quad_coh: quad-coh array phase: phase array """ p0_id = p0_ind[2] * xNum * yNum + p0_ind[1] * xNum + p0_ind[0] p1_id = p1_ind[2] * xNum * yNum + p1_ind[1] * xNum + p1_ind[0] t_start = t_para[0] t_end = t_para[1] t_delta = t_para[2] fs = 1 / t_delta # sampling frequency t_num = int((t_end - t_start) / t_delta + 1) t_seq = np.linspace(t_start, t_end, t_num) u0 = varSeq[p0_id] u1 = varSeq[p1_id] f0 = interp1d(tSeq, u0, kind='linear', fill_value='extrapolate') f1 = interp1d(tSeq, u1, kind='linear', fill_value='extrapolate') u0_ = f0(t_seq) u1_ = f1(t_seq) segNum = tL * fs freq, coh, co_coh, quad_coh, phase = funcs.coherence(u0_, u1_, fs, segNum) return t_seq, u0_, u1_, freq, coh, co_coh, quad_coh, phase
def coh_sowfa(p0_ind, p1_ind, xNum, yNum, t_para, tSeq, varSeq, tL): p0_id = p0_ind[2] * xNum * yNum + p0_ind[1] * xNum + p0_ind[0] p1_id = p1_ind[2] * xNum * yNum + p1_ind[1] * xNum + p1_ind[0] t_start = t_para[0] t_end = t_para[1] t_delta = t_para[2] fs = 1 / t_delta # sampling frequency t_num = int((t_end - t_start) / t_delta + 1) t_seq = np.linspace(t_start, t_end, t_num) u0 = varSeq[p0_id] u1 = varSeq[p1_id] f0 = interp1d(tSeq, u0, kind='linear', fill_value='extrapolate') f1 = interp1d(tSeq, u1, kind='linear', fill_value='extrapolate') u0_ = f0(t_seq) u1_ = f1(t_seq) segNum = tL * fs # freq, coh, co_coh, phase = funcs.coherence(u0_, u1_, fs, segNum) tmp = funcs.coherence(u0_, u1_, fs, segNum) return t_seq, u0_, u1_, tmp[0], tmp[1], tmp[2], tmp[4]
coh = [] yInd = yInd_start while yInd <= yInd_end: coh_temp = [] xInd0 = xInd_start xInd1 = xInd0 + dInd while xInd1 < xNum: u0 = data_org['u'][:, yInd, xInd0] u1 = data_org['u'][:, yInd, xInd1] # time interpolation f0 = interp1d(tSeq, u0, kind='cubic', fill_value='extrapolate') f1 = interp1d(tSeq, u1, kind='cubic', fill_value='extrapolate') u0 = f0(t_seq) u1 = f1(t_seq) # calculate coherence and phase freq, coh_, phase_ = funcs.coherence(u0, u1, fs, segNum) coh_temp.append(coh_) xInd0 += 1 xInd1 += 1 coh_temp = sum(coh_temp) / len(coh_temp) coh.append(coh_temp) yInd += 1 coh = sum(coh) / len(coh) cohList.append(coh)
ax.text(0.56, 1.02, 'dx = ' + str(np.round(dx, 1)) + 'm' + ', ' + 'h = ' + str(np.round(p0_coor[2])) + 'm', transform=ax.transAxes, fontsize=12) plt.grid() plt.legend() saveName = 'u_ts_120' + '_dx_' + str(np.round(dx, 1)) + '_h_' + str( np.round(p0_coor[2])) + '_pr.png' plt.savefig(ppDir + '/' + saveName) plt.show() plt.close() # calculate coherence and phase_ freq, coh, co_coh, phase = funcs.coherence(u0, u1, fs, segNum) def fitting_func(x, a, alpha): return a * np.exp(-alpha * x) """ plot coherence """ f_out = 0.15 tmp = abs(freq - f_out) ind_in, ind_out = 1, np.where(tmp == tmp.min())[0][0] fig, ax = plt.subplots(figsize=(6, 6)) ax.plot(freq, coh, linestyle='', marker='x', markersize=3, color='k') popt, pcov = curve_fit(fitting_func, freq[ind_in:ind_out],
1.02, 'dx = ' + str(np.round(dx, 1)) + 'm' + ', ' + 'h = ' + str(np.round(p0_coor[2])) + 'm', transform=ax.transAxes, fontsize=12) plt.grid() plt.legend() saveName = 'u_ts_120' + '_dx_' + str(np.round(dx, 1)) + '_h_' + str( np.round(p0_coor[2])) + '_pr.png' plt.savefig(ppDir + '/' + saveName) plt.show() plt.close() segNum = 120 * fs # calculate coherence and phase freq, coh01, co_coh01, phase01 = funcs.coherence(u0, u1, fs, segNum) freq, coh02, co_coh02, phase02 = funcs.coherence(u0, u2, fs, segNum) freq, coh03, co_coh03, phase03 = funcs.coherence(u0, u3, fs, segNum) """ plot coherence and fitting curve """ def fitting_func(x, a, alpha): return a * np.exp(-alpha * x) f_out = 1 tmp = abs(freq - f_out) ind_in, ind_out = 1, np.where(tmp == tmp.min())[0][0] # dx = 40m fig, ax = plt.subplots(figsize=(6, 4))