SimVsObs: Comparison between observed and simulated variables

View source: R/plot_out.R

SimVsObsR Documentation

Comparison between observed and simulated variables

Description

Simple comparison between time series of observed and simulated variables. This function is specially designed to check the correct operation of the wrapper functions prepared by the user. The premise is as follows: if the user can generate a 'nice' graph (graphically evidencing the simulated and observed values, and obtaining finite numerical values for the objectives) then they can proceed with greater confidence to the hydroMOPSO optimisation step.

Usage


SimVsObs(sim,
         obs,
         obj.values,
         obj.names,
         var.names, 
         var.units, 
         legend.sim = "Simulated", 
         legend.obs = "Observed", 
         cal.period,
         warmup.period,
         full.period,
         xlim = NULL,
         ylim = NULL,
         main = "study case #1",
         analysis.period,
         digits.round = 8,
         col.obs = "black",
         col.sim = "mediumblue",
         lwd = 0.75,
         pch.obs = 15,
         cex.pt = 0.25,
         cex.main = 1,
         cex.lab = 1,
         cex.axis = 1,
         cex.leg = 1)

Arguments

sim

(list)
List with simulations of the output variables involved in the optimisation. The list must have as many elements as variables involved, each as a zoo class.

obs

(list)
List with observations of the output variables involved in the optimisation. The list must have as many elements as variables involved, each as a zoo class.

obj.values

(numeric)
Vector with values of the objectives considered in the optimisation.

obj.names

(character)
Vector with the names of the optimisation objectives.

var.names

(character)
Vector with the names of the output variables.

var.units

(character)
Vector with the units of measurement of the output variables.

legend.sim

(character)
Single character with an identifiable name for the simulated values in the output graph.
By default legend.sim = "Simulated".

legend.obs

(character)
Single character with an identifiable name for the observed values in the output graph.
By default legend.sim = "Observed".

warmup.period

(Date)
Vector with the dates of the warmup period.

cal.period

(Date)
Vector with the dates of the calibration period.

full.period

(Date)
Vector with the dates of the full period (warmup + calibration and/or verification).

xlim

(code)
ToDo

ylim

(code)
ToDo

main

(character)
Title for the plot, usually an identifiable name of the case study.
By default main = "study case #1".

analysis.period

(character)
The graph to be plotted is in verification or calibration.

digits.round

(numeric)
Number of decimal places to round Objs.values. By default digits.round = 8

col.obs

(character)
Colour to identify the time series of observed values obs.
By default col.obs = "black".

col.sim

(character)
Colour to identify the time series of simulated values obs.
By default col.obs = "mediumblue".

lwd

(numeric)
Line width for time series sim and obs.
By default lwd = 1.

pch.obs

(numeric)
Plotting symbol (pch) specification.
By default pch.obs = 15.

cex.pt

(numeric)
Expansion factor for the plotting symbol.
By default cex.pt = 1.

cex.main

(numeric)
Expansion factor for the main title.
By default cex.main = 1.

cex.lab

(numeric)
Expansion factor for x and y labels.
By default cex.lab = 1.

cex.axis

(numeric)
Expansion factor for the axis annotation.
By default cex.axis = 1.

cex.leg

(numeric)
Expansion factor for the text legend.
By default cex.leg = 1.

Value

No return value

Author(s)

Rodrigo Marinao Rivas ra.marinao.rivas@gmail.com, Mauricio Zambrano-Bigiarini, mzb.devel@gmail.com

See Also

hydroMOPSO

Examples


###############################################################################################

# This example is derived from example 5 of the hydroMOPSO function

library(hydroMOPSO)
library(airGR)
library(hydroTSM)
library(hydroGOF)

# RTL basin ------------------------------------------------
basin.area <- 1415025887 # basin area in square meters

# Load time series -----------------------------------------
data(Trancura9414001plus) # Load RTL data set

# Dates ----------------------------------------------------
dates.raw <- Trancura9414001plus[,"Date"]
dates <- as.Date(dates.raw) # dates

# INPUTS time series ---------------------------------------

# Precipitation (input variable)
ts.pcp.raw <- Trancura9414001plus[,"P_mm"]
ts.pcp <- zoo(ts.pcp.raw, dates)

# Potential EvapoTranspiration (input variable)
ts.pet.raw <- Trancura9414001plus[,"PET_mm"]
ts.pet <- zoo(ts.pet.raw, dates)

# OUTPUTS time series --------------------------------------
# Observed streamflow (calibration output variable)
ts.qobs.raw <- Trancura9414001plus[,"Qobs_m3s"]
ts.qobs <- zoo(ts.qobs.raw, dates)

# Parameter ranges and noCal parameters --------------------

lower <- c("X1" = 0.01, "X2" = -100, "X3" = 0.01, "X4" = 0.5) # parameter range lower threshold
upper <- c("X1" = 1200, "X3" =  100, "X3" = 5000, "X4" = 5  ) # parameter range upper threshold

noCal.param <- (lower + upper)/2 # uncalibrated parameters

# Names and units of observed output variables -------------

char.obs.names <- "Streamflow"
char.obs.units <- "m3/s"

# Objectives names -----------------------------------------

char.objs.names <- c("KGE2012_Q", "KGEGarcia_Q")

# Calibration dates and subsetting -------------------------

WarmUpCal.dates <- dip("1979-01-01", "1979-12-31") # WarmUp for Calibration
Cal.dates <- dip("1980-01-01", "1999-12-31") # Calibration
FullCal.dates <- dip("1979-01-01", "1999-12-31") # WarmUp + Calibration

start.FullCal <- FullCal.dates[1]
end.FullCal   <- FullCal.dates[length(FullCal.dates)]

# INPUTS time series ---------------------------------------

# Precipitation (input variable)
ts.pcp.FullCal <- window(ts.pcp, start = start.FullCal, end = end.FullCal) # subsetting pcp

# Potential EvapoTranspiration (input variable)
ts.pet.FullCal <- window(ts.pet, start = start.FullCal, end = end.FullCal) # subsetting pet

# OUTPUTS time series --------------------------------------

# Observed streamflow (calibration output variable)
ts.qobs.FullCal <- window(ts.qobs, start = start.FullCal, end = end.FullCal) # subsetting qobs

list.obs.Cal <- list(Q = ts.qobs.FullCal)

# Structuring Inputs and Options of GR4J model -------------

InputsModel.Cal <- CreateInputsModel(FUN_MOD= RunModel_GR4J, 
                                     DatesR= as.POSIXlt(FullCal.dates),
                                     Precip= coredata(ts.pcp.FullCal), 
                                     PotEvap= coredata(ts.pet.FullCal))

RunOptions.Cal <- CreateRunOptions(FUN_MOD= RunModel_GR4J, InputsModel= InputsModel.Cal,
                                   IndPeriod_Run = 1:length(FullCal.dates), warnings = FALSE)

# Checking Wrapper function in calibration -----------------

noCal.results.Cal <- GR4JExampleCal(param.values = noCal.param,
                                    Obs = list.obs.Cal,
                                    Objs.names = char.objs.names,
                                    var.names = char.obs.names, 
                                    var.units = char.obs.units,
                                    warmup.period  = WarmUpCal.dates,
                                    cal.period = Cal.dates,
                                    full.period = FullCal.dates,
                                    InputsModel = InputsModel.Cal, 
                                    RunOptions = RunOptions.Cal,
                                    area = basin.area)

noCal.sim.Cal <- noCal.results.Cal[["sim"]]
noCal.objs.Cal <- noCal.results.Cal[["Objs"]]

dev.new()
SimVsObs(sim = noCal.sim.Cal, obs = list.obs.Cal,
         obj.values = noCal.objs.Cal, obj.names = char.objs.names,
         var.names = char.obs.names, var.units = char.obs.units, 
         legend.sim = "Simulated", legend.obs = "Observed", 
         warmup.period  = WarmUpCal.dates, cal.period = Cal.dates, full.period = FullCal.dates,
         main = "...just checking GR4JExampleCal function", analysis.period = "calibration",
         digits.round = 4)


hydroMOPSO documentation built on June 18, 2025, 9:15 a.m.