# rm(list = ls())
# Read raster model for Lepus californicus
model_path <- system.file("extdata/Lepus_californicus_cont.tif",
package = "bamm")
model <- raster::raster(model_path)
# Convert model to sparse
sparse_mod <- bamm::model2sparse(model = model,threshold=0.1)
# Compute adjacency matrix
adj_mod <- bamm::adj_mat(sparse_mod,ngbs=1)
# Initial points to start dispersal process
occs_lep_cal <- data.frame(longitude = c(-115.10417,
-104.90417),
latitude = c(29.61846,
29.81846))
# Convert to sparse the initial points
occs_sparse <- bamm::occs2sparse(modelsparse = sparse_mod,
occs = occs_lep_cal)
# Run the bam (sdm) simultation for 100 time steps
smd_lep_cal <- bamm::sdm_sim(set_A = sparse_mod,
set_M = adj_mod,
initial_points = occs_sparse,
nsteps = 10)
#----------------------------------------------------------------------------
# Predict species' distribution under suitability change
# scenarios (could be climate chage scenarios).
#----------------------------------------------------------------------------
# Read suitability layers (two suitability change scenarios)
layers_path <- system.file("extdata/suit_change",
package = "bamm")
niche_mods_stack <- raster::stack(list.files(layers_path,
pattern = ".tif$",
full.names = TRUE))
raster::plot(niche_mods_stack)
# Predict
new_preds <- predict(object = smd_lep_cal,
niche_layers = niche_mods_stack,
nsteps_vec = c(50,100))
# Generate the dispersal animation for time period 1 and 2
# \donttest{
if(requireNamespace("animation")){
ani_prd <- tempfile(pattern = "prediction_",fileext = ".gif")
#new_preds <- predict(object = smd_lep_cal,
# niche_layers = niche_mods_stack,
# nsteps_vec = c(10,10),
# animate=TRUE,
# filename=ani_prd,
# fmt="GIF")
}
# }
Run the code above in your browser using DataLab