View source: R/prepare_projection.R
| prepare_projection | R Documentation |
This function prepared data for model projections to multiple scenarios, storing the paths to the rasters representing each scenario.
prepare_projection(models = NULL, variable_names = NULL, present_dir = NULL,
past_dir = NULL, past_period = NULL, past_gcm = NULL,
future_dir = NULL, future_period = NULL,
future_pscen = NULL, future_gcm = NULL,
write_file = FALSE, filename = NULL,
raster_pattern = ".tif*")
models |
an object of class |
variable_names |
(character) names of the variables used to fit the
model or do the PCA in the |
present_dir |
(character) path to the folder containing variables that represent the current scenario for projection. Default is NULL. |
past_dir |
(character) path to the folder containing subfolders with variables representing past scenarios for projection. Default is NULL. |
past_period |
(character) names of the subfolders within |
past_gcm |
(character) names of the subfolders within |
future_dir |
(character) path to the folder containing subfolders with variables representing future scenarios for projection. Default is NULL. |
future_period |
(character) names of the subfolders within |
future_pscen |
(character) names of the subfolders within
|
future_gcm |
(character) names of the subfolders within |
write_file |
(logical) whether to write the object containing the paths
to the structured folders. This object is required for projecting models
across multiple scenarios using the |
filename |
(character) the path or name of the folder where the object
will be saved. This is only applicable if |
raster_pattern |
(character) pattern used to identify the format of raster files within the folders. Default is ".tif*". |
An object of class prepared_projection containing the following
elements:
Present, Past, and Future: paths to the variables structured in subfolders.
Raster_pattern: the pattern used to identify the format of raster files within the folders.
PCA: if a principal component analysis (PCA) was performed on the set of
variables with prepare_data(), a list with class "prcomp" will
be returned. See ?stats::prcomp() for details.
variables: names of the raw predictor variables used to project.
organize_future_worldclim()
# Import example of fitted_models (output of fit_selected())
data("fitted_model_maxnet", package = "kuenm2")
# Organize and structure future climate variables from WorldClim
# Import the current variables used to fit the model.
# In this case, SoilType will be treated as a static variable (constant
# across future scenarios).
var <- terra::rast(system.file("extdata", "Current_variables.tif",
package = "kuenm2"))
# Create a "Current_raw" folder in a temporary directory and copy the raw
# variables there.
out_dir_current <- file.path(tempdir(), "Current_raw")
dir.create(out_dir_current, recursive = TRUE)
# Save current variables in temporary directory
terra::writeRaster(var, file.path(out_dir_current, "Variables.tif"))
# Set the input directory containing the raw future climate variables.
# For this example, the data is located in the "inst/extdata" folder.
in_dir <- system.file("extdata", package = "kuenm2")
# Create a "Future_raw" folder in a temporary directory and copy the raw
# variables there.
out_dir_future <- file.path(tempdir(), "Future_raw")
# Organize and rename the future climate data, structuring it by year and GCM.
# The 'SoilType' variable will be appended as a static variable in each scenario.
# The files will be renamed following the "bio_" format
organize_future_worldclim(input_dir = in_dir,
output_dir = out_dir_future,
name_format = "bio_", variables = NULL,
static_variables = var$SoilType, mask = NULL,
overwrite = TRUE)
# Prepare projections using fitted models to check variables
pr <- prepare_projection(models = fitted_model_maxnet,
present_dir = out_dir_current,
past_dir = NULL,
past_period = NULL,
past_gcm = NULL,
future_dir = out_dir_future,
future_period = c("2041-2060", "2081-2100"),
future_pscen = c("ssp126", "ssp585"),
future_gcm = c("ACCESS-CM2", "MIROC6"),
write_file = FALSE,
filename = NULL,
raster_pattern = ".tif*")
pr
# Prepare projections using variables names
pr_b <- prepare_projection(models = NULL,
variable_names = c("bio_1", "bio_7", "bio_12"),
present_dir = out_dir_current,
past_dir = NULL,
past_period = NULL,
past_gcm = NULL,
future_dir = out_dir_future,
future_period = c("2041-2060", "2081-2100"),
future_pscen = c("ssp126", "ssp585"),
future_gcm = c("ACCESS-CM2", "MIROC6"),
write_file = FALSE,
filename = NULL,
raster_pattern = ".tif*")
pr_b
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.