def plot_scatter(est, ref): import matplotlib.pyplot as plt from scipy import stats maske = ~np.isnan(est) & ~np.isnan(ref) slope, intercept, r_value, p_value, std_err = stats.linregress(est[maske], ref[maske]) line = slope * est +intercept from pcc import skill_score SS = skill_score(est,ref,th=0) plt.scatter(est, ref, label='Reflectivity [dBZ]', color='grey', alpha=0.6) text = ('f(x) = ' + str(round(slope,3)) + 'x + ' + str(round(intercept,3)) + '\nCorr: ' + str(round(r_value,3)) + r'$\pm$: '+ str(round(std_err,3))+ '\nN: '+ str(int(SS['N']))+ '\nHit: ' + str(round(SS['H']/SS['N'],3)*100)+'%'+ '\nMiss: ' + str(round(SS['M']/SS['N'],3)*100)+'%'+ '\nFalse: ' + str(round(SS['F']/SS['N'],3)*100)+'%'+ '\nCnegative: ' + str(round(SS['C']/SS['N'],3)*100)+'%'+ '\nHR: ' + str(round(SS['HR'],3))+ '\nPOD: ' + str(round(SS['POD'],3))+ '\nFAR: ' + str(round(SS['FAR'],3))+ '\nBID: ' + str(round(SS['BID'],3))+ '\nHSS: ' + str(round(SS['HSS'],3))+ '\nBias: '+ str(round(SS['bias'],3))+ '\nRMSE: '+ str(round(SS['RMSE'],3)) ) plt.annotate(text, xy=(0.01, 0.99), xycoords='axes fraction', fontsize=10, horizontalalignment='left', verticalalignment='top') t1 = np.linspace(0,70,70) plt.plot(t1,t1,'k-') plt.plot(t1, t1*slope + intercept, 'r-', lw=3 ,label='Regression') plt.plot(t1, t1*slope + (intercept+5), 'r-.', lw=1.5 ,label=r'Reg $\pm$ 5 mdBZ') plt.plot(t1, t1*slope + (intercept-5), 'r-.', lw=1.5 ) plt.plot(np.nanmean(est),np.nanmean(ref), 'ob', lw = 4,label='Mean') plt.legend(loc='lower right', fontsize=10, scatterpoints= 1, numpoints=1, shadow=True) plt.xlim(0,70) plt.ylim(0,70)
A = np.copy(rrr) B = np.ma.masked_invalid(gprof_pp_b) #A[A<TH_rain] = 18 #B[B<TH_rain] = 18 ref = np.copy(rrr) est = np.ma.masked_invalid(gprof_pp_b) mask = ~np.isnan(B) & ~np.isnan(A) slope, intercept, r_value, p_value, std_err = stats.linregress( B[mask], A[mask]) line = slope * B + intercept from pcc import skill_score RR = skill_score(est, ref, 0.001) from pcc import plot_score plot_score(est, ref, RR) #plt.scatter(B[mask],A[mask], label='RR [mm/h]') plt.plot(B, line, 'r-') #maxAB = np.nanmax([np.nanmax(A[mask]),np.nanmax(B[mask])]) #plt.xlim(0,maxAB + 1) #plt.ylim(0,maxAB + 1) plt.legend(loc='upper center', bbox_to_anchor=(0.5, 1.1), ncol=2, fancybox=True, shadow=True, fontsize='small', title="Slope: " + str(round(slope, 3)) + ', Intercept: ' +
top='off', labelbottom='off', right='off', left='off', labelleft='off') plt.xlim(-420,390) plt.ylim(-4700, -3700) ax4 = fig.add_subplot(224, aspect='equal')#------------------------------------ maske = ~np.isnan(ggg) & ~np.isnan(rrr) slope, intercept, r_value, p_value, std_err = stats.linregress(ggg[maske], rrr[maske]) line = slope * ggg +intercept from pcc import skill_score SS = skill_score(ggg,rrr,th=0) plt.scatter(ggg, rrr, label='RR [mm/h]', color='grey', alpha=0.6) text = ('f(x) = ' + str(round(slope,3)) + 'x + ' + str(round(intercept,3)) + '\nCorr: ' + str(round(r_value,3)) + r'$\pm$: '+ str(round(std_err,3))+ '\nN: '+ str(int(SS['N']))+ '\nHit: ' + str(SS['H'])+ '\nMiss: ' + str(SS['M'])+ '\nFalse: ' + str(SS['F'])+ '\nCnegative: ' + str(SS['C'])+ '\nHR: ' + str(round(SS['HR'],3))+ '\nPOD: ' + str(round(SS['POD'],3))+ '\nFAR: ' + str(round(SS['FAR'],3))+ '\nBID: ' + str(round(SS['BID'],3))+ '\nHSS: ' + str(round(SS['HSS'],3))+
labelbottom='off', right='off', left='off', labelleft='off') plt.xlim(-420, 390) plt.ylim(-4700, -3700) ax4 = fig.add_subplot( 224, aspect='equal') #------------------------------------ try: maske = ~np.isnan(ggg) & ~np.isnan(rrr) slope, intercept, r_value, p_value, std_err = stats.linregress( ggg[maske], rrr[maske]) SS = skill_score(ggg, rrr, th=TH_ref) ax4.scatter(ggg, rrr, label='Reflectivity [dBZ]', color='grey', alpha=0.6) r_value_s, p_value_s = stats.spearmanr(ggg[maske], rrr[maske]) text = ('f(x) = ' + str(round(slope, 3)) + 'x + ' + str(round(intercept, 3)) + '\nCorr: ' + str(round(r_value, 3)) + r'$\pm$ ' + str(round(std_err, 3)) + '\nN: ' + str(int(SS['N'])) + '\nHit: ' + str(SS['H']) + '\nMiss: ' + str(SS['M']) + '\nFalse: ' + str(SS['F']) + '\nCnegative: ' +
labelbottom='off', right='off', left='off', labelleft='off') plt.xlim(-420,390) plt.ylim(-4700, -3700) ax4 = fig.add_subplot(224, aspect='equal')#------------------------------------ maske = ~np.isnan(ggg) & ~np.isnan(rrr) slope, intercept, r_value, p_value, std_err = stats.linregress(ggg[maske], rrr[maske]) line = slope * ggg +intercept from pcc import skill_score SS = skill_score(ggg,rrr,th=TH_ref) ax4.scatter(ggg, rrr, label='Reflectivity [dBZ]', color='grey', alpha=0.6) r_value_s, p_value_s = stats.spearmanr(ggg[maske],rrr[maske]) text = ('f(x) = ' + str(round(slope,3)) + 'x + ' + str(round(intercept,3)) + '\nCorr: ' + str(round(r_value,3)) + r'$\pm$: '+ str(round(std_err,3))+ '\nN: '+ str(int(SS['N']))+ '\nHit: ' + str(SS['H'])+ '\nMiss: ' + str(SS['M'])+ '\nFalse: ' + str(SS['F'])+ '\nCnegative: ' + str(SS['C'])+ '\nHR: ' + str(round(SS['HR'],3))+ '\nPOD: ' + str(round(SS['POD'],3))+ '\nFAR: ' + str(round(SS['FAR'],3))+
A = np.copy(rrr) B = np.ma.masked_invalid(gprof_pp_b) #A[A<TH_rain] = 18 #B[B<TH_rain] = 18 ref = np.copy(rrr) est = np.ma.masked_invalid(gprof_pp_b) mask = ~np.isnan(B) & ~np.isnan(A) slope, intercept, r_value, p_value, std_err = stats.linregress(B[mask], A[mask]) line = slope*B+intercept from pcc import skill_score RR = skill_score(est,ref,0.001) from pcc import plot_score plot_score(est,ref,RR) #plt.scatter(B[mask],A[mask], label='RR [mm/h]') plt.plot(B,line,'r-') #maxAB = np.nanmax([np.nanmax(A[mask]),np.nanmax(B[mask])]) #plt.xlim(0,maxAB + 1) #plt.ylim(0,maxAB + 1) plt.legend(loc='upper center', bbox_to_anchor=(0.5, 1.1), ncol=2, fancybox=True, shadow=True, fontsize='small', title= "Slope: " + str(round(slope,3)) + ', Intercept: '+ str(round(intercept,3)) + "\n Correlation: " + str(round(r_value,3)) + ', Std_err: '+ str(round(std_err,3))) plt.xlabel("DPR Ref [dbz]") plt.ylabel("RADOLAN Ref [dbz]") plt.title(" .")
right='off', left='off', labelleft='off') plt.xlim(-420, 390) plt.ylim(-4700, -3700) ax4 = fig.add_subplot( 224, aspect='equal') #------------------------------------ maske = ~np.isnan(ggg) & ~np.isnan(rrr) slope, intercept, r_value, p_value, std_err = stats.linregress( ggg[maske], rrr[maske]) line = slope * ggg + intercept from pcc import skill_score SS = skill_score(ggg, rrr, th=0) plt.scatter(ggg, rrr, label='RR [mm/h]', color='grey', alpha=0.6) text = ('f(x) = ' + str(round(slope, 3)) + 'x + ' + str(round(intercept, 3)) + '\nCorr: ' + str(round(r_value, 3)) + r'$\pm$: ' + str(round(std_err, 3)) + '\nN: ' + str(int(SS['N'])) + '\nHit: ' + str(SS['H']) + '\nMiss: ' + str(SS['M']) + '\nFalse: ' + str(SS['F']) + '\nCnegative: ' + str(SS['C']) + '\nHR: ' + str(round(SS['HR'], 3)) + '\nPOD: ' + str(round(SS['POD'], 3)) + '\nFAR: ' + str(round(SS['FAR'], 3)) + '\nBID: ' + str(round(SS['BID'], 3)) + '\nHSS: ' + str(round(SS['HSS'], 3)) + '\nBias: ' + str(round(SS['bias'], 3)) + '\nRMSE: ' + str(round(SS['RMSE'], 3))) ax4.annotate(text,
def validation_plot_log(data1, data2, th_ss): """ Function: Plot for the validation of two datasets Input: data1, data2 ::: Input Data Output: Validation PLot """ # Todo: Schoener machen! #mini = np.nanmin([np.nanmin(data1), np.nanmin(data2)]) - 5.0 mini = 0.0 maxi = np.nanmax([np.nanmax(data1), np.nanmax(data2)]) + 5.0 print 'LIMITS: ', mini, maxi cd1 = 'blue' cd2 = 'green' from scipy import stats, linspace fig = plt.figure(figsize=(14,14)) ax1 = fig.add_subplot(223, aspect='auto')#--------------------------------------------------------------- maske = ~np.isnan(data1) & ~np.isnan(data2) slope, intercept, r_value, p_value, std_err = stats.linregress(data1[maske], data2[maske]) line = slope * data1 +intercept slope2, intercept2, r_value2, p_value2, std_err2 = stats.linregress(data2[maske], data1[maske]) line2 = slope2 * data2 +intercept2 from pcc import skill_score SS = skill_score(data1,data2,th=th_ss) ax1.scatter(data1, data2, label='RR in mm/h', color='grey', alpha=0.6) #plt.boxplot(data1[maske],vert=0) #plt.boxplot(data2[maske],vert=1) plt.yscale('log') plt.xscale('log') r_value_s, p_value_s = stats.spearmanr(data1[maske],data2[maske]) text = ('f(x) = ' + str(round(slope,3)) + 'x + ' + str(round(intercept,3)) + '\nCorr: ' + str(round(r_value,3)) + r'$\pm$: '+ str(round(std_err,3))+ '\nN: '+ str(int(SS['N']))+ '\nHit: ' + str(SS['H'])+ '\nMiss: ' + str(SS['M'])+ '\nFalse: ' + str(SS['F'])+ '\nCnegative: ' + str(SS['C'])+ '\nHR: ' + str(round(SS['HR'],3))+ '\nPOD: ' + str(round(SS['POD'],3))+ '\nFAR: ' + str(round(SS['FAR'],3))+ '\nBID: ' + str(round(SS['BID'],3))+ '\nHSS: ' + str(round(SS['HSS'],3))+ '\nBias: '+ str(round(SS['bias'],3))+ '\nRMSE: '+ str(round(SS['RMSE'],3))+ '\nCorrS:' + str(round(r_value_s,3)) ) ax1.annotate(text, xy=(0.01, 0.99), xycoords='axes fraction', fontsize=10, horizontalalignment='left', verticalalignment='top') #t1 = linspace(0,50,5000) t1=10 ** np.linspace(np.log10(10**-2), np.log10(10**2), 5000) plt.plot(t1,t1,'k-') #plt.plot(np.log10(t1),np.log10(t1),'k-') #plt.plot(t1,t1*slope+intercept,label='RADOLAN', color='green', lw=1.5, alpha=0.5) #plt.plot(t1*slope2+intercept2,t1,label='GPM', color='blue', lw=1.5, alpha=0.5) plt.legend(loc='lower right', fontsize=10, scatterpoints= 1, numpoints=1, shadow=True) #plt.xlim(mini,maxi) #plt.ylim(mini,maxi) plt.xlim(10**-2,10**2) plt.ylim(10**-2,10**2) plt.xlabel('GPM DPR') plt.ylabel('RADOLAN') plt.grid() ax2 = fig.add_subplot(221, aspect='auto')#----------------------------------------------------------------------------- st = 50 counts1, bins1, patches1 = plt.hist(data1[maske], bins=10 ** np.linspace(np.log10(10**-2), np.log10(10**2), st), alpha=0.5, color=cd2, label='GPM DPR') plt.yscale('log') plt.xscale('log') counts2, bins2, patches2 =plt.hist(data2[maske], bins=10 ** np.linspace(np.log10(10**-2), np.log10(10**2), st), alpha=0.9, edgecolor='black', facecolor="None", label='RADOLAN') plt.yscale('log') plt.xscale('log') #plt.xlim(mini, maxi) plt.ylabel('g_frequency in #') plt.grid(color=cd2) plt.legend(loc='upper right') plt.xlim(10**-2,10**2) ax3 = fig.add_subplot(224, aspect='auto')#------------------------------------------------------------------------------- counts2, bins2, patches2 =plt.hist(data2[maske], bins=10 ** np.linspace(np.log10(10**-2), np.log10(10**2), st),orientation='horizontal', alpha=0.5, color=cd1, label='RADOLAN') plt.yscale('log') plt.xscale('log') counts1, bins1, patches1 = plt.hist(data1[maske], bins=10 ** np.linspace(np.log10(10**-2), np.log10(10**2), st), alpha=0.9, edgecolor='black', facecolor="None",orientation='horizontal', label='GPM') plt.yscale('log') plt.xscale('log') plt.xlabel('r_frequency in #') #plt.ylim(mini,maxi) plt.grid(color=cd1) plt.legend(loc='upper right') plt.ylim(10**-2,10**2) ax4 = fig.add_subplot(222, aspect='auto')#--------------------------------------------------------------------------------- bin_centers1 = np.mean(zip(bins1[:-1], bins1[1:]), axis=1) bin_centers2 = np.mean(zip(bins2[:-1], bins2[1:]), axis=1) ax4.plot(bin_centers1,counts1.cumsum(),color=cd2 ,ls='-', lw=2,alpha=0.5, label='GPM') ax4.plot(bin_centers2,counts2.cumsum(),color=cd1, ls='-', lw=2, alpha=0.5, label='RADOLAN') #plt.yscale('log') plt.xscale('log') maske = ~np.isnan(counts1) & ~np.isnan(counts2) slope2, intercept2, r_value2, p_value2, std_err2 = stats.linregress(counts1[maske], counts2[maske]) r_value_s, p_value_s = stats.spearmanr(counts1[maske], counts2[maske]) plt.ylabel('frequency in #') plt.xlabel('RR in mm/h') tit = 'Corr: '+ str(round(r_value2,3)) + r'$\pm$' + str(round(std_err2,3)) + '\n SCorr: '\ + str(round(r_value_s,3)) + r'$\pm$' + str(round(p_value_s,3)) plt.legend(loc='lower right')#, title=tit) #plt.xlim(10**-2,10**3) plt.grid()
def validation_plot(data1, data2, th_ss): """ Function: Plot for the validation of two datasets Input: data1, data2 ::: Input Data Output: Validation PLot """ # Todo: Schoener machen! mini = np.nanmin([np.nanmin(data1), np.nanmin(data2)]) - 5.0 maxi = np.nanmax([np.nanmax(data1), np.nanmax(data2)]) + 5.0 print 'Max data1: ', np.nanmax(data1) print 'Max data2: ', np.nanmax(data2) cd1 = 'blue' cd2 = 'green' print '________________________ Maxi:', maxi from scipy import stats, linspace fig = plt.figure(figsize=(14,14)) ax1 = fig.add_subplot(223, aspect='auto')#------------------------------------ maske = ~np.isnan(data1) & ~np.isnan(data2) slope, intercept, r_value, p_value, std_err = stats.linregress(data1[maske], data2[maske]) line = slope * data1 +intercept slope2, intercept2, r_value2, p_value2, std_err2 = stats.linregress(data2[maske], data1[maske]) line2 = slope2 * data2 +intercept2 from pcc import skill_score SS = skill_score(data1,data2,th=th_ss) ax1.scatter(data1, data2, label='Reflectivity [dBZ]', color='grey', alpha=0.6) r_value_s, p_value_s = stats.spearmanr(data1[maske],data2[maske]) text = ('f(x) = ' + str(round(slope,3)) + 'x + ' + str(round(intercept,3)) + '\nCorr: ' + str(round(r_value,3)) + r'$\pm$: '+ str(round(std_err,3))+ '\nN: '+ str(int(SS['N']))+ '\nHit: ' + str(SS['H'])+ '\nMiss: ' + str(SS['M'])+ '\nFalse: ' + str(SS['F'])+ '\nCnegative: ' + str(SS['C'])+ '\nHR: ' + str(round(SS['HR'],3))+ '\nPOD: ' + str(round(SS['POD'],3))+ '\nFAR: ' + str(round(SS['FAR'],3))+ '\nBID: ' + str(round(SS['BID'],3))+ '\nHSS: ' + str(round(SS['HSS'],3))+ '\nBias: '+ str(round(SS['bias'],3))+ '\nRMSE: '+ str(round(SS['RMSE'],3))+ '\nCorrS:' + str(round(r_value_s,3)) ) ax1.annotate(text, xy=(0.01, 0.99), xycoords='axes fraction', fontsize=10, horizontalalignment='left', verticalalignment='top') t1 = linspace(mini,maxi,50) plt.plot(t1,t1,'k-') #plt.plot(t1, t1*slope + intercept, 'r-', lw=3 ,label='Regression') #plt.plot(t1, t1*slope + (intercept+5), 'r-.', lw=1.5 ,label=r'Reg $\pm$ 5 mdBZ') #plt.plot(t1, t1*slope + (intercept-5), 'r-.', lw=1.5 ) plt.plot(t1,t1*slope + intercept,label='RADOLAN', color='green', lw=1.5, alpha=0.5) plt.plot(t1*slope2 + intercept2,t1,label='GPM', color='blue', lw=1.5, alpha=0.5) #plt.plot(np.nanmean(data1),np.nanmean(data2), 'ob', lw = 4,label='Mean') #plt.plot(np.nanmedian(data1),np.nanmedian(data2), 'vb', lw = 4,label='Median') #import matplotlib as mpl #mean = [ np.nanmean(data1),np.nanmean(data2)] #width = np.nanstd(data1) #height = np.nanstd(data2) #angle = 0 #ell = mpl.patches.Ellipse(xy=mean, width=width, height=height, # angle=180+angle, color='blue', alpha=0.8, # fill=False, ls='--', label='Std') #ax1.add_patch(ell) plt.legend(loc='lower right', fontsize=10, scatterpoints= 1, numpoints=1, shadow=True) #plt.scatter(data1, data2, alpha=0.5) plt.xlim(mini,maxi) plt.ylim(mini,maxi) plt.xlabel('GPM DPR') plt.ylabel('RADOLAN') plt.grid() #plt.colorbar(shrink=1) ax2 = fig.add_subplot(221, aspect='auto')#------------------------------------ counts1, bins1, patches1 = plt.hist(data1[maske], bins=int(maxi), alpha=0.5, color=cd2, label='GPM DPR') counts2, bins2, patches2 =plt.hist(data2[maske], bins=int(maxi), alpha=0.9, edgecolor='black', facecolor="None", label='RADOLAN') plt.xlim(mini, maxi) plt.ylabel('g_frequency in #') plt.grid(color=cd2) plt.legend(loc='upper right') ax3 = fig.add_subplot(224, aspect='auto')#------------------------------------ counts2, bins2, patches2 =plt.hist(data2[maske], bins=int(maxi),orientation='horizontal', alpha=0.5, color=cd1, label='RADOLAN') counts1, bins1, patches1 = plt.hist(data1[maske], bins=int(maxi), alpha=0.9, edgecolor='black', facecolor="None",orientation='horizontal', label='GPM') plt.xlabel('r_frequency in #') plt.ylim(mini,maxi) plt.grid(color=cd1) plt.legend(loc='upper right') ax4 = fig.add_subplot(222, aspect='auto')#------------------------------------ bin_centers1 = np.mean(zip(bins1[:-1], bins1[1:]), axis=1) bin_centers2 = np.mean(zip(bins2[:-1], bins2[1:]), axis=1) ax4.plot(counts1.cumsum(),color=cd2 ,ls='-', lw=2,alpha=0.5, label='GPM') ax4.plot(counts2.cumsum(),color=cd1, ls='-', lw=2, alpha=0.5, label='RADOLAN') maske = ~np.isnan(counts1) & ~np.isnan(counts2) slope2, intercept2, r_value2, p_value2, std_err2 = stats.linregress(counts1[maske], counts2[maske]) r_value_s, p_value_s = stats.spearmanr(counts1[maske], counts2[maske]) plt.ylabel('frequency in #') plt.xlabel('Reflectivity in dBz') tit = 'Corr: '+ str(round(r_value2,3)) + r'$\pm$' + str(round(std_err2,3)) + '\n SCorr: '\ + str(round(r_value_s,3)) + r'$\pm$' + str(round(p_value_s,3)) plt.legend(loc='lower right')#, title=tit) plt.grid()
plt.ylim(0,maxAB + 1) plt.legend(loc='upper center', bbox_to_anchor=(0.5, 1.1), ncol=2, fancybox=True, shadow=True, fontsize='small', title= "Slope: " + str(round(slope,3)) + ', Intercept: '+ str(round(intercept,3)) + "\n Correlation: " + str(round(r_value,3)) + ', Std_err: '+ str(round(std_err,3))) plt.xlabel(GPMI_name[ip]) plt.ylabel("RADOLAN RR [mm/h]") plt.title(" .") plt.grid(True) plt.tight_layout() plt.show() ############################################################################### import pcc R = pcc.skill_score(est,ref,0.1) pcc.plot_score(est,ref,R) plt.xlabel(GPMI_name[ip]) plt.ylabel("RADOLAN RR [mm/h]") #plt.yscale('log') #plt.xscale('log') plt.title(" .") plt.tight_layout() plt.show() ''' plt.hist(A[mask],bins=200, color='red', alpha=0.4, label='RADOLAN interpoliert') plt.hist(B[mask], bins=200, color='blue', alpha=0.4, label='GPROF')
shadow=True, fontsize='small', title="Slope: " + str(round(slope, 3)) + ', Intercept: ' + str(round(intercept, 3)) + "\n Correlation: " + str(round(r_value, 3)) + ', Std_err: ' + str(round(std_err, 3))) plt.xlabel(GPMI_name[ip]) plt.ylabel("RADOLAN RR [mm/h]") plt.title(" .") plt.grid(True) plt.tight_layout() plt.show() ############################################################################### import pcc R = pcc.skill_score(est, ref, 0.1) pcc.plot_score(est, ref, R) plt.xlabel(GPMI_name[ip]) plt.ylabel("RADOLAN RR [mm/h]") #plt.yscale('log') #plt.xscale('log') plt.title(" .") plt.tight_layout() plt.show() ''' plt.hist(A[mask],bins=200, color='red', alpha=0.4, label='RADOLAN interpoliert') plt.hist(B[mask], bins=200, color='blue', alpha=0.4, label='GPROF') #pdf = stats.norm.pdf(sorted(B[mask]), B[mask], B[mask]) #plt.plot(sorted(B[mask]), pdf) plt.xlabel("RR [mm/h]")