# R code developed by: # International Research Institute for Climate and Society # Columbia University in the City of New York, USA # Last update: Jully 3, 2013 # -------------------------------------------------------------------------------- # -------------------------------------------------------------------------------- # FUNCTION : ExtractContinuousScores # -------------------------------------------------------------------------------- # Dependancies : (see each function for further details) # -- File "Directory_Output/XXX_ens_correct_MonthlyMean_Continuous_Skill_Scores_3_Month_Predictions.csv" # OR # -- File "Directory_Output/XXX_ens_correct_MonthlyMean_Anomalies_Continuous_Skill_Scores_3_Month_Predictions.csv" # -------------------------------------------------------------------------------- # Results : # -- A list of all the selected scores of interest, put in the right order for plotting # -------------------------------------------------------------------------------- # Parameters : # -- XXX the model # -- L=1 or 2 or 3 the leading time for to consider for the scores # -- ens="ensemble" or "single" the nature of the model # -- correct="corrected_method" or "uncorected" indicate the way the results have been corrected (or not) # -- anomalies=TRUE or FALSE indicate if you want the scores to be extracted for the anomalies (TRUE) or the nominal values (FALSE) # -------------------------------------------------------------------------------- ExtractContinuousScores <- function(XXX,L,ens,correct,anomalies){ if (!anomalies){ # anomalies=FALSE : extract the continuous scores of the nominal values Pred<-read.csv(paste(Directory_Output,XXX,"_",ens,"_",correct,"_MonthlyMean_Continuous_Skill_Scores_3_Month_Predictions.csv",sep=""),sep=",") # In that case, extract MSE, SS, Bias and ACC MSE_Pred<-Pred[seq(4,nrow(Pred),by=9),L+1] MSE_Pred <-c(MSE_Pred[c(11,12)], MSE_Pred[-c(11,12)]) #Put them back in order (Jan -> Dec) SS_Pred<-Pred[seq(7,nrow(Pred),by=9),L+1] SS_Pred <-c(SS_Pred[c(11,12)], SS_Pred[-c(11,12)]) Bias_Pred<-Pred[seq(9,nrow(Pred),by=9),L+1] Bias_Pred <-c(Bias_Pred[c(11,12)], Bias_Pred[-c(11,12)]) ACC_Pred<-Pred[seq(8,nrow(Pred),by=9),L+1] ACC_Pred <-c(ACC_Pred[c(11,12)], ACC_Pred[-c(11,12)]) Scores<-list(MSE=MSE_Pred, SS=SS_Pred, Bias=Bias_Pred, ACC=ACC_Pred) return(Scores) } else { # anomalies=TRUE : extract the continuous scores on the anomalies Pred<-read.csv(paste(Directory_Output,XXX,"_",ens,"_",correct,"_MonthlyMean_Anomalies_Continuous_Skill_Scores_3_Month_Predictions.csv",sep=""),sep=",") # In that case, extract MSE and SS MSE_Pred<-Pred[seq(4,nrow(Pred),by=7),L+1] MSE_Pred <-c(MSE_Pred[c(11,12)], MSE_Pred[-c(11,12)]) #Put them back in order (Jan -> Dec) SS_Pred<-Pred[seq(6,nrow(Pred),by=7),L+1] SS_Pred <-c(SS_Pred[c(11,12)], SS_Pred[-c(11,12)]) Scores<-list(MSE=MSE_Pred, SS=SS_Pred) return(Scores) } } # -------------------------------------------------------------------------------- # FUNCTION : ExtractProbalisticScores # -------------------------------------------------------------------------------- # Dependancies : (see each function for further details) # -- File "Directory_Output/XXX_ens_correct_Eventev_MonthlyMean_Anomalies_Probabilistic_Skill_Scores_3_Month_Predictions.csv" # -------------------------------------------------------------------------------- # Results : # -- A list of all the selected scores of interest, put in the right order for plotting # -------------------------------------------------------------------------------- # Parameters : # -- XXX the model # -- L=1 or 2 or 3 the leading time for to consider for the scores # -- correct="corrected_method" or "uncorected" indicate the way the results have been corrected (or not) # -- ev=1 or 2 the reference of the event taken into account for the scores # -------------------------------------------------------------------------------- ExtractProbalisticScores<-function(XXX,L,correct,ev){ Sco<-read.csv(paste(Directory_Output, XXX, "_", "ensemble", "_", correct, "_", "Event", ev, "_MonthlyMean_Anomalies_Probabilistic_Skill_Scores_3_Month_Predictions.csv", sep = ""),sep=",") # In that case, extract BS, SS and ROC BS<-Sco[seq(2,nrow(Sco),by=4),L+1] BS <-c(BS[c(11,12)], BS[-c(11,12)]) SS<-Sco[seq(4,nrow(Sco),by=4),L+1] SS <-c(SS[c(11,12)], SS[-c(11,12)]) ROC<-Sco[seq(5,nrow(Sco),by=4),L+1] ROC <-c(ROC[c(11,12)], ROC[-c(11,12)]) Scores<-list(BS=BS, SS=SS, ROC=ROC) return(Scores) }