Methods to compute temperature indices over a time series

temperature(object, ...)

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

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

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

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

Arguments

object

a numeric vector with the maximum temperature, or a data.frame with geographical coordinates (lonlat), or an object of class sf with geometry 'POINT' or 'POLYGON', or an array with two dimensions containing the maximum and minimum temperature, in that order. See details

...

additional arguments passed to methods. See details

tmin

a numeric vector with the minimum temperature

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 temperature indices:

maxDT

maximun day temperature (degree Celsius)

minDT

minimum day temperature (degree Celsius)

maxNT

maximun night temperature (degree Celsius)

minNT

minimum night temperature (degree Celsius)

DTR

diurnal temperature range (mean difference between DT and NT (degree Celsius))

SU

summer days, number of days with maximum temperature > 30 (degree Celsius)

TR

tropical nights, number of nights with maximum temperature > 25 (degree Celsius)

CFD

consecutive frosty days, number of days with temperature bellow 0 degree Celsius

WSDI

maximum warm spell duration, consecutive days with temperature > 90th percentile

CSDI

maximum cold spell duration, consecutive nights with temperature < 10th percentile

T10p

the 10th percentile of night tempeture (degree Celsius)

T90p

the 90th percentile of day tempeture (degree Celsius)

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. For data.frame, array and sf methods

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 temperature data to be fetched. If data.from is 'nasapower', the temperature can be adjusted to 2 m, the default, c("T2M_MAX", "T2M_MIN") or 10 m c("T10M_MAX", "T10M_MIN")

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

# S3 Methods

The array method assumes that object contains climate data available in your R section; this requires an array with two dimensions, 1st dimension contains the day temperature and 2nd dimension the night temperature, see help("temp_dat", package = "climatrends") for an example on input structure.

The data.frame and the sf methods assumes that the climate data will be 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

See also

Other temperature functions: ETo(), GDD(), crop_sensitive()

Examples

# the default method
data("innlandet", package = "climatrends")

# a single temporal observation
temperature(innlandet$tmax, innlandet$tmin)
#>    maxDT  minDT maxNT  minNT   DTR    SU    TR   CFD  WSDI  CSDI   T10p  T90p
#>    <dbl>  <dbl> <dbl>  <dbl> <int> <int> <int> <int> <int> <int>  <dbl> <dbl>
#> 1: 15.13 -14.86  6.77 -19.25     6     0     0   115     4     5 -15.81  9.09

# return as timeseries with 30-day intervals
temperature(innlandet$tmax, 
            innlandet$tmin, 
            dates = innlandet$dates,
            timeseries = TRUE, 
            intervals = 30)
#>        id       date index  value
#>     <int>     <date> <chr>  <dbl>
#> 1:      1 2019-01-01 maxDT  -0.15
#> 2:      1 2019-01-01 minDT -14.86
#> 3:      1 2019-01-01 maxNT  -3.41
#> 4:      1 2019-01-01 minNT -18.67
#> 5:      1 2019-01-01   DTR   4.35
#> ---                              
#> 68:     1 2019-05-31   CFD   3.00
#> 69:     1 2019-05-31  WSDI   2.00
#> 70:     1 2019-05-31  CSDI   3.00
#> 71:     1 2019-05-31  T10p   0.20
#> 72:     1 2019-05-31  T90p  11.14

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

# array method
data("temp_dat", package = "climatrends")

temperature(temp_dat,
            day.one = "2013-10-28",
            span = 12)
#>     maxDT minDT maxNT minNT   DTR    SU    TR   CFD  WSDI  CSDI  T10p  T90p
#>     <dbl> <dbl> <dbl> <dbl> <int> <int> <int> <int> <int> <int> <dbl> <dbl>
#> 1:  33.50 33.20  8.40  8.20    25    12     0     0     5     2  8.21 33.50
#> 2:  34.90 34.60  9.50  8.90    25    12     0     0     6     2  8.91 34.90
#> 3:  32.30 31.70  8.50  8.00    23    12     0     0     8     2  8.01 32.00
#> 4:  27.50 26.90  2.10  1.50    25     0     0     0     2     5  1.60 27.40
#> 5:  32.80 32.00  6.40  5.70    26    12     0     0     2     3  5.70 32.58
#> 6:  27.60 26.90  6.50  5.90    20     0     0     0     2     2  6.01 27.40
#> 7:  32.80 32.00  6.40  5.70    26    12     0     0     2     3  5.70 32.58
#> 8:  31.90 31.00  4.90  4.60    26    12     0     0     2     2  4.61 31.57
#> 9:  32.60 31.30  5.10  4.30    27    12     0     0     2     3  4.30 32.27
#> 10: 28.70 28.00  4.40  2.70    24     0     0     0     2     2  2.81 28.50