Methods to compute rainfall indices over a time series

rainfall(object, ...)

# S3 method for default
rainfall(object, ..., timeseries = FALSE)

# S3 method for data.frame
rainfall(object, day.one, span = NULL, ..., timeseries = FALSE)

# S3 method for matrix
rainfall(object, day.one, span = NULL, ..., timeseries = FALSE)

# S3 method for sf
rainfall(object, day.one, span = NULL, ..., timeseries = FALSE, as.sf = TRUE)

Arguments

object

a numeric vector with precipitation data or a data.frame with geographical coordinates (lonlat), or an object of class sf with geometry 'POINT' or 'POLYGON', or a named matrix with precipitation data. See details.

...

additional arguments passed to methods. See details.

timeseries

logical, FALSE for a single point time series observation or TRUE for a time series based on intervals

day.one

a vector of class Date or any other object that can be coerced to Date (e.g. integer, character YYYY-MM-DD) for the starting day to capture the climate data

span

an integer or a vector with integers (optional if last.day is given) for the length of the time series to be captured

as.sf

logical, to return an object of class 'sf'

Value

A dataframe with rainfall indices:

MLDS

maximum length of consecutive dry day, rain < 1 mm (days)

MLWS

maximum length of consecutive wet days, rain >= 1 mm (days)

R10mm

number of heavy precipitation days 10 >= rain < 20 mm (days)

R20mm

number of very heavy precipitation days rain >= 20 (days)

Rx1day

maximum 1-day precipitation (mm)

Rx5day

maximum 5-day precipitation (mm)

R95p

total precipitation when rain > 95th percentile (mm)

R99p

total precipitation when rain > 99th percentile (mm)

Rtotal

total precipitation (mm) in wet days, rain >= 1 (mm)

SDII

simple daily intensity index, total precipitation divided by the number of wet days (mm/days)

Details

#' Additional arguments:

intervals: an integer (no lower than 5), for the days intervals when timeseries = TRUE

last.day: optional to span, an object of class Date or any other object that can be coerced to Date (e.g. integer, character YYYY-MM-DD) for the last day of the time series

dates: a character (or Date or numeric) vector for the dates of tmax and tmin in the default method

data.from: character for the source of remote data. Current remote source is: 'nasapower'

pars: character vector for the precipitation data to be fetched. If data.from is 'nasapower', the default precipitation parameter is "PRECTOTCORR".

days.before: optional, an integer for the number of days before day.one to be included in the timespan.

# S3 Methods

The matrix method assumes that object contains climate data available in your R section; see help("rain_dat", package = "climatrends") for an example on input structure.

The data.frame and the sf methods assumes that the climate data will e fetched from a remote (cloud) source that be adjusted using the argument data.from.

When timeseries = TRUE, an id is created, which is the index for the rownames of the inputted object.

References

Aguilar E., et al. (2005). Journal of Geophysical Research, 110(D23), D23107. doi:10.1029/2005JD006119

Examples

# A vector with precipitation data
set.seed(987219)
rain <- runif(50, min = 0, max = 6)

rainfall(rain)
#>     MLDS  MLWS R10mm R20mm Rx1day Rx5day  R95p  R99p Rtotal  SDII
#>    <int> <int> <int> <int>  <dbl>  <dbl> <dbl> <dbl>  <dbl> <dbl>
#> 1:     2    15     0     0   5.79  21.31 17.02  5.79 153.17  3.55

# Return as timeseries with intervals of 7 days
dates <- 17650:17699
rainfall(rain, dates = dates, timeseries = TRUE, intervals = 7)
#>        id       date  index value
#>     <int>     <date>  <chr> <dbl>
#> 1:      1 2018-04-29   MLDS  1.00
#> 2:      1 2018-04-29   MLWS  4.00
#> 3:      1 2018-04-29  R10mm  0.00
#> 4:      1 2018-04-29  R20mm  0.00
#> 5:      1 2018-04-29 Rx1day  5.04
#> ---                              
#> 66:     1 2018-06-10 Rx5day 15.99
#> 67:     1 2018-06-10   R95p  5.79
#> 68:     1 2018-06-10   R99p  5.79
#> 69:     1 2018-06-10 Rtotal 20.14
#> 70:     1 2018-06-10   SDII  3.49

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

# the matrix method
data("rain_dat", package = "climatrends")

rainfall(rain_dat,
         day.one = "2013-10-28",
         span = 12)
#>      MLDS  MLWS R10mm R20mm Rx1day Rx5day  R95p  R99p Rtotal  SDII
#>     <int> <int> <int> <int>  <dbl>  <dbl> <dbl> <dbl>  <dbl> <dbl>
#> 1:      9     1     0     0   2.41   2.41  2.41  2.41   2.41  2.41
#> 2:      9     1     0     0   2.87   2.87  2.87  2.87   2.87  2.87
#> 3:     12     0     0     0   0.00   0.00  0.00  0.00   0.00  0.00
#> 4:     12     0     0     0   0.00   0.00  0.00  0.00   0.00  0.00
#> 5:     12     0     0     0   0.00   0.00  0.00  0.00   0.00  0.00
#> 6:     12     0     0     0   0.00   0.00  0.00  0.00   0.00  0.00
#> 7:     12     0     0     0   0.00   0.00  0.00  0.00   0.00  0.00
#> 8:     12     0     0     0   0.00   0.00  0.00  0.00   0.00  0.00
#> 9:     12     0     0     0   0.00   0.00  0.00  0.00   0.00  0.00
#> 10:    12     0     0     0   0.00   0.00  0.00  0.00   0.00  0.00