def hypothesisTest(sensor1, sensor2, vari): TD, WS1, CwS, HwS, Temp1, GTemp, WC, RH, HSI, DP, PWBTemp, SP, BP, Alt, DAlt, NAWBTemp, WBGT, TWL, MD = readdata( sensor1) TD, WS2, CwS, HwS, Temp2, GTemp, WC, RH, HSI, DP, PWBTemp, SP, BP, Alt, DAlt, NAWBTemp, WBGT, TWL, MD = readdata( sensor2) if vari == 'T': A = Temp1 B = Temp2 elif vari == 'WS': A = WS1 B = WS2 t, p = stats.ttest_ind(A, B) t = abs(t) if vari == 'T': print('t(Temperature) =', t) print('p-value(Temperature) =', p) elif vari == 'WS': print('t(Wind speed) =', t) print('p-value(Wind speed) =', p)
def plotScatter(A,B,C,D,E,vari): TD, WS, CwSA, HwSA, TempA, GTemp, WC, RH, HSI, DP, PWBTempA, SP, BP, Alt, DAlt, NAWBTemp, WBGTA, TWL, MD = readdata(A) TD, WS, CwSB, HwSB, TempB, GTemp, WC, RH, HSI, DP, PWBTempB, SP, BP, Alt, DAlt, NAWBTemp, WBGTB, TWL, MD = readdata(B) TD, WS, CwSC, HwSC, TempC, GTemp, WC, RH, HSI, DP, PWBTempC, SP, BP, Alt, DAlt, NAWBTemp, WBGTC, TWL, MD = readdata(C) TD, WS, CwSD, HwSD, TempD, GTemp, WC, RH, HSI, DP, PWBTempD, SP, BP, Alt, DAlt, NAWBTemp, WBGTD, TWL, MD = readdata(D) TD, WS, CwSE, HwSE, TempE, GTemp, WC, RH, HSI, DP, PWBTempE, SP, BP, Alt, DAlt, NAWBTemp, WBGTE, TWL, MD = readdata(E) if vari == 'T': D = [TempA,TempB,TempC,TempD,TempE] elif vari == 'WBGT': D = [WBGTA,WBGTB,WBGTC,WBGTD,WBGTE] elif vari == 'CwS': D = [CwSA,CwSB,CwSC,CwSD,CwSD,CwSE] fig = plt.figure(figsize=(14,5)) ax1 = plt.subplot(251) ax2 = plt.subplot(252) ax3 = plt.subplot(253) ax4 = plt.subplot(254) ax5 = plt.subplot(255) ax6 = plt.subplot(256) ax7 = plt.subplot(257) ax8 = plt.subplot(258) ax9 = plt.subplot(259) ax10 = plt.subplot(2,5,10) axes = [ax1,ax2,ax3,ax4,ax5,ax6,ax7,ax8,ax9,ax10] X = ['A','B','C','D','E'] a = 0 if vari == 'T': vname = 'Temperature' elif vari == 'WBGT': vname = 'WBGT' elif vari == 'CwS': vname = 'Crosswind Speed' #fig.suptitle('Scatter plots of ' + vname + ' values between sensors') for i in range(5): for j in range(i+1,5): dat = pScatter(D[i],D[j]) axes[a].scatter(dat,D[j],c='b',s=0.2) axes[a].set_xlabel(vname + "(Sensor "+X[i]+")") axes[a].set_ylabel(vname + "(Sensor " + X[j] + ")") a = a+1 plt.tight_layout() plt.show()
def calcCi(A, B, C, D, E, vari): TD, WSA, CwS, HwS, TempA, GTemp, WC, RH, HSI, DP, PWBTemp, SP, BP, Alt, DAlt, NAWBTemp, WBGT, TWL, MD = readdata( A) TD, WSB, CwS, HwS, TempB, GTemp, WC, RH, HSI, DP, PWBTemp, SP, BP, Alt, DAlt, NAWBTemp, WBGT, TWL, MD = readdata( B) TD, WSC, CwS, HwS, TempC, GTemp, WC, RH, HSI, DP, PWBTemp, SP, BP, Alt, DAlt, NAWBTemp, WBGT, TWL, MD = readdata( C) TD, WSD, CwS, HwS, TempD, GTemp, WC, RH, HSI, DP, PWBTemp, SP, BP, Alt, DAlt, NAWBTemp, WBGT, TWL, MD = readdata( D) TD, WSE, CwS, HwS, TempE, GTemp, WC, RH, HSI, DP, PWBTemp, SP, BP, Alt, DAlt, NAWBTemp, WBGT, TWL, MD = readdata( E) if vari == 'T': A = [TempA, TempB, TempC, TempD, TempE] print('For Temperature:') if vari == 'WS': A = [WSA, WSB, WSC, WSD, WSE] print('For Windspeed:') sensor_list = ['A', 'B', 'C', 'D', 'E'] lower_list = [] upper_list = [] for i in range(5): mu, sigma = np.mean(A[i]), np.std(A[i]) size = len(A[i]) lower, upper = scipy.stats.t.interval(0.95, size - 1, mu, sigma) lower_list.append(lower) upper_list.append(upper) intervals_list = pd.DataFrame([sensor_list, lower_list, upper_list]).transpose() intervals_list.columns = ['Sensor', 'Lower boundary', 'Upper boundary'] print(intervals_list)
def showCorrelation(A,B,C,D,E,vari): TD, WS, CwSA, HwSA, TempA, GTemp, WC, RH, HSI, DP, PWBTempA, SP, BP, Alt, DAlt, NAWBTemp, WBGTA, TWL, MD = readdata(A) TD, WS, CwSB, HwSB, TempB, GTemp, WC, RH, HSI, DP, PWBTempB, SP, BP, Alt, DAlt, NAWBTemp, WBGTB, TWL, MD = readdata(B) TD, WS, CwSC, HwSC, TempC, GTemp, WC, RH, HSI, DP, PWBTempC, SP, BP, Alt, DAlt, NAWBTemp, WBGTC, TWL, MD = readdata(C) TD, WS, CwSD, HwSD, TempD, GTemp, WC, RH, HSI, DP, PWBTempD, SP, BP, Alt, DAlt, NAWBTemp, WBGTD, TWL, MD = readdata(D) TD, WS, CwSE, HwSE, TempE, GTemp, WC, RH, HSI, DP, PWBTempE, SP, BP, Alt, DAlt, NAWBTemp, WBGTE, TWL, MD = readdata(E) if vari == 'T': D = [TempA,TempB,TempC,TempD,TempE] elif vari == 'WBGT': D = [WBGTA,WBGTB,WBGTC,WBGTD,WBGTE] elif vari == 'CwS': D = [CwSA,CwSB,CwSC,CwSD,CwSD,CwSE] a = np.zeros((5,5)) b = np.zeros((5,5)) c = np.zeros((5,5)) d = np.zeros((5,5)) for i in range(5): for j in range(5): a[i][j],b[i][j],c[i][j],d[i][j] = calcCorrelation(D[i],D[j]) if vari == 'T': B = 'Temperature' elif vari == 'WBGT': B = 'Wet Bulb Globe Temperature' elif vari == 'CwS': B = 'Crosswind Speed' print("\nPearson's coefficients for",B) print(a) print("\nSpearmann's coefficients for",B) print(b)
def plotCdf(A, B, C, D, E, vari, n): TD, WSA, CwS, HwS, TempA, GTemp, WC, RH, HSI, DP, PWBTemp, SP, BP, Alt, DAlt, NAWBTemp, WBGT, TWL, MD = readdata( A) TD, WSB, CwS, HwS, TempB, GTemp, WC, RH, HSI, DP, PWBTemp, SP, BP, Alt, DAlt, NAWBTemp, WBGT, TWL, MD = readdata( B) TD, WSC, CwS, HwS, TempC, GTemp, WC, RH, HSI, DP, PWBTemp, SP, BP, Alt, DAlt, NAWBTemp, WBGT, TWL, MD = readdata( C) TD, WSD, CwS, HwS, TempD, GTemp, WC, RH, HSI, DP, PWBTemp, SP, BP, Alt, DAlt, NAWBTemp, WBGT, TWL, MD = readdata( D) TD, WSE, CwS, HwS, TempE, GTemp, WC, RH, HSI, DP, PWBTemp, SP, BP, Alt, DAlt, NAWBTemp, WBGT, TWL, MD = readdata( E) fig = plt.figure(figsize=(14, 5)) ax1 = fig.add_subplot(111) if vari == 'T': a1 = ax1.hist(x=TempA, bins=n, cumulative=1, density=1, color='w', alpha=0.7, rwidth=0.85, histtype='barstacked') a2 = ax1.hist(x=TempB, bins=n, cumulative=1, density=1, color='w', alpha=0.7, rwidth=0.85, histtype='barstacked') a3 = ax1.hist(x=TempC, bins=n, cumulative=1, density=1, color='w', alpha=0.7, rwidth=0.85, histtype='barstacked') a4 = ax1.hist(x=TempD, bins=n, cumulative=1, density=1, color='w', alpha=0.7, rwidth=0.85, histtype='barstacked') a5 = ax1.hist(x=TempE, bins=n, cumulative=1, density=1, color='w', alpha=0.7, rwidth=0.85, histtype='barstacked') if vari == 'WS': a1 = ax1.hist(x=WSA, bins=n, cumulative=1, density=1, color='w', alpha=0.7, rwidth=0.85, histtype='barstacked') a2 = ax1.hist(x=WSB, bins=n, cumulative=1, density=1, color='w', alpha=0.7, rwidth=0.85, histtype='barstacked') a3 = ax1.hist(x=WSC, bins=n, cumulative=1, density=1, color='w', alpha=0.7, rwidth=0.85, histtype='barstacked') a4 = ax1.hist(x=WSD, bins=n, cumulative=1, density=1, color='w', alpha=0.7, rwidth=0.85, histtype='barstacked') a5 = ax1.hist(x=WSE, bins=n, cumulative=1, density=1, color='w', alpha=0.7, rwidth=0.85, histtype='barstacked') ax1.plot(a1[1][1:] - (a1[1][1:] - a1[1][:-1]) / 2, a1[0], label='Sensor A') ax1.plot(a2[1][1:] - (a2[1][1:] - a2[1][:-1]) / 2, a2[0], label='Sensor B') ax1.plot(a3[1][1:] - (a3[1][1:] - a3[1][:-1]) / 2, a3[0], label='Sensor C') ax1.plot(a4[1][1:] - (a4[1][1:] - a4[1][:-1]) / 2, a4[0], label='Sensor D') ax1.plot(a5[1][1:] - (a5[1][1:] - a5[1][:-1]) / 2, a5[0], label='Sensor E') plt.ylabel('Cumulative Density') if vari == 'T': plt.xlabel('Temperature [\N{DEGREE SIGN}C]') #plt.title('CDFs for the 5 sensors Temperature values') if vari == 'WS': plt.xlabel('Windspeed [m/s]') #plt.title('CDFs for the 5 sensors Windspeed values') plt.legend(loc='best') plt.tight_layout() plt.show()
def plotWSPdfkde(A, B, C, D, E, n): TD, WSA, CwS, HwS, TempA, GTemp, WC, RH, HSI, DP, PWBTemp, SP, BP, Alt, DAlt, NAWBTemp, WBGT, TWL, MD = readdata( A) TD, WSB, CwS, HwS, TempB, GTemp, WC, RH, HSI, DP, PWBTemp, SP, BP, Alt, DAlt, NAWBTemp, WBGT, TWL, MD = readdata( B) TD, WSC, CwS, HwS, TempC, GTemp, WC, RH, HSI, DP, PWBTemp, SP, BP, Alt, DAlt, NAWBTemp, WBGT, TWL, MD = readdata( C) TD, WSD, CwS, HwS, TempD, GTemp, WC, RH, HSI, DP, PWBTemp, SP, BP, Alt, DAlt, NAWBTemp, WBGT, TWL, MD = readdata( D) TD, WSE, CwS, HwS, TempE, GTemp, WC, RH, HSI, DP, PWBTemp, SP, BP, Alt, DAlt, NAWBTemp, WBGT, TWL, MD = readdata( E) ax1 = plt.subplot(231) ax2 = plt.subplot(232) ax3 = plt.subplot(233) ax4 = plt.subplot(234) ax5 = plt.subplot(235) ax1.hist(x=WSA, bins=n, density=True, histtype='step', label='PDF') ax1.set_xlabel('Sensor A') ax2.hist(x=WSB, bins=n, density=True, histtype='step', label='PDF') ax2.set_xlabel('Sensor B') ax3.hist(x=WSC, bins=n, density=True, histtype='step', label='PDF') ax3.set_xlabel('Sensor C') ax4.hist(x=WSD, bins=n, density=True, histtype='step', label='PDF') ax4.set_xlabel('Sensor D') ax5.hist(x=WSE, bins=n, density=True, histtype='step', label='PDF') ax5.set_xlabel('Sensor E') sns.kdeplot(WSA, color='springgreen', ax=ax1, label="KDE") sns.kdeplot(WSB, color='springgreen', ax=ax2, label="KDE") sns.kdeplot(WSC, color='springgreen', ax=ax3, label="KDE") sns.kdeplot(WSD, color='springgreen', ax=ax4, label="KDE") sns.kdeplot(WSE, color='springgreen', ax=ax5, label="KDE") plt.legend(loc='lower left', bbox_to_anchor=(1.5, 0)) #plt.suptitle('PDFs and the kernel density estimation for the 5 sensors Wind Speed values', ) plt.subplots_adjust(wspace=0.3) plt.subplots_adjust(hspace=0.5) plt.show()
def plotPdf(A, B, C, D, E): TD, WS, CwS, HwS, TempA, GTemp, WC, RH, HSI, DP, PWBTemp, SP, BP, Alt, DAlt, NAWBTemp, WBGT, TWL, MD = readdata( A) TD, WS, CwS, HwS, TempB, GTemp, WC, RH, HSI, DP, PWBTemp, SP, BP, Alt, DAlt, NAWBTemp, WBGT, TWL, MD = readdata( B) TD, WS, CwS, HwS, TempC, GTemp, WC, RH, HSI, DP, PWBTemp, SP, BP, Alt, DAlt, NAWBTemp, WBGT, TWL, MD = readdata( C) TD, WS, CwS, HwS, TempD, GTemp, WC, RH, HSI, DP, PWBTemp, SP, BP, Alt, DAlt, NAWBTemp, WBGT, TWL, MD = readdata( D) TD, WS, CwS, HwS, TempE, GTemp, WC, RH, HSI, DP, PWBTemp, SP, BP, Alt, DAlt, NAWBTemp, WBGT, TWL, MD = readdata( E) mu1, sigma1 = np.mean(TempA), np.std(TempA) mu2, sigma2 = np.mean(TempB), np.std(TempB) mu3, sigma3 = np.mean(TempC), np.std(TempC) mu4, sigma4 = np.mean(TempD), np.std(TempD) mu5, sigma5 = np.mean(TempE), np.std(TempE) x1 = np.linspace(mu1 - 4 * sigma1, mu1 + 4 * sigma1, 100) x2 = np.linspace(mu2 - 4 * sigma2, mu2 + 4 * sigma2, 100) x3 = np.linspace(mu3 - 4 * sigma3, mu3 + 4 * sigma3, 100) x4 = np.linspace(mu4 - 4 * sigma4, mu4 + 4 * sigma4, 100) x5 = np.linspace(mu5 - 4 * sigma5, mu5 + 4 * sigma5, 100) plt.figure(figsize=(14, 5)) plt.plot(x1, stats.norm.pdf(x1, mu1, sigma1), label='Sensor A') plt.plot(x2, stats.norm.pdf(x2, mu2, sigma2), label='Sensor B') plt.plot(x3, stats.norm.pdf(x3, mu3, sigma3), label='Sensor C') plt.plot(x4, stats.norm.pdf(x4, mu4, sigma4), label='Sensor D') plt.plot(x5, stats.norm.pdf(x5, mu5, sigma5), label='Sensor E') plt.ylabel('Probability Density') plt.xlabel('Temperature [\N{DEGREE SIGN}C]') #plt.title('PDFs for the 5 sensors Temperature values') plt.ylim(ymin=0) plt.legend(loc='best') plt.show()
def plotPmf(A, B, C, D, E, n): TD, WS, CwS, HwS, TempA, GTemp, WC, RH, HSI, DP, PWBTemp, SP, BP, Alt, DAlt, NAWBTemp, WBGT, TWL, MD = readdata( A) TD, WS, CwS, HwS, TempB, GTemp, WC, RH, HSI, DP, PWBTemp, SP, BP, Alt, DAlt, NAWBTemp, WBGT, TWL, MD = readdata( B) TD, WS, CwS, HwS, TempC, GTemp, WC, RH, HSI, DP, PWBTemp, SP, BP, Alt, DAlt, NAWBTemp, WBGT, TWL, MD = readdata( C) TD, WS, CwS, HwS, TempD, GTemp, WC, RH, HSI, DP, PWBTemp, SP, BP, Alt, DAlt, NAWBTemp, WBGT, TWL, MD = readdata( D) TD, WS, CwS, HwS, TempE, GTemp, WC, RH, HSI, DP, PWBTemp, SP, BP, Alt, DAlt, NAWBTemp, WBGT, TWL, MD = readdata( E) fig = plt.figure(figsize=(14, 5)) ax1 = fig.add_subplot(231) ax2 = fig.add_subplot(232) ax3 = fig.add_subplot(233) ax4 = fig.add_subplot(234) ax5 = fig.add_subplot(235) weights = np.ones_like(TempE) / float(len(TempE)) ax1.hist(x=TempA, bins=n, density=True, color='b', histtype='step') ax1.set_ylabel('Probability') ax1.set_xlabel('Temperature [\N{DEGREE SIGN}C]\nSensor A') ax2.hist(x=TempB, bins=n, density=True, color='b', histtype='step') ax2.set_ylabel('Probability') ax2.set_xlabel('Temperature [\N{DEGREE SIGN}C]\nSensor B') ax3.hist(x=TempC, bins=n, density=True, color='b', histtype='step') ax3.set_ylabel('Probability') ax3.set_xlabel('Temperature [\N{DEGREE SIGN}C]\nSensor C') ax4.hist(x=TempD, bins=n, density=True, color='b', histtype='step') ax4.set_ylabel('Probability') ax4.set_xlabel('Temperature [\N{DEGREE SIGN}C]\nSensor D') ax5.hist(x=TempE, bins=n, density=True, color='b', histtype='step', weights=weights) ax5.set_ylabel('Probability') ax5.set_xlabel('Temperature [\N{DEGREE SIGN}C]\nSensor E') #fig.suptitle('PMFs for the 5 sensors Temperature values',) plt.subplots_adjust(wspace=0.5) plt.subplots_adjust(hspace=0.5) plt.show()