Learn R Programming

CSIndicators (version 1.2.0)

CST_DayLength: Day length on 's2dv_cube' objects

Description

Day length on 's2dv_cube' objects

Usage

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

Value

An 's2dv_cube' object containing day length values expressed in hours in the element data, with the same dimensions as the input parameter 'data'.

Arguments

data

An 's2dv_cube' object object. The structure of the s2dv cube should have the standard structure with data, dims, coords and attrs.

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 dimension to compute the indicator. By default, it is set to 'time'. More than one dimension name matching the dimensions provided in the object data$data can be specified.

lat_dim

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

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.

ncores

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

...

Additional arguments passed to the aggregation function.

Author

Javier Corvillo, javier.corvillo@bsc.es

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.

References

: Forsythe, William C., Edward J. Rykiel Jr., Randal S. Stahl, Hsin-i Wu and Robert M. Schoolfield, 1995. A model comparison for daylength as a function of latitude and day of the year. Ecological Modeling 80:87-95.

Examples

Run this code
temp <- NULL
temp$data <- array(rnorm(100, mean = 300, sd = 5), 
                  c(member = 5, sdate = 3, time = 214, longitude = 2, latitude = 5))
temp$coords <- list(latitude = c(35, 40, 45, 50, 55), longitude = c(-5, 0))
variableT <- list(varName = 'tas', 
                 metadata = list(tas = list(units = 'K', long_name = '2m Temperature')))
temp$attrs <- list(Variable = variableT, 
                  Datasets = 'synthetic', 
                  when = Sys.time())
Dates <- c(seq(as.Date("2000-05-01"), as.Date("2000-11-30"), by = 'day'),
          seq(as.Date("2001-05-01"), as.Date("2001-11-30"), by = 'day'),
          seq(as.Date("2002-05-01"), as.Date("2002-11-30"), by = 'day'))
dim(Dates) <- c(sdate = 3, time = 214)
temp$attrs$Dates <- Dates
class(temp) <- "s2dv_cube"
DL <- CST_DayLength(temp)
DL_summer <- CST_DayLength(temp, start = list(21, 6), end = list(21, 9))

Run the code above in your browser using DataLab