import4D: Imports predictive variables defined for different times

Description Usage Arguments Value Author(s)

View source: R/import4D.R

Description

Imports raster layers representing different variables at different times, and applies to them a common mask considering all their respective empty cells. The raster layers should be stored as individual files with any extension readable by the stack function, including ".asc", ".tif", and many others.

Requirements

The raster layers to import must fulfill the following requirements:

Data organization

When working with SDMs across time, a set of variables are dynamic and change over time (i.e. climate), while others are static do not change significantly over time (i.e. topography). This function allows to select static and dynamic variables through the arguments static.vars and dynamic.vars. This way the user does not need to have the static variables duplicated as many times as time steps (years, months, etc) are considered in the analysis.

The data can be organized as desired by the user, as long as all files are inside the folder defined in the folder argument. Any of these methods is recommended:

Using a raster template

The argument raster.template allows to select a given raster layer with a particular resolution and a given coordinate reference system (that can alternatively be provided through the argument raster.template.crs). If selected, all imported variables will be reprojected to the coordinate reference system of the template, and rescaled to the extension and resolution of the template. Take in mind that for large datasets this operation might take a while, and may require a large amount of RAM memory.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
import4D(
raster.template = NULL,
raster.template.crs = NULL,
folder = here::here(),
dynamic.vars = NULL,
static.vars = NULL,
vars.crs = NULL,
times = NULL,
to.data.frame = FALSE
)

Arguments

raster.template

Complete path to a raster file or raster object to be used as a template to reproject and rescale all imported variables.

raster.template.crs

Character string defining a coordinate reference system of the template as per the PROJ.4 standard. Only required when the raster format does not contain this information (as it happens with .asc files). The default crs is "+init=epsg:4326", valid for data using latitude and longitude degrees as coordinates, and the global datum WGS84. Check the help file of crs for further details. The argument can be set to NULL, or "unknown" if the coordinate reference system is unknown.

folder

Character string, path (without final slash) to the folder where the raster files, or folder containing the raster files, are stored. Defaults to the given working folder of the R session.

dynamic.vars

Character vector, names of the variables that change over time. For example c("temperature", "rainfall").

static.vars

Character vector, names of the variables that change over time. For example c("slope", "aspect").

vars.crs

Character string, definition of the coordinate reference system of the variables. If not provided, and not included in the file formats, the function cannot reproject the static and dynamic variables to the coordinate reference system of raster.template.

times

Character vector with the names of the times represented by the raster layers. For example c("2010", "2020") or c("january", "february"). These names must be available either in the names of the files, or the names of the folders where the files are. Names are matched as lower-case.

to.data.frame

Boolean. If TRUE, the function returns a large data frame were cases represent raster cells over space and time, and columns represent environmental variables. The values of the times argument are included in the time column.

Value

If no raster.template is provided, a named list, with slots named after times containing raster bricks with the given variables. If raster.template is provided, a named list with raster bricks. If to.data.frame = TRUE, a single dataframe with the values of all the valid cells available in the raster layers.

Author(s)

Blas Benito <blasbenito@gmail.com>. The functions stack, brick, crs, projectRaster and resample are authored by Robert J. Hijmans.


BlasBenito/SDMworkshop documentation built on March 4, 2020, 4:16 a.m.