Commit 8a7d38cc authored by Leonie Pick's avatar Leonie Pick

New histogram for classified storm drivers

parent beee3fe6
This diff is collapsed.
......@@ -591,7 +591,7 @@ def Select_Features(Data,Target,N2,K2,Pipe,SelectParams,EstimateParams,scoring,s
ranking = np.argsort(transformer.ranking_)
## Plot test results
ax = pl.Ranking(Scores_mean, Scores_std, Data, ranking, FeaturesSelect, estimators, scoring_name, est, ax, Save, SaveName)
ax = pl.Ranking(Scores_mean, Scores_std, Data, ranking, FeaturesSelect, estimators, scoring_name, nFeatures, est, ax, Save, SaveName)
return EstimateParams, ax
###
......
......@@ -249,7 +249,7 @@ def Diagnostics(n_features,n_classes,NData, Save):
plt.show()
###
###
def Ranking(Scores, Std, Data, Ranking, nfeaturesFinal, estimators, scoring_name, est, ax, Save, SaveName):
def Ranking(Scores, Std, Data, Ranking, nfeaturesFinal, estimators, scoring_name, nFeatures, est, ax, Save, SaveName):
nEstimators = len(estimators)
......@@ -265,7 +265,7 @@ def Ranking(Scores, Std, Data, Ranking, nfeaturesFinal, estimators, scoring_name
ax[est].errorbar(np.arange(1,Data.shape[1]+1,1),Scores[:,0],color='midnightblue',yerr=2*Std[:,0],linewidth=1.5,elinewidth=1.5,label='Validation set')
ax[est].errorbar(np.arange(1,Data.shape[1]+1,1),Scores[:,1],color='gray',yerr=2*Std[:,1],linewidth=1.5,elinewidth=1.5,label='Training set')
ax[est].set_xticks(np.arange(1,Data.shape[1]+1,1))
ax[est].set_xlim([0.5,11.5])
ax[est].set_xlim([0.5,nFeatures+.5])
ax[est].scatter(np.argmax(Scores[:,0])+1,np.max(Scores[:,0]),s=50,color='maroon',zorder=3,label='Best')
#ax[est].scatter(np.argmax(Scores[:,1])+1,np.max(Scores[:,1]),s=30,color='gray',zorder=3,label='Best (Training)')
#ax[est].scatter(nfeaturesFinal,Scores[nfeaturesFinal-1,0],s=20,color='midnightblue',zorder=2,label='Best (Validation)')
......@@ -273,10 +273,14 @@ def Ranking(Scores, Std, Data, Ranking, nfeaturesFinal, estimators, scoring_name
ax[est].tick_params(axis ='x',which='both',direction='inout',labelsize=16)
ax[est].tick_params(axis ='y',which='both',direction='inout',labelsize=16)
IDs = [1,9,11,2,10,3,6,7,8,4,5]
newID = np.zeros(nFeatures)
for i in range(nFeatures):
newID[i] = int(IDs[Ranking[i]])
axu=ax[est].twiny()
axu.set_xticks(np.arange(1,Data.shape[1]+1,1))
axu.set_xticklabels(Ranking)
axu.set_xlim([0.5,11.5])
axu.set_xticklabels(newID.astype(int))
axu.set_xlim([0.5,nFeatures+.5])
axu.tick_params(axis ='x',which='both',direction='inout',labelsize=16)
if est == 0:
......@@ -664,7 +668,7 @@ def Musical(Time,HTime,Storms,Kp_all,KpHours_all,SN,SNYears,HMC,HMC_filt,Referen
for i in [1,0]:
zi = np.where(z==i)[0]
ni, bins = np.histogram(HTime[Reference[KnownE[zi],1],4],np.arange(1900,2017,1))
axs2.barh(np.arange(1900,2016,1), ni, left = nip, height=0.8,color=cm(float(i)),zorder=5)
axs2.barh(np.arange(1900.5,2016.5,1), ni, left = nip, height=0.9, color=cm(float(i)),zorder=5)
nip += ni
#Turner_CIR = np.where(np.logical_and(Reference[:,2] == b'Turner',Target['type'] ==0))[0]
......@@ -739,7 +743,7 @@ def Musical(Time,HTime,Storms,Kp_all,KpHours_all,SN,SNYears,HMC,HMC_filt,Referen
plt.show()
###
###
def MusicalClassified(Time,HTime,Storms,Class_Proba,Kp_all,KpHours_all,SN,SNYears,HMC,HMC_filt,Save,SaveName):
def MusicalClassified(Time,HTime,Reference,Source,Storms,Class_Proba,Class,Kp_all,KpHours_all,SN,SNYears,HMC,HMC_filt,Save,SaveName):
fig, axs = plt.subplots(1,4,facecolor='w', edgecolor='k',sharey=True)
fig.set_size_inches([6.69, 8.86], forward=True)
......@@ -791,7 +795,7 @@ def MusicalClassified(Time,HTime,Storms,Class_Proba,Kp_all,KpHours_all,SN,SNYear
axs2.set_xticks([0,0.5,1])
axs2.set_xticklabels(['0','0.5','1'])
axs2.set_ylim([HTime[Storms[0],4],HTime[Storms[-1],4]])
axs2.set_xlabel('Occurrence [%]')
axs2.set_xlabel('Occurrence')
#axs2.spines['bottom'].set_color('khaki')
##axs2.spines['top'].set_color('midnightblue')
......@@ -863,12 +867,19 @@ def MusicalClassified(Time,HTime,Storms,Class_Proba,Kp_all,KpHours_all,SN,SNYear
################################################
# Plots class occurrences
n, bins = np.histogram(HTime[Storms,4],np.arange(1900.5,2017.5,1))
#n, bins = np.histogram(HTime[Storms,4],np.arange(1900.5,2017.5,1))
n, bins = np.histogram(HTime[Storms,4],np.arange(1900,2017,1))
start = 1; step=0.1; loops = 1./step; nip = 0
for i in range(int(loops)):
zi = np.where(np.logical_and(z>start-step,z<=start))[0]
ni, bins = np.histogram(HTime[Storms[zi],4],np.arange(1900.5,2017.5,1))
axs2.barh(np.arange(1900.5,2016.5,1), (ni*100/n)/100, left = nip, height=0.8,color=cm(1-(i*step)-step/2)) #left = (nip*100/n)/100
#zi = np.where(np.logical_and(z>start-step,z<=start))[0]
if i == 0:
zi = np.where(np.logical_and(z>=start-step,z<=start))[0]
else:
zi = np.where(np.logical_and(z>=start-step,z<start))[0]
#ni, bins = np.histogram(HTime[Storms[zi],4],np.arange(1900.5,2017.5,1))
ni, bins = np.histogram(HTime[Storms[zi],4],np.arange(1900,2017,1))
axs2.barh(np.arange(1900.5,2016.5,1), (ni*100/n)/100, left = nip, height=0.8, color=cm(1-(i*step)-step/2)) #left = (nip*100/n)/100
start -= step
nip += (ni*100/n)/100
#nCIR, bins = np.histogram(HTime['dyear'][Storms[CIRs_pred,1]],np.arange(1900,2017,1))
......@@ -886,11 +897,55 @@ def MusicalClassified(Time,HTime,Storms,Class_Proba,Kp_all,KpHours_all,SN,SNYear
#axs3.plot((SN[SN_start:SN_end,1]-np.min(SN[SN_start:SN_end,1]))/np.ptp(SN[SN_start:SN_end,1]),SN[SN_start:SN_end,0],color='black',linewidth=1.5, label='SN')
axs3.plot((SN[SN_start:SN_end]/max(SN[SN_start:SN_end]))**1,SNYears[SN_start:SN_end],color='white',linewidth=1.5, label='SN')
axs3.plot((HMC_filt/min(HMC_filt))**1,HTime[:,4],color='white',linestyle='--',linewidth=1.5, label='HMC')
####################################################################
#Class occurrence in separate plot
fig2, axs2 = plt.subplots(1,1,facecolor='white', edgecolor='k')
fig2.set_size_inches([6.69,4], forward=True)
fig2.subplots_adjust(bottom=0.06,top=0.9,left=0.115,right=0.99,hspace=0.00,wspace=0.00)
ClassPositive = np.where(Class==1)[0]
nPos, binsPos = np.histogram(HTime[Storms[ClassPositive],4],np.arange(1900,2017,1))
nNeg, binsNeg = np.histogram(HTime[Storms[~ClassPositive],4],np.arange(1900,2017,1))
Training = np.where(Reference[:,2]==1)[0]
ClassPositiveRef = np.where(Reference[Training,0]==1)[0]
nPosRef, binsRef = np.histogram(HTime[Reference[Training[ClassPositiveRef],1]],np.arange(1900,2017,1))
nNegRef, binsRef = np.histogram(HTime[Reference[Training[~ClassPositiveRef],1]],np.arange(1900,2017,1))
axs2b=axs2.twinx()
axs2b.invert_yaxis()
if Save == True:
fig.savefig('./Dump/Fig/development/StormsClassified_'+SaveName+'.pdf',format='pdf',dpi=200)#,transparent=True)
#fig.savefig('./Dump/Fig/StormsClassified.png',format='png',dpi=200)#,transparent=True)
axs2.bar(binsPos[0:-1],height=nPosRef,width=1,align='edge',color='maroon',edgecolor='None',alpha=0.5,label='Training ICMEs',zorder=0)
axs2.bar(binsPos[0:-1],height=nPos,width=1,align='edge',color='None',edgecolor='maroon',linewidth=1,label='Predicted ICMEs',zorder=1)
#axs2.bar(binsPos[0:-1],height=nNegRef,width=1,bottom=nPosRef,align='edge',color='midnightblue',edgecolor='None',alpha=0.5,label='Training C/SIRs',zorder=0)
#axs2.bar(binsPos[0:-1],height=nNeg,width=1,bottom=nPos,align='edge',color='None',edgecolor='midnightblue',linewidth=1,label='C/SIRs',zorder=1)
axs2b.bar(binsPos[0:-1],height=nNegRef,width=1,align='edge',color='midnightblue',edgecolor='None',alpha=0.5,label='Training C/SIRs',zorder=0)
axs2b.bar(binsPos[0:-1],height=nNeg,width=1,align='edge',color='None',edgecolor='midnightblue',linewidth=1,label='Predicted C/SIRs',zorder=1)
axs2.legend(loc=3,ncol=1,frameon=True,fontsize=11)
axs2b.legend(loc=2,ncol=1,frameon=True,fontsize=11)
axs2.set_xlim([1930,2016])
axs2.set_ylim([0,120])
axs2b.set_ylim([120,0])
axs2.set_yticks(np.arange(0,120,20))
axs2.set_yticks(np.arange(0,120,10),minor=True)
axs2.tick_params(axis='y', colors='maroon')
axs2b.set_yticks(np.linspace(100,0,6))
axs2b.set_yticks(np.linspace(120,0,13),minor=True)
axs2b.tick_params(axis='y', colors='midnightblue')
axs2.set_xlabel('Year')
axs2.set_ylabel('Count ICMEs')
axs2b.set_ylabel('Count C/SIRs')
if Save == True:
fig.savefig('./Dump/Fig/development/StormsClassified_'+SaveName+'.pdf',format='pdf',dpi=200,bbox_inches='tight',pad_inches=0.01)#,transparent=True)
fig.savefig('./Dump/Fig/development/StormsClassified_'+SaveName+'.png',format='png',dpi=200,bbox_inches='tight',pad_inches=0.01)#,transparent=True)
fig2.savefig('./Dump/Fig/development/StormsHisto_'+SaveName+'.pdf',format='pdf',dpi=200,bbox_inches='tight',pad_inches=0.01)#,transparent=True)
fig2.savefig('./Dump/Fig/development/StormsHisto_'+SaveName+'.png',format='png',dpi=200,bbox_inches='tight',pad_inches=0.01)#,transparent=True)
plt.show()
###
###
......@@ -962,7 +1017,7 @@ def Stats(HTime,Storms,SN,SNYears,HMC,Proba,Class,Save,SaveName):
if Save == True:
fig.savefig('./Dump/Fig/development/Statistics_'+SaveName+'.pdf',format='pdf',dpi=200,bbox_inches='tight',pad_inches=0.01)
#fig.savefig('./Dump/Fig/Statistics.png',format='png',dpi=200,bbox_inches='tight',pad_inches=0.01)
fig.savefig('./Dump/Fig/development/Statistics_'+SaveName+'.png',format='png',dpi=200,bbox_inches='tight',pad_inches=0.01)
plt.show()
###
###
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment