General functions and methods to concatenate climate data across a time series

get_timeseries(object, day.one, ...)

# S3 method for default
get_timeseries(
  object,
  day.one,
  span = NULL,
  last.day = NULL,
  as.matrix = FALSE,
  data.from = "nasapower",
  ...
)

# S3 method for matrix
get_timeseries(object, day.one, span = NULL, last.day = NULL, ...)

# S3 method for array
get_timeseries(object, day.one, span = NULL, last.day = NULL, ...)

Arguments

object

a data.frame (or any other object that can be coerced to data.frame) with geographical coordinates (lonlat), or an object of class sf with geometry 'POINT' or 'POLYGON', or a named matrix with climate data, or an array with two dimensions for max and min temperature. See details.

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

...

additional arguments passed to methods. See details.

span

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

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

as.matrix

logical, optional, to return a matrix or array instead of a data.frame

data.from

character, for the source of climate data. See details.

Value

A list with class clima_ls with data.frame(s) with the class clima_df

Details

The default method and the sf method assumes that the climate data will be fetched from an remote (cloud) data.from.

The matrix method assumes that the climate data was previously handled and will be inputted in the format of a named matrix. See help("modis", "climatrends") for examples.

Available remote sources to pass data.from: "nasapower"

Additional arguments:

pars: character vector of solar, meteorological or climatology parameters to download. See help("parameters", "nasapower") when data.from = "nasapower".

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

Examples

if (FALSE) { # interactive()
# Using local sources
# an array with temperature data
data("temp_dat", package = "climatrends")

set.seed(9271)
span <- as.integer(runif(10, 6, 15))

get_timeseries(temp_dat, "2013-10-28", span = span)

# matrix with precipitation data
data("rain_dat", package = "climatrends")

get_timeseries(rain_dat, "2013-10-28", span = span)

# \donttest{
# data can be returned as matrix
library("sf")
# Fetch data from NASA POWER using 'sf' method
data("lonlatsf", package = "climatrends")

g <- get_timeseries(object = lonlatsf,
                    day.one = "2018-05-16",
                    last.day = "2018-05-30",
                    pars = c("PRECTOTCORR", "T2M"),
                    as.matrix = TRUE)
# }
}