|
|
Configs |
|
|
\ No newline at end of file |
|
|
Configs
|
|
|
|
|
|
|
|
|
[[_TOC_]]
|
|
|
|
|
|
# 1.1 Initialisation
|
|
|
|
|
|
### 1.1.1 Pantropical diversity (Hagen and Skeels et al 2021)
|
|
|
|
|
|
This function intialises a single species that occupies all non-arid equatorial grid cells.
|
|
|
Requires 3 traits: dispersal, temp, temp_width
|
|
|
Specify paramters: params$initialAbundance
|
|
|
|
|
|
~~~R
|
|
|
initial_abundance = params$initialAbundance
|
|
|
|
|
|
create_ancestor_species <- function(landscape, config) {
|
|
|
|
|
|
p_world <- raster::rasterFromXYZ(cbind(landscape$coordinates[which(landscape$coordinates[,2] > -23.5 & landscape$coordinates[,2] < 23.5),],
|
|
|
landscape$environment[which(landscape$coordinates[,2] > -23.5 & landscape$coordinates[,2] < 23.5), 1, drop = F]))
|
|
|
p_world <- extend(p_world, landscape$extent)
|
|
|
mesic_equatorial_cells <- as.character(Which(p_world, cells=T))
|
|
|
|
|
|
all_species <- list()
|
|
|
|
|
|
new_species <- create_species(NA, as.character(mesic_equatorial_cells), config)
|
|
|
new_species$traits[ , "dispersal"] <- 1
|
|
|
new_species$traits[ , "temp"] <- landscape$environment[mesic_equatorial_cells, "temp"]
|
|
|
new_species$traits[ , "prec"] <- 0
|
|
|
new_species$traits[ , "temp_width"] <- params$TW
|
|
|
all_species <- append(all_species, list(new_species))
|
|
|
|
|
|
return(all_species)
|
|
|
}
|
|
|
~~~
|
|
|
|
|
|
# 1.2 Dispersal
|
|
|
|
|
|
### 1.2.1 Pantropical diversity (Hagen and Skeels et al 2021)
|
|
|
|
|
|
This function draws the dispersal kernel from a Weibull distriution with shape and scale parameters.
|
|
|
Specify paramters: params$WeibullShape, params$WeibullScale
|
|
|
~~~R
|
|
|
|
|
|
get_dispersal_values <- function(n, species, landscape, config) {
|
|
|
values <- rweibull(n, shape = params$WeibullShape, scale = params$WeibullScale)
|
|
|
return(values)
|
|
|
}
|
|
|
~~~
|
|
|
|
|
|
# 1.3 Evolution
|
|
|
|
|
|
### 1.3.1 Pantropical diversity (Hagen and Skeels et al 2021)
|
|
|
|
|
|
This function evolves a single temperature-niche trait under a random walk (Brownian Motion) model.
|
|
|
Requires 1 trait: temp
|
|
|
Specify paramters: params$Tev
|
|
|
|
|
|
~~~R
|
|
|
apply_evolution <- function(species, cluster_indices, landscape, config) {
|
|
|
|
|
|
traits <- species[["traits"]]
|
|
|
traits[, "temp"] <- traits[, "temp"] + rnorm(1, mean = 0, sd = params$Tev)
|
|
|
|
|
|
# set bounds between 0 and 1 so the species can;t evolve a niche beyond that present in the data (all temp is scaled between 0 and 1)
|
|
|
if(any(traits[, "temp"] > 1)){traits[which(traits[,"temp"]>1), "temp"] <- 1}
|
|
|
if(any(traits[, "temp"] < 0)){traits[which(traits[,"temp"]<0), "temp"] <- 0}
|
|
|
|
|
|
|
|
|
return(traits)
|
|
|
|
|
|
}
|
|
|
|
|
|
~~~
|
|
|
|
|
|
# 1.4 Speciation
|
|
|
|
|
|
### 1.4.1 Pantropical diversity (Hagen and Skeels et al 2021)
|
|
|
|
|
|
This function increases divergence between populations by 0.1 at each timestep and speciation occurs after divergence crosses threshold S. Values < 1 mean populations seperate more slowly than they come back toegther, as populations that come into secondary contact seperate at rate of 1 per time step.
|
|
|
|
|
|
Specify paramters: params$S
|
|
|
Requires 2 traits: temp, temp_width
|
|
|
|
|
|
~~~R
|
|
|
divergence_threshold = params$S
|
|
|
|
|
|
get_divergence_factor <- function(species, cluster_indices, landscape, config) {
|
|
|
return(0.1)
|
|
|
}
|
|
|
~~~
|
|
|
|
|
|
# 1.5 Ecology
|
|
|
|
|
|
### 1.5.1 Pantropical diversity (Hagen and Skeels et al 2021)
|
|
|
|
|
|
This function determines whether species can occupy a grid cell based on the temperature niche trait and width as well as aridity. Species can occupy cells of the temp niche + or - the temp width. A further constraint is added where species cannot occupy arid grid cells.
|
|
|
|
|
|
Requires environment: temperature (temp) and aridity (prec)
|
|
|
|
|
|
~~~R
|
|
|
apply_ecology <- function(abundance, traits, landscape, config) {
|
|
|
temp_diff <- abs( traits[, "temp"] - landscape[, "temp"])
|
|
|
abundance <- temp_diff < traits[, "temp_width"]
|
|
|
abundance[which(landscape[, "prec"] > 0.5)] <- 0
|
|
|
return(abundance)
|
|
|
}
|
|
|
~~~ |
|
|
\ No newline at end of file |