Get Started with airGR"


airGR is a package that brings into the R software the hydrological modelling tools used and developed at the Catchment Hydrology Research Group at INRAE (France), including the GR rainfall-runoff models that can be applied either on a lumped or semi-distributed way. A snow accumulation and melt model (CemaNeige) and the associated functions for the calibration and evaluation of models are also included. Each model core is coded in Fortran to ensure low computational time. The other package functions (i.e. mainly the calibration algorithm and the efficiency criteria calculation) are coded in R.

The airGR package has been designed to fulfill two major requirements: to facilitate the use by non-expert users and to allow flexibility regarding the addition of external criteria, models or calibration algorithms. The names of the functions and their arguments were chosen to this end. airGR also contains basics plotting facilities.

Seven hydrological models and one snow melt and accumulation model are implemented in airGR. The hydrological models can be applied either on a lumped way or on a semi-distributed way (on sub-catchments). The snow model can either be used alone or with the daily or hourly hydrological models. Naturally each hydrological model can also be used alone.

The models can be called within airGR using the following functions:

The GRP forecasting model and the Otamin predictive uncertainty tool are not available in airGR.

In this vignette, we show how to prepare and run a calibration and a simulation with airGR hydrological models.

Loading data

In the following example, we use a data sample contained in the package. For real applications, the user has to import its data into R and to prepare it with an adequate data.frame format as described below.

First, it is necessary to load the airGR package:


Below is presented an example of a data.frame of daily hydrometeorological observations time series for a fictional catchment included in the airGR package that contains:

summary(BasinObs, digits = 2)

The usual functions (e.g. read.table()) can be used to load real-case data sets.

Preparation of functions inputs

To run a model, the functions of the airGR package (e.g. the models, calibration and criteria calculation functions) require data and options with specific formats.

To facilitate the use of the package, there are several functions dedicated to the creation of these objects:

InputsModel object

To run a GR hydrological model or CemaNeige, the user has to prepare the input data with the CreateInputsModel() function. As arguments, this function needs the function name corresponding to the model the user wants to run, a vector of dates, a vector of precipitation and a vector of potential evapotranspiration.

In the example below, we already have the potential evapotranspiration. If the user does not have these data, it is possible to compute it with the Oudin's formula with the PE_Oudin() function (this function only needs Julian days, daily average air temperature and latitude).

Missing values (NA) of precipitation (or potential evapotranspiration) are not allowed.

InputsModel <- CreateInputsModel(FUN_MOD = RunModel_GR4J, DatesR = BasinObs$DatesR,
                                 Precip = BasinObs$P, PotEvap = BasinObs$E)

RunOptions object

The CreateRunOptions() function allows to prepare the options required to the RunModel*() functions, which are the actual models functions.

The user must at least define the following arguments:

To select a period for which the user wants to run the model, select the corresponding indexes for different time periods (not the POSIXt dates), as follows:

Ind_Run <- seq(which(format(BasinObs$DatesR, format = "%Y-%m-%d") == "1990-01-01"), 
               which(format(BasinObs$DatesR, format = "%Y-%m-%d") == "1999-12-31"))

The initialization of hydrological models is of the utmost importance. Indeed, an inaccurate initialization causes poor quality discharge simulations during the earliest stages of the running period. For example, in the GR models, by default, the production and the routing store levels store level are respectively set to 30 % and 50 % of their capacity, which may be far from their ideal value. Two solutions are offered to accurately initialize the GR models in airGR: manually predefining the initial states (e.g. from a previous run) or running the models during a warm up period before the actual running period. It is generally advised to set up this warm up period to be equal or superior to one year.

As a consequence, it is possible to define in CreateRunOptions() the following arguments:

RunOptions <- CreateRunOptions(FUN_MOD = RunModel_GR4J,
                               InputsModel = InputsModel, IndPeriod_Run = Ind_Run,
                               IniStates = NULL, IniResLevels = NULL, IndPeriod_WarmUp = NULL)

The CreateRunOptions() function returns warnings if the default initialization options are used:

InputsCrit object

The CreateInputsCrit() function allows to prepare the input in order to calculate a criterion. It is possible to define the following arguments:

Missing values (NA) are allowed for observed discharge.

It is possible to compute a composite criterion (e.g. the average between NSE computed on discharge and NSE computed on log of discharge). In this case, users have to provide lists to the following arguments (some of the are optional): FUN_CRIT, Obs, VarObs, BoolCrit, transfo, Weights.

InputsCrit <- CreateInputsCrit(FUN_CRIT = ErrorCrit_NSE, InputsModel = InputsModel, 
                               RunOptions = RunOptions, VarObs = "Q", Obs = BasinObs$Qmm[Ind_Run])

CalibOptions object

Before using the automatic calibration tool, the user needs to prepare the calibration options with the CreateCalibOptions() function. For that, it is necessary to define the following arguments:

CalibOptions <- CreateCalibOptions(FUN_MOD = RunModel_GR4J, FUN_CALIB = Calibration_Michel)


The evaluation of the quality of a simulation is estimated through the calculation of criteria. These criteria can be used both as objective-functions during the calibration of the model, or as a measure for evaluating its performance on a control period.

The package offers the possibility to use different criteria:

It is also possible to create user-defined criteria. For doing that, it is only necessary to define the function in R following the same syntax as the criteria functions included in airGR.


The objective of the calibration algorithm is to identify the model parameters: by comparing the model outputs with observed data, this algorithm determines the combination of parameters that represents the best the behavior of the watershed.

In the airGR package, a function called Calibration_Michel() is implemented. This functions allows running a calibration with the package models. The calibration algorithm optimizes the error criterion selected as objective-function. This algorithm works in two steps:

  1. a screening of the parameters space is performed using either a rough predefined grid or a user-defined list of parameter sets
  2. a simple steepest descent local search algorithm is performed from the best set of parameters found at the first step
OutputsCalib <- Calibration_Michel(InputsModel = InputsModel, RunOptions = RunOptions,
                                   InputsCrit = InputsCrit, CalibOptions = CalibOptions,
                                   FUN_MOD = RunModel_GR4J)
Param <- OutputsCalib$ParamFinalR

The Calibration_Michel() function is the only one implemented in the airGR package to calibrate the model, but the user can implement its own calibration function. Two vignettes explain how it can be done (2.1 Plugging in new calibration and 2.2 MCMC parameter estimation).

The Calibration_Michel() function returns a vector with the parameters of the chosen model, which means that the number of values can differ depending on the model that is used. It is possible to use the Calibration_Michel() function with user-implemented hydrological models.


This step assesses the predictive capacity of the model. Control is defined as the estimation of the accuracy of the model on data sets that are not used in its construction, and in particular its calibration. The classical way to perform a control is to keep data from a period separated from the calibration period. If possible, this control period should correspond to climatic situations that differ from those of the calibration period in order to better point out the qualities and weaknesses of the model. This exercise is necessary for assessing the robustness of the model, that is to say its ability to keep stable performances outside of the calibration conditions.

Performing a model control with airGR is similar to running a simulation (see below), followed by the computation of one or several performance criteria.


Simulation run

To run a model, the user has to use the RunModel*() functions (InputsModel, RunOptions and parameters). All the data needed have already been prepared in the previous steps defined in this guide.

OutputsModel <- RunModel_GR4J(InputsModel = InputsModel, RunOptions = RunOptions, Param = Param)

Results preview

Although it is possible for the user to design its own graphics from the outputs of the RunModel*() functions, the airGR package offers the possibility to make use of the plot() function. This function returns a dashboard of results including various graphs (depending on the model used):

plot(OutputsModel, Qobs = BasinObs$Qmm[Ind_Run])

Moreover, if the CemaNeige model is used, the air temperature and the simulated snowpack water equivalent time series are plotted.

Efficiency criterion

To evaluate the efficiency of the model, it is possible to use the same criterion as defined at the calibration step or to use another criterion.

OutputsCrit <- ErrorCrit_NSE(InputsCrit = InputsCrit, OutputsModel = OutputsModel)
OutputsCrit <- ErrorCrit_KGE(InputsCrit = InputsCrit, OutputsModel = OutputsModel)


Try the airGR package in your browser

Any scripts or data that you put into this service are public.

airGR documentation built on March 18, 2022, 6:47 p.m.