Learn R Programming

CSIndicators (version 1.2.0)

DayLength: Day length on multidimensional array objects

Description

Day length computes the number of hours of daylight at a given latitude and day of the year. This can be used for computing other agricultural or epidemiological indicators where day length may affect the indicator's values.

Usage

DayLength(
  data,
  lat,
  dates = NULL,
  start = NULL,
  end = NULL,
  time_dim = "time",
  lat_dim = "latitude",
  ncores = NULL,
  fun = NULL,
  ...
)

Value

A multidimensional array with named dimensions containing day length expressed in hours.

Arguments

data

A multidimensional array with named dimensions.

lat

A vector of latitudes in degrees.

dates

A multidimensional array of dates with named dimensions matching the temporal dimensions on parameter 'data'. By default it is NULL, to select a period this parameter must be provided.

start

An optional parameter to define the initial date of the period to select from the data by providing a list of two elements: the initial date of the period and the initial month of the period. By default it is set to NULL and the indicator is computed using all the data provided in data.

end

An optional parameter to define the final date of the period to select from the data by providing a list of two elements: the final day of the period and the final month of the period. By default it is set to NULL and the indicator is computed using all the data provided in data.

time_dim

A character string indicating the name of the temporal dimension. By default, it is set to 'time'.

lat_dim

A character string indicating the name of the latitude dimension. By default, it is set to 'latitude'.

ncores

An integer indicating the number of cores to use in parallel computation.

fun

A function to be applied along the time dimension to aggregate the Day Length. By default, the mean Day Length is computed over time_dim. To keep the original temporal resolution (i.e., return values for each time step), set `fun = NULL`, in which case no aggregation is applied.

...

Additional arguments passed to the aggregation function.

Author

Javier Corvillo, javier.corvillo@bsc.es

Examples

Run this code
data <- array(rnorm(5 * 3 * 214 * 2), 
             c(member = 5, sdate = 3, time = 214, latitude = 2))
lat <- c(40, 35)
Dates <- c(seq(as.Date("01-05-2000", format = "%d-%m-%Y"), 
              as.Date("30-11-2000", format = "%d-%m-%Y"), by = 'day'),
          seq(as.Date("01-05-2001", format = "%d-%m-%Y"), 
              as.Date("30-11-2001", format = "%d-%m-%Y"), by = 'day'),
          seq(as.Date("01-05-2002", format = "%d-%m-%Y"), 
              as.Date("30-11-2002", format = "%d-%m-%Y"), by = 'day'))
dim(Dates) <- c(sdate = 3, time = 214)
# Compute daylength for all dates
DL <- DayLength(data, lat = lat, dates = Dates)
# Compute daylength for summer period only
DL_summer <- DayLength(data, lat = lat, dates = Dates, 
                      start = list(21, 6), end = list(21, 9))
# Compute mean daylength over time
DL_mean <- DayLength(data, lat = lat, dates = Dates, fun = mean)

Run the code above in your browser using DataLab