Description Usage Arguments Value Author(s)
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:
Same extension and resolution.
Same coordinate reference system (crs). It it is not included in the files (usually the case with .asc files), it can be defined through the argument vars.crs
.
Variable names must not be nested. For example, "temp" is nested in "temperature", and therefore the function will be unable to separate both. Howeve, non-nested names, such as "temp" and "prec" will work totally fine.
The variable name must contain a string representing the time step. Valid examples are "var_name_2010", "varName_January". Please note that string matching is case INSENSITIVE, and therefore time-step names such as "january" and "January" will be grouped together automatically.
All variables must be available for every time-step. The function does not specifically check this assumption, and errors may arise from its violation.
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:
All files stored in the same folder, with a name of the type name_time
for the dynamic variables, and name
for the static ones. For example, the folder "variables" could have inside the files "temperature_2010.tif", "temperature_2011.tif", and "slope.tif".
Files stored in folders with the variable names, and files named with the time name. For example, the folder "dynamic/temperature" could have the files "2010.tif", "2011.tif", and the folder "static" could have the file "slope.tif"
Files stored in variables named after the time steps. For example, the folder "2010" would have the file "temperature.tif" for 2010, and the folder "2011" would have the file "temperature.tif" for 2011, while the "static" folder would have the file "slope.tif".
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.
1 2 3 4 5 6 7 8 9 10 |
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 |
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 |
static.vars |
Character vector, names of the variables that change over time. For example |
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 |
times |
Character vector with the names of the times represented by the raster layers. For example |
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 |
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.
Blas Benito <blasbenito@gmail.com>. The functions stack
, brick
, crs
, projectRaster
and resample
are authored by Robert J. Hijmans.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.