plot_OutputsModel.R 20.50 KiB
#*****************************************************************************************************************
#' Function which creates a screen plot giving an overview of the model outputs
#'
#' Dashboard of results including various graphs (depending on the model):
#' (1) time series of total precipitation and simulated flows (and observed flows if provided)
#' (2) interannual median monthly simulated flow (and observed flows if provided)
#' (3) correlation plot between simulated and observed flows (if observed flows provided)
#' (4) cumulative frequency plot for simulated flows (and observed flows if provided)
#*****************************************************************************************************************
#' @title   Default preview of model outputs
#' @author  Laurent Coron (June 2014)
## @example tests/example_plot_OutputsModel.R
#' @encoding UTF-8
#' @export
#_FunctionInputs__________________________________________________________________________________________________
#' @param  OutputsModel      [object of class \emph{OutputsModel}] list of model outputs (which must at least include DatesR, Precip and Qsim) [POSIXlt, mm, mm]
#' @param  Qobs              (optional) [numeric] time series of observed flow (for the same time-steps than simulated) [mm]
#' @param  IndPeriod_Plot    (optional) [numeric] indices of the time-steps to be plotted (among the OutputsModel series)
#' @param  BasinArea         (optional) [numeric] basin area [km2], used to plot flow axes in m3/s
#' @param  quiet             (optional) [boolean] boolean indicating if the function is run in quiet mode or not, default=FALSE
#_FunctionOutputs_________________________________________________________________________________________________
#' @return  screen plot window
#*****************************************************************************************************************'
plot_OutputsModel <- function(OutputsModel,Qobs=NULL,IndPeriod_Plot=NULL,BasinArea=NULL,quiet=FALSE){
  if(!inherits(OutputsModel,"GR") & !inherits(OutputsModel,"CemaNeige")){ stop(paste("OutputsModel not in the correct format for default plotting \n",sep="")); return(NULL); }
  BOOL_Dates <- FALSE; 
      if("DatesR" %in% names(OutputsModel)){ BOOL_Dates <- TRUE; }
  BOOL_Pobs <- FALSE; 
      if("Precip" %in% names(OutputsModel)){ BOOL_Pobs <- TRUE; }
  BOOL_Qsim <- FALSE; 
      if("Qsim"   %in% names(OutputsModel)){ BOOL_Qsim <- TRUE; }
  BOOL_Qobs <- FALSE;
      if(BOOL_Qsim & length(Qobs)==length(OutputsModel$Qsim)){ if(sum(is.na(Qobs))!=length(Qobs)){ BOOL_Qobs <- TRUE; } }
  BOOL_Snow <- FALSE;
      if("CemaNeigeLayers" %in% names(OutputsModel)){ if("SnowPack" %in% names(OutputsModel$CemaNeigeLayers[[1]])){ BOOL_Snow <- TRUE; } }
  BOOL_Psol <- FALSE;
      if("CemaNeigeLayers" %in% names(OutputsModel)){ if("Psol"     %in% names(OutputsModel$CemaNeigeLayers[[1]])){ BOOL_Psol <- TRUE; } }
  if(!BOOL_Dates){
    stop(paste("OutputsModel must contain at least DatesR to allow plotting \n",sep="")); return(NULL); }
  if(inherits(OutputsModel,"GR") & !BOOL_Qsim){
    stop(paste("OutputsModel must contain at least Qsim to allow plotting \n",sep="")); return(NULL); }
  if(BOOL_Dates){
    MyRollMean1 <- function(x,n){
      return(filter(x,rep(1/n,n),sides=2)); }
    MyRollMean2 <- function(x,n){
      return(filter(c(tail(x,n%/%2),x,x[1:(n%/%2)]),rep(1/n,n),sides=2)[(n%/%2+1):(length(x)+n%/%2)]); }
    BOOL_TS  <- FALSE;
    TimeStep <- difftime(tail(OutputsModel$DatesR,1),tail(OutputsModel$DatesR,2),units="secs")[[1]];
    if(inherits(OutputsModel,"hourly" ) & TimeStep ==                     60*60){ BOOL_TS <- TRUE; plotunit <- "[mm/h]";     }
    if(inherits(OutputsModel,"daily"  ) & TimeStep ==                  24*60*60){ BOOL_TS <- TRUE; plotunit <- "[mm/d]";     }
    if(inherits(OutputsModel,"monthly") & TimeStep %in% c(28,29,30,31)*24*60*60){ BOOL_TS <- TRUE; plotunit <- "[mm/month]"; }
    if(inherits(OutputsModel,"yearly" ) & TimeStep %in%     c(365,366)*24*60*60){ BOOL_TS <- TRUE; plotunit <- "[mm/y]";     }
    if(!BOOL_TS){ stop(paste("the time step of the model inputs could not be found \n",sep="")); return(NULL); } 
  if(length(IndPeriod_Plot)==0){ IndPeriod_Plot <- 1:length(OutputsModel$DatesR); }
  if(inherits(OutputsModel,"CemaNeige")){ NLayers <- length(OutputsModel$CemaNeigeLayers); }
  BOOL_QobsZero <- FALSE; if(BOOL_Qobs){ SelectQobsNotZero <- (round(Qobs[IndPeriod_Plot]             ,4)!=0); BOOL_QobsZero <- sum(!SelectQobsNotZero,na.rm=TRUE)>0; }
  BOOL_QsimZero <- FALSE; if(BOOL_Qsim){ SelectQsimNotZero <- (round(OutputsModel$Qsim[IndPeriod_Plot],4)!=0); BOOL_QsimZero <- sum(!SelectQsimNotZero,na.rm=TRUE)>0; }
  if(BOOL_QobsZero & !quiet){ warning("\t zeroes detected in Qobs -> some plots in the log space will not be created using all time-steps \n"); }
  if(BOOL_QsimZero & !quiet){ warning("\t zeroes detected in Qsim -> some plots in the log space will not be created using all time-steps \n"); }
  BOOL_FilterZero <- TRUE;
  ##Options
  BLOC <- TRUE; if(BLOC){
    cexaxis <- 1.0; cexlab <- 0.9; cexleg=1.0; lwd=1.8; lineX=2.6; lineY=2.6; bgleg <- rgb(1,1,1,alpha=0.7); bgleg <- NA;
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
matlayout <- NULL; iPlot <- 0; if(BOOL_Pobs){ matlayout <- rbind(matlayout,c(iPlot+1,iPlot+1,iPlot+1)); iPlot <- iPlot+1; } if(BOOL_Snow){ matlayout <- rbind(matlayout,c(iPlot+1,iPlot+1,iPlot+1),c(iPlot+1,iPlot+1,iPlot+1)); iPlot <- iPlot+1; } if(BOOL_Qsim | BOOL_Qobs){ matlayout <- rbind(matlayout,c(iPlot+1,iPlot+1,iPlot+1),c(iPlot+1,iPlot+1,iPlot+1)); iPlot <- iPlot+1; } if(BOOL_TS & BOOL_Qsim){ matlayout <- rbind(matlayout,c(iPlot+1,iPlot+2,iPlot+3),c(iPlot+1,iPlot+2,iPlot+3)); iPlot <- iPlot+3; } iPlotMax <- iPlot; isRStudio <- Sys.getenv("RSTUDIO") == "1"; if(!isRStudio){ if(iPlotMax==1){ dev.new(width=10,height=02); } if(iPlotMax==2){ dev.new(width=10,height=05); } if(iPlotMax==3){ dev.new(width=10,height=05); } if(iPlotMax==5){ dev.new(width=10,height=07); } if(iPlotMax==6){ dev.new(width=10,height=10); } } layout(matlayout); Xaxis <- 1:length(IndPeriod_Plot); if(BOOL_Dates){ Seq1 <- which(OutputsModel$DatesR[IndPeriod_Plot]$mday==1 & OutputsModel$DatesR[IndPeriod_Plot]$mon %in% c(0,3,6,9)); Seq2 <- which(OutputsModel$DatesR[IndPeriod_Plot]$mday==1 & OutputsModel$DatesR[IndPeriod_Plot]$mon==0); } if(!is.null(BasinArea)){ Factor_MMH_M3S <- BasinArea/( 60*60/1000); Factor_MMD_M3S <- BasinArea/( 24*60*60/1000); Factor_MMM_M3S <- BasinArea/(365.25/12*24*60*60/1000); Factor_MMY_M3S <- BasinArea/( 365.25*24*60*60/1000); if(inherits(OutputsModel,"hourly" )){ Factor_UNIT_M3S <- Factor_MMH_M3S; } if(inherits(OutputsModel,"daily" )){ Factor_UNIT_M3S <- Factor_MMD_M3S; } if(inherits(OutputsModel,"monthly")){ Factor_UNIT_M3S <- Factor_MMM_M3S; } if(inherits(OutputsModel,"yearly" )){ Factor_UNIT_M3S <- Factor_MMY_M3S; } } } kPlot <- 0; ##Precip if(BOOL_Pobs){ kPlot <- kPlot+1; mar <- c(3,5,1,5); par(new=FALSE,mar=mar,las=0) ylim1 <- range(OutputsModel$Precip[IndPeriod_Plot],na.rm=TRUE); ylim2 <- ylim1; ylim2 <- rev(ylim2); plot(Xaxis,OutputsModel$Precip[IndPeriod_Plot],type="h",ylim=ylim2,col="royalblue",lwd=0.7,xaxt="n",yaxt="n",xlab="",ylab="",xaxs="i",yaxs="i"); axis(side=2,at=pretty(ylim1),labels=pretty(ylim1),cex.axis=cexaxis) par(las=0); mtext(side=2,paste("precip. ",plotunit,sep=""),line=lineY,cex=cexlab,adj=1); par(las=0); if(BOOL_Psol){ par(new=TRUE); for(iLayer in 1:NLayers){ if(iLayer==1){ PsolLayerMean <- OutputsModel$CemaNeigeLayers[[iLayer]]$Psol/NLayers; } else { PsolLayerMean <- PsolLayerMean + OutputsModel$CemaNeigeLayers[[iLayer]]$Psol/NLayers; } } plot(Xaxis,PsolLayerMean[IndPeriod_Plot],type="h",ylim=ylim2,col="lightblue",lwd=0.7,xaxt="n",yaxt="n",xlab="",ylab="",xaxs="i",yaxs="i"); } if(BOOL_Dates){ axis(side=1,at=Seq1,labels=FALSE,cex.axis=cexaxis); axis(side=1,at=Seq2,labels=format(OutputsModel$DatesR[IndPeriod_Plot],format="%m/%Y")[Seq2],lwd.ticks=1.5,cex.axis=cexaxis); } else { axis(side=1,at=pretty(Xaxis),labels=pretty(Xaxis),cex.axis=cexaxis); } } ##SnowPack if(BOOL_Snow){ kPlot <- kPlot+1; mar <- c(3,5,1,5); par(new=FALSE,mar=mar,las=0) ylim1 <- c(+99999,-99999) for(iLayer in 1:NLayers){
141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
ylim1[1] <- min(ylim1[1],OutputsModel$CemaNeigeLayers[[iLayer]]$SnowPack); ylim1[2] <- max(ylim1[2],OutputsModel$CemaNeigeLayers[[iLayer]]$SnowPack); if(iLayer==1){ SnowPackLayerMean <- OutputsModel$CemaNeigeLayers[[iLayer]]$SnowPack/NLayers; } else { SnowPackLayerMean <- SnowPackLayerMean + OutputsModel$CemaNeigeLayers[[iLayer]]$SnowPack/NLayers; } } plot(SnowPackLayerMean[IndPeriod_Plot],type="l",ylim=ylim1,lwd=lwd*1.2,col="royalblue",xlab="",ylab="",xaxt="n",yaxt="n",xaxs="i") for(iLayer in 1:NLayers){ lines(OutputsModel$CemaNeigeLayers[[iLayer]]$SnowPack[IndPeriod_Plot],lty=3,col="royalblue",lwd=lwd*0.8); } axis(side=2,at=pretty(ylim1),labels=pretty(ylim1),cex.axis=cexaxis) par(las=0); mtext(side=2,paste("snow pack ","[mm]",sep=""),line=lineY,cex=cexlab); par(las=0); legend("topright",c(paste("mean snow pack",sep=""),paste("snow pack for each layer",sep="")),col=c("royalblue","royalblue"),lty=c(1,3),lwd=c(lwd*1.2,lwd*0.8),bty="o",bg=bgleg,box.col=bgleg,cex=cexleg) box() if(BOOL_Dates){ axis(side=1,at=Seq1,labels=FALSE,cex.axis=cexaxis); axis(side=1,at=Seq2,labels=format(OutputsModel$DatesR[IndPeriod_Plot],format="%m/%Y")[Seq2],lwd.ticks=1.5,cex.axis=cexaxis); } else { axis(side=1,at=pretty(Xaxis),labels=pretty(Xaxis),cex.axis=cexaxis); } } ##Flows if(BOOL_Qsim){ kPlot <- kPlot+1; mar <- c(3,5,1,5); par(new=FALSE,mar=mar,las=0) ylim1 <- range(OutputsModel$Qsim[IndPeriod_Plot],na.rm=TRUE); if(BOOL_Qobs){ ylim1 <- range(c(ylim1,Qobs[IndPeriod_Plot]),na.rm=TRUE); } ylim2 <- c(ylim1[1],1.2*ylim1[2]); plot(Xaxis,rep(NA,length(Xaxis)),type="n",ylim=ylim2,xlab="",ylab="",xaxt="n",yaxt="n",xaxs="i"); txtleg <- NULL; colleg <- NULL; if(BOOL_Qobs){ lines(Xaxis,Qobs[IndPeriod_Plot],lwd=lwd,lty=1,col="black"); txtleg <- c(txtleg,"observed"); colleg <- c(colleg,"black"); } if(BOOL_Qsim){ lines(Xaxis,OutputsModel$Qsim[IndPeriod_Plot],lwd=lwd,lty=1,col="orangered"); txtleg <- c(txtleg,"simulated"); colleg <- c(colleg,"orangered"); } axis(side=2,at=pretty(ylim1),labels=pretty(ylim1),cex.axis=cexaxis) par(las=0); mtext(side=2,paste("flow ",plotunit,sep=""),line=lineY,cex=cexlab); par(las=0); if(!is.null(BasinArea)){ Factor <- Factor_UNIT_M3S; axis(side=4,at=pretty(ylim1*Factor)/Factor,labels=pretty(ylim1*Factor),cex.axis=cexaxis); par(las=0); mtext(side=4,paste("flow ","m3/s",sep=""),line=lineY,cex=cexlab); par(las=0); } if(BOOL_Dates){ axis(side=1,at=Seq1,labels=FALSE,cex.axis=cexaxis); axis(side=1,at=Seq2,labels=format(OutputsModel$DatesR[IndPeriod_Plot],format="%m/%Y")[Seq2],lwd.ticks=1.5,cex.axis=cexaxis); } else { axis(side=1,at=pretty(Xaxis),labels=pretty(Xaxis),cex.axis=cexaxis); } legend("topright",txtleg,col=colleg,lty=1,lwd=lwd,bty="o",bg=bgleg,box.col=bgleg,cex=cexleg) box() } ##Regime if(BOOL_TS & BOOL_Qsim & (inherits(OutputsModel,"hourly") | inherits(OutputsModel,"daily"))){ kPlot <- kPlot+1; mar <- c(6,5,1,5); plotunitregime <- "[mm/month]"; par(new=FALSE,mar=mar,las=0) ModelData <- as.data.frame(matrix(as.numeric(NA),nrow=length(IndPeriod_Plot),ncol=5)); ModelData[,1] <- as.numeric(format(OutputsModel$DatesR[IndPeriod_Plot],format="%Y%m%d%H")); if(BOOL_Pobs){ ModelData[,2] <- OutputsModel$Precip[IndPeriod_Plot]; } if(BOOL_Psol){ ModelData[,3] <- PsolLayerMean[IndPeriod_Plot]; } if(BOOL_Qobs){ ModelData[,4] <- Qobs[IndPeriod_Plot]; } if(BOOL_Qsim){ ModelData[,5] <- OutputsModel$Qsim[IndPeriod_Plot]; } colnames(ModelData) <- c("DatesModel","Precip","Psol","Qobs","Qsim"); TxtDatesModelData <- formatC(ModelData$DatesModel,format="d",width=8,flag="0"); if(inherits(OutputsModel,"hourly")){ DailyData <- as.data.frame(aggregate(ModelData[,2:5],by=list(as.numeric(substr(TxtDatesModelData,1,8))),FUN=sum,na.rm=T)); } if(inherits(OutputsModel,"daily")){ DailyData <- ModelData; } colnames(DailyData) <- c("DatesDaily","Precip","Psol","Qobs","Qsim"); TxtDatesDailyData <- formatC(DailyData$DatesDaily,format="d",width=8,flag="0"); MontlyData <- as.data.frame(aggregate(DailyData[,2:5],by=list(as.numeric(substr(TxtDatesDailyData,1,6))),FUN=sum,na.rm=T)); colnames(MontlyData) <- c("DatesMontly","Precip","Psol","Qobs","Qsim"); TxtDatesMontlyData <- formatC(MontlyData$DatesMontly,format="d",width=6,flag="0"); DailyDataAggregD <- as.data.frame(aggregate(DailyData[,2:5],by=list(as.numeric(substr(TxtDatesDailyData ,5,8))),FUN=mean,na.rm=T)); colnames(DailyDataAggregD) <- c("DatesDailyAggregD","Precip","Psol","Qobs","Qsim"); MonthlyDataAggregM <- as.data.frame(aggregate(MontlyData[,2:5],by=list(as.numeric(substr(TxtDatesMontlyData,5,6))),FUN=mean,na.rm=T));
211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
colnames(MonthlyDataAggregM) <- c("DatesMonthlyAggregM","Precip","Psol","Qobs","Qsim"); Window <- 30; DailyDataAggregD2 <- DailyDataAggregD; MonthlyDataAggregM2 <- MonthlyDataAggregM; if(plotunitregime=="[mm/month]"){ DailyDataAggregD2[ 2:5] <- DailyDataAggregD2[ 2:5]*Window; } if(plotunitregime=="[mm/d]" ){ MonthlyDataAggregM2[2:5] <- MonthlyDataAggregM2[2:5]/Window; } DailyDataAggregD3 <- as.data.frame(cbind(DailyDataAggregD2$DatesDailyAggregD, MyRollMean2(DailyDataAggregD2$Precip,Window), MyRollMean2(DailyDataAggregD2$Psol,Window), MyRollMean2(DailyDataAggregD2$Qobs,Window) , MyRollMean2(DailyDataAggregD2$Qsim,Window))); colnames(DailyDataAggregD3) <- colnames(DailyDataAggregD2); TxtDatesDailyAggregD3 <- formatC(DailyDataAggregD3$DatesDailyAggregD,format="d",width=4,flag="0"); xLabels <- paste(substr(TxtDatesDailyAggregD3,3,4),"/",substr(TxtDatesDailyAggregD3,1,2),sep="") Seq1 <- 1:nrow(DailyDataAggregD3); SeqLab1 <- Seq1[substr(xLabels,1,2)=="01"]; SeqLab1 <- c(SeqLab1,length(xLabels)); xLabels1 <- xLabels[SeqLab1]; Seq2 <- Seq1[substr(xLabels,1,2)=="15"]; SeqLab2 <- Seq2; xLabels2 <- c("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"); ylimQ <- range(c(DailyDataAggregD3$Qobs[Seq1],DailyDataAggregD3$Qsim[Seq1]),na.rm=TRUE); if(BOOL_Pobs){ ylimP <- c(max(MonthlyDataAggregM2$Precip,na.rm=TRUE),0); } txtleg <- NULL; colleg <- NULL; lwdleg <- NULL; lwdP=10 if(BOOL_Pobs){ plot(Seq2,MonthlyDataAggregM2$Precip[1:12],type="h",xlim=range(Seq1),ylim=c(3*ylimP[1],ylimP[2]),lwd=lwdP,lend=1,lty=1,col="royalblue",xlab="",ylab="",xaxt="n",yaxt="n",xaxs="i",yaxs="i",bty="n") txtleg <- c(txtleg,"Ptot" ); colleg <- c(colleg,"royalblue"); lwdleg <- c(lwdleg,lwdP/3); axis(side=2,at=pretty(0.8*ylimP,n=3),labels=pretty(0.8*ylimP,n=3),cex.axis=cexaxis,col.axis="royalblue",col.ticks="royalblue"); par(new=TRUE); } if(BOOL_Psol){ plot(Seq2,MonthlyDataAggregM2$Psol[1:12],type="h",xlim=range(Seq1),ylim=c(3*ylimP[1],ylimP[2]),lwd=lwdP,lend=1,lty=1,col="lightblue",xlab="",ylab="",xaxt="n",yaxt="n",xaxs="i",yaxs="i",bty="n"); txtleg <- c(txtleg,"Psol" ); colleg <- c(colleg,"lightblue"); lwdleg <- c(lwdleg,lwdP/3); par(new=TRUE); } plot(0,0,type="n",xlim=range(Seq1),ylim=c(ylimQ[1],2*ylimQ[2]),xlab="",ylab="",xaxt="n",yaxt="n",xaxs="i") if(BOOL_Qobs){ lines(Seq1,DailyDataAggregD3$Qobs[Seq1],lwd=lwd,lty=1,col="black" ); txtleg <- c(txtleg,"Qobs" ); colleg <- c(colleg,"black" ); lwdleg <- c(lwdleg,lwd); } if(BOOL_Qsim){ lines(Seq1,DailyDataAggregD3$Qsim[Seq1],lwd=lwd,lty=1,col="orangered"); txtleg <- c(txtleg,"Qsim"); colleg <- c(colleg,"orangered"); lwdleg <- c(lwdleg,lwd); } axis(side=1,at=SeqLab1,tick=TRUE ,labels=xLabels1,cex.axis=cexaxis) ### axis(side=1,at=SeqLab2,tick=FALSE,labels=xLabels2,cex.axis=cexaxis) axis(side=2,at=pretty(ylimQ),labels=pretty(ylimQ),cex.axis=cexaxis) par(las=0); mtext(side=1,paste("30-days rolling mean",sep=""),line=lineX,cex=cexlab); par(las=0); posleg <- "topright"; txtlab <- "flow regime"; if(BOOL_Pobs){ posleg <- "right"; txtlab <- "precip. & flow regime"; } par(las=0); mtext(side=2,paste(txtlab," ",plotunitregime,sep=""),line=lineY,cex=cexlab); par(las=0); if(!is.null(BasinArea)){ Factor <- Factor_MMM_M3S; axis(side=4,at=pretty(ylimQ*Factor)/Factor,labels=pretty(ylimQ*Factor),cex.axis=cexaxis); par(las=0); mtext(side=4,paste("flow ","m3/s",sep=""),line=lineY,cex=cexlab); par(las=0); } ### posleg <- "topright"; if(BOOL_Pobs){ posleg <- "right"; } ### legend(posleg,txtleg,col=colleg,lty=1,lwd=lwdleg,bty="o",bg=bgleg,box.col=bgleg,cex=cexleg) box() } ##Cumulative_frequency if((BOOL_Qsim | BOOL_Qobs) & BOOL_FilterZero){ kPlot <- kPlot+1; mar <- c(6,5,1,5); par(new=FALSE,mar=mar,las=0) xlim <- c(0,1); ylim <- range(log(c(Qobs[IndPeriod_Plot][SelectQobsNotZero & SelectQsimNotZero],OutputsModel$Qsim[IndPeriod_Plot][SelectQobsNotZero & SelectQsimNotZero])),na.rm=TRUE); seqDATA1 <- log(c(0.01,0.02,0.05,0.1,0.2,0.5,1,2,5,10,20,50,100,200,500,1000,2000,5000,10000)); seqDATA2 <- exp(seqDATA1); plot(0,0,type="n",xlim=xlim,ylim=ylim,xaxt="n",yaxt="n",xlab="",ylab="",main=""); ### abline(h=0,lty=2,col=grey(0.5)); ### abline(h=1,lty=2,col=grey(0.5)); axis(side=1,at=pretty(xlim),labels=pretty(xlim),cex.axis=cexaxis); par(las=0); mtext(side=1,text="non-exceedance prob. [-]",line=lineY,cex=cexlab); par(las=0); axis(side=2,at=seqDATA1,labels=seqDATA2,cex.axis=cexaxis); par(las=0); mtext(side=2,text=paste("flow ",plotunit,"",sep=""),line=lineY,cex=cexlab); par(las=0); txtleg <- NULL; colleg <- NULL; if(BOOL_Qobs){ DATA2 <- log(Qobs[IndPeriod_Plot][SelectQobsNotZero & SelectQsimNotZero]);
281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
SeqQuant <- seq(0,1,by=1/(length(DATA2))); Quant <- as.numeric(quantile(DATA2,SeqQuant,na.rm=TRUE)); Fn <- ecdf(DATA2); YY <- DATA2; YY <- YY[order( Fn(DATA2) )]; XX <- Fn(DATA2); XX <- XX[order( Fn(DATA2) )]; lines(XX,YY,lwd=1,col="black"); txtleg <- c(txtleg,"observed"); colleg <- c(colleg,"black"); } if(BOOL_Qsim){ DATA2 <- log(OutputsModel$Qsim[IndPeriod_Plot][SelectQobsNotZero & SelectQsimNotZero]); SeqQuant <- seq(0,1,by=1/(length(DATA2))); Quant <- as.numeric(quantile(DATA2,SeqQuant,na.rm=TRUE)); Fn <- ecdf(DATA2); YY <- DATA2; YY <- YY[order( Fn(DATA2) )]; XX <- Fn(DATA2); XX <- XX[order( Fn(DATA2) )]; lines(XX,YY,lwd=1,col="orangered"); txtleg <- c(txtleg,"simulated"); colleg <- c(colleg,"orangered"); } if(!is.null(BasinArea)){ Factor <- Factor_UNIT_M3S; axis(side=4,at=seqDATA1,labels=round(seqDATA2*Factor),cex.axis=cexaxis); par(las=0); mtext(side=4,paste("flow ","m3/s",sep=""),line=lineY,cex=cexlab); par(las=0); } legend("topleft",title="log scale",txtleg,col=colleg,lty=1,lwd=lwd,bty="o",bg=bgleg,box.col=bgleg,cex=cexleg) box() } ##Correlation_QQ if(BOOL_Qsim & BOOL_Qobs & BOOL_FilterZero){ kPlot <- kPlot+1; mar <- c(6,5,1,5); par(new=FALSE,mar=mar,las=0) ylim <- log(range(c(Qobs[IndPeriod_Plot][SelectQobsNotZero & SelectQsimNotZero],OutputsModel$Qsim[IndPeriod_Plot][SelectQobsNotZero & SelectQsimNotZero]),na.rm=TRUE)); plot(log(Qobs[IndPeriod_Plot][SelectQobsNotZero & SelectQsimNotZero]),log(OutputsModel$Qsim[IndPeriod_Plot][SelectQobsNotZero & SelectQsimNotZero]),type="p",pch=1,cex=0.9,col="black",xlim=ylim,ylim=ylim,xaxt="n",yaxt="n",xlab="",ylab="") abline(a=0,b=1,col="royalblue"); seqDATA1 <- log(c(0.01,0.02,0.05,0.1,0.2,0.5,1,2,5,10,20,50,100,200,500,1000,2000,5000,10000)); seqDATA2 <- exp(seqDATA1); axis(side=1,at=seqDATA1,labels=seqDATA2,cex=cexaxis); axis(side=2,at=seqDATA1,labels=seqDATA2,cex=cexaxis); par(las=0); mtext(side=1,paste("observed flow ",plotunit,"",sep=""),line=lineX,cex=cexlab); par(las=0); par(las=0); mtext(side=2,paste("simulated flow ",plotunit,"",sep=""),line=lineY,cex=cexlab); par(las=0); if(!is.null(BasinArea)){ Factor <- Factor_UNIT_M3S; axis(side=4,at=seqDATA1,labels=round(seqDATA2*Factor),cex.axis=cexaxis); par(las=0); mtext(side=4,paste("flow ","m3/s",sep=""),line=lineY,cex=cexlab); par(las=0); } legend("bottomright","log scale",lty=1,col=NA,bty="o",bg=bgleg,box.col=bgleg,cex=cexleg) box() } ##Empty_plots while(kPlot < iPlotMax){ kPlot <- kPlot+1; par(new=FALSE) plot(0,0,type="n",xlab="",ylab="",axes=FALSE) } ##Restoring_layout_options layout(1); }