knitr::opts_chunk$set(
  message = FALSE,
  warning = FALSE,
  fig.height = 6,
  fig.width = 6,
  fig.align = "center",
  echo = TRUE,
  collapse = TRUE,
  comment = "#>"
)

options(rmarkdown.html_vignette.check_title = FALSE)
set.seed(123)

Introduction

This is a detailed description of the functioning of the app and of the diveRpine package. We add some notes to modify and customize the app. This's a live document.

Landscape configuration

The first step is creating a virtual landscape with different land-uses. By default diveRpine uses four different land-uses: pine plantation, natural forest, cropland and others. To create the virtual landscape, diveRpine uses the auxiliary function create_landscape(). It generates a raster of 13356 ncell (106 rows and 126 cols) (Figure \@ref(fig:empty)).

library(diveRpine) 
library(tidyverse) 
library(raster) 
library(landscapeR) 
library(knitr) 
library(kableExtra) 
library(sf) 
library(viridis)
empty_landscape <- diveRpine::create_landscape()
plot(empty_landscape, legend = FALSE, col = "#FFFFe5")

Target pine-plantation

The next step is to configure the target pine-plantation. The user has to specify several features of the target pine-plantation:

For instance, a user could select a pine plantation size of 1000 ha (pp_size) with a low tree density (\< 500 tree/ha). The land use previous to the establishment of the pine plantation was Natural Forest (oak). The target pine plantation is located at 1400 m.a.s.l. and with an annual radiation of 4.5 GJm^-2^.

# Here there are some inputs needed for manual rendering (#not run)
input <- list()

# Select pine size
pp_size <- 1000
pp_den <- "low" 
pp_den_den <- 100 
pp_use <- "Oak"
elev <- 1400
rad <- 4.5

input$pp_size <- pp_size

The app creates a pine plantation patch, with the features selected by the users (Figure \@ref(fig:pine)).

# position
position_pine <- matrix(
  c(
    nrow(empty_landscape) / 2,
    ncol(empty_landscape) / 2
  ),
  ncol = 2, nrow = 1
)
# Create pine plantation target
pine <- landscapeR::makePatch(empty_landscape,
  val = 1, rast = TRUE, bgr = 0,
  size = input$pp_size,
  spt = position_pine
)

plot(pine, legend = FALSE, axes = FALSE, col = c("#FFFFe5", "#a1d99b"))

Natural forests

Then, several natural forests patches are created according to user selection. Before, the position of the natural forests are established using the free background space. The position(s) depends on the number of natural forest patch selected by the users. For instance, a user could select 5 natural forest patches (nf_n) with a size range between 100-200 ha (nf_size).

#### Get the positions for the creation of the NF patches.
nf_n <- 5
input$nf_n <- nf_n

#### Get the positions for the creation of the NF patches.
positions_nf <-
  sample(
    which(t(raster::as.matrix(pine) == 0)), nf_n
  )


#### Generate the sizes of the natural forests patch
nf_size <- c(100, 200)
input$nf_size <- nf_size

Then, the user select the range sizes of the natural forests patches.

nf_sizes <-
  round(
    runif(
      nf_n,
      input$nf_size[1],
      input$nf_size[2]
    ),
    digits = 0
  )

Natural forest patches are added to the virtual landscape (Figure \@ref(fig:pineOak)).

##   pine_oak
pine_oak <- makeClass(pine,
  val = 2, rast = TRUE,
  npatch = nf_n,
  pts = positions_nf,
  size = nf_sizes
)
plot(pine_oak, legend = FALSE, axes = FALSE, 
     col = c("#FFFFe5", "#a1d99b", "green"))
#n_crops <- sample(3:8, size = 1)
n_crops <- 4
set.seed(123)
crops_size <-
  sample(
    10:ceiling(
      length(which(t(raster::as.matrix(pine_oak)) == 0)) * 0.05
    ),
    size = n_crops
  )

landscape <-
  makeClass(pine_oak,
    val = 3, rast = TRUE,
    npatch = n_crops,
    size = crops_size
  )

plot(landscape,
  legend = FALSE, axes = FALSE,
  col = c("#FFFFe5", "#a1d99b", "green", "lightgoldenrod1")
)

Crops

Now, crop patches are added to the virtual landscape resulting with the first configuration of the landscape (Figure \@ref(fig:landscapeConfigured)).

Compute initial richness

A richness value is assigned to each pixel. This value will depend on the pixel category (i.e. natural forest, pine plantation, etc).

Pine plantation

For each pixel $j$, the initial richness value ($R_{init,j}$) is computed following

$$ Richess \sim Potential\ Richenss \times fc $$

where $Potential\ Richenss$ is a random value coming from a range of values obtained from references in our study area [@GomezAparicioetal2009ArePine; @PerezLuqueetal2014SinfonevadaDataset]; and $fc$ is a correction factor which considers:

$$fc = w_{past}\cdot f(\mathrm{past~Land~Use}) + w_{dist}\cdot f(\mathrm{Seed~source~distance}) + w_{treeden}\cdot f(\mathrm{Tree~density}) + w_{clim}\cdot f(\mathrm{Climate~proxy})$$ We specified the following weights according to literature [@GomezAparicioetal2009ArePine; @NavarroGonzalezetal2013WeightLanduse; @PerezLuqueetal2014SinfonevadaDataset]:

Tree Density (ftreeden)

Richness and species diversity within pine plantation are strongly conditioned by the tree density [@GomezAparicioetal2009ArePine]. Tree Density of the pine plantation has a negative effect on the plant diversity, and on the total plant species richness. An increase on the plantation tree density provokes decreasing of the richness plant values [@GomezAparicioetal2009ArePine]. In our study area, the lower diversity of plant species observed in pine plantations is probably due to the high tree density of pine plantations compared to natural forests, which implies lower light levels under the canopy, and this implies lower diversity of herbaceous species.

In addition, the abundance and richness of disperses birds is negatively affected at high tree densities (especially for jays), reducing the flow of seeds entering into the pine plantations, and thus the potential plant species diversity within them.

So, potential richness is affected by pine forest density. Thus, according to Eq. 3 of @GomezAparicioetal2009ArePine, potential richness is affected as a function of density, as follows:

$$ ftreeden = \exp \left [ -\frac{1}{2} \left( \frac{ treeDensity - 0.22} {1504.1} \right )^2\right ] $$

Seed source distance (fdist)

Seed dispersal depends on the distance from the seed source [@Hewitt2002]. In pine plantations, the presence and abundance of species other than pines is determined, among others, by the distance to the seed source [@GonzalezMorenoetal2011SpatialStructure], although it is not the only reason that explains the diversity observed in pine plantations.

@GonzalezMorenoetal2011SpatialStructure found that, of the different vegetation types considered in our study are, natural oak forests are the most influential in terms of distance to the seed source. Oak vegetation has higher plant diversity than pine plantations,especially for herbaceous species [@GomezAparicioetal2009ArePine]. Shorter distances could increase the pool of species in the pine plantations and reduce the evenness of plantation communities.

Specifically, the relationship found between distance to the source and diversity observed in pine plantations is governed by the following equation:

$$ Diversity = 1.7605 - 0.0932 * \sqrt{\sqrt{Distance}}$$

So, for each pixel of pine plantation the distances between the centroid of the pixel and the edge of each natural forest patches are computed using the function dist2nf() (Figure \@ref(fig:distance-raster)).

nf_value <- 2
dist_raster <- dist2nf(landscape)

borde_pine <- rasterToPolygons(landscape,
  fun = function(x) {
    x == 1
  }, dissolve = TRUE
)

nf_edges <- rasterToPolygons(landscape, fun = function(x) {
  x == nf_value
}, dissolve = TRUE)


plot(dist_raster, col = magma(25, direction = -1))
plot(borde_pine, add = TRUE)
plot(nf_edges, add = TRUE, border = "brown")

Then, we compute the distance effect on the diversity for all the landscape (Figure \@ref(fig:distance-effect)), but we will focus only on pine plantations (Figure \@ref(fig:distance-effectpine)). We can see that pixels close to natural forest patches has higher values of diversity.

### Compute diversity raster (See Gonzalez-Moreno et al. 2011)
sh <- calc(dist_raster, fun = function(x) {
  1.7605 - 0.0932 * (sqrt(sqrt(x)))
})
plot(sh)
landscape1 <- landscape
landscape1[landscape1 == 1] <- -100

s <- calc(stack(landscape1, sh), 
          fun = function(x) ifelse(x[1] == -100, (x[1] / -100) * x[2], NA))
plot(s)
plot(borde_pine, add=TRUE)

We scaled the distance effect from 0 to 1 (Figure \@ref(fig:distance-effectpinescaled)).

### Scale the distance effect from 0 to 1
sh_scaled <- (s - cellStats(s, "min")) / (cellStats(s, "max") - cellStats(s, "min"))
plot(sh_scaled)
plot(borde_pine, add=TRUE)

Past Land Use

The past land-use affects to seed banks. In our study area, seedling regeneratio of Quercus species within pine plantation depends on past land-use, distance to seed sources and tree density [@NavarroGonzalezetal2013WeightLanduse; @GomezAparicioetal2009ArePine]. We know that the regeneration of Quercus in pine plantations depends more on past land-use than on plantation tree density and distance to the seed source (see table 2 in @NavarroGonzalezetal2013WeightLanduse). To quantify the importance of each of the three variables, we look at the values of variance explained by each of the models for each variable. Subsequently, we rescale the importance of each variable and obtain:

imp <- read.csv("rescaled_importance_landuse.csv")
imp %>% 
  kableExtra::kbl(booktabs = T, 
                  caption = "Rescaled importance of varaibles. From Navarro-González et al. (2013)", 
                  escape = FALSE)

Therefore, we can say that the regeneration of Quercus under pine plantation followed the next rule:

$$ reg \sim 0.4767 \cdot pastlandUse + 0.3204 \cdot Distance + 0.2029 \cdot Density $$ We consider only the past land-use, as tree-density and distance to source are considered in a above hierarchical level.

But, we need to know the contribution (importance) of the Quercus species to the richness found in pine plantations. We use data from SINFONEVADA Forest inventory [@PerezLuqueetal2014SinfonevadaDataset]. Of the total richness observed in the SINFONEVADA plots, we analyze how much is due to the contribution of Quercus species

### uuid of Sinfonevada
sinfo_uuid <- 'db6cd9d7-7be5-4cd0-8b3c-fb6dd7446472'

### See metadata
sinfo_meta <- datasets(uuid = sinfo_uuid)

# Get table of ocurrences
sf <- occ_data(datasetKey=sinfo_meta$data$key, limit = 8000)

# Get only the fields of interest  
df <- sf$data %>% dplyr::select(decimalLatitude, decimalLongitude, scientificName)
write_csv(df, here::here("manual/data/diversity_sinfonevada.csv"))
df <- read.csv("diversity_sinfonevada.csv")
# How many species by plot
richness_loc <- df %>%
  group_by(decimalLatitude, decimalLongitude) %>% 
  count() %>% 
  as.data.frame() %>% 
  tibble::rownames_to_column(var='id_plot') %>%
  rename(rich = n)

# Get number of quercus species by plot 
q <- df %>%
  filter(grepl("Quercus", scientificName)) %>% 
  group_by(decimalLatitude, decimalLongitude) %>% 
  count() %>% 
  as.data.frame() %>% 
  rename(rich_quercus = n)

# Get total richness by plot 
richness_tot <- df %>%
  group_by(decimalLatitude, decimalLongitude) %>% 
  count() %>% 
  as.data.frame() %>% 
  rename(rich_total = n)

per_quercus_plot <- richness_tot %>% 
  inner_join(q, by=c('decimalLatitude', 'decimalLongitude')) %>% 
  mutate(per = rich_quercus / rich_total)

per_quercus_plot %>% ggplot(aes(per)) + geom_histogram() +
  xlab('% Quercus species by plot') + theme_minimal()
aux <- per_quercus_plot %>% 
  summarise(mean = mean(per)*100,
            min = min(per)*100, 
            max = max(per)*100, 
            median = median(per)*100)

Quercus contribute (on average) to the richness of the plot about r round(aux$mean) % (Figure \@ref(fig:quercusImp)), therefore, we should adjust the contribution of land use to the richness of the pine forest plots.

The richness value of a plantation is conditioned by the past land use [@NavarroGonzalezetal2013WeightLanduse], since the probability of finding recruits of Quercus species within a pine plantations depends on the past land use of that plantation. @NavarroGonzalezetal2013WeightLanduse differentiate between the probability of finding regeneration in a pine plantation and the amount of regeneration (number of recruits) found within pine plantation. In our case, we are more interested in the probability of finding regeneration, rather than abundance. Thus we have that:

odd <- read.csv("odds_ratio_landuse.csv")
odd %>% 
  kableExtra::kbl(booktabs = T, 
                  caption = "Rescaled probability of finding regeneration. From Navarro-González et al. (2013)", 
                  escape = FALSE)

where, the rescaled probability of finding regeneration as a function of land use follows the following gradient: Holm oak forest (0.9999) > Shrubland (0.4982) > Cropland (0.0279) > Grassland (0.0001).

Note that all these values are for the same distance and an average density of 750 pines / ha.

Climate-proxy variables

Climatic conditions are important determinants of species richness, particularly in mountainous regions. In our study area (Sierra Nevada, southern Spain), @GomezAparicioetal2009ArePine found an effect of climate conditions on potential species richness within pine plantations. These authors used 19 variables related to climatic and topographic conditions, and applied a principal components analysis (PCA), and they found that elevation and annual radiation were the variables most correlated with the first two axes of the PCA (which explaining 83.3 % of the variance) (See equation 2 and Figures 5A-B in @GomezAparicioetal2009ArePine). They found that climate have a strong effect on plant richness and also on potential regeneration. In our app, diveRpine, we only considered the potential richness, and the effect of climate conditions on the potential richness within pine plantations were implemented using the equation 2 of @GomezAparicioetal2009ArePine, specifically: $$\mathrm{Climatic~effect}=\mathrm{exp}\left [-\frac{1}{2}\left ( \frac{\mathrm{Altitude }- \mathrm{XA_0}}{\mathrm{XA_b}} \right )^{2} \right ] \times ~\mathrm{exp}\left [-\frac{1}{2}\left ( \frac{\mathrm{Radiation }- \mathrm{XR_0}}{\mathrm{XR_b}} \right )^{2} \right ]$$ with $\mathrm{XA_0}=1557.16$, $\mathrm{XA_b}=644.89$, $\mathrm{XR_0}=0$, and $\mathrm{XR_b}=13.24$

This equation in used as default in initRichess() with the argument fclim, that used the elevation (elev) and radiation (rad) values specified by the user in the diveRpine app.

Natural Forests an Crops

For natural forests and crop pixels, the initial richness value will be randomly selected from a specific richness range.

 r_range <- as.data.frame(
      cbind(
        value = c(0, 1, 2, 3),
        lowRich = c(0, 12.82, mean(13.72, 15.62), 1),
        upRich = c(0, 13.34, mean(16.11, 19.66), 2)
      ))
r_range %>% 
  mutate(patch = case_when(
    value == 0 ~ "",
    value == 1 ~ "Pine plantation",
    value == 2 ~ "Natural Forests",
    value == 3 ~ "Crops",
  )) %>%
  relocate(patch) %>% 
  kableExtra::kbl(booktabs = T, 
                  col.names = c("Type", "Type numeric", "Low Richness value", "High Richness value"), 
                  caption = "Richness ranges values", 
                  escape = FALSE)

Initial Richness

The initial Richness is computed using the function initRichness()

# landscape() 
# dist_raster()
# ri_range (init params )
# den_pp()$den 
# pastUse()

rasterRich <- initRichness(r = landscape, 
                           draster = dist_raster, 
                           r_range = r_range,
                           treedensity = pp_den_den, 
                           pastUse = pp_use, 
                           elev = 1500, 
                           rad = 4,
                           rescale = FALSE)

And it can be plotted using plot_richness() (Figure \@ref(fig:initialrichness))

plot_richness(rasterRich)

Get values of Richness for NF and Pine

We used an custom function to compute the mean, min and max. This function (summaryRaster()) takes a raster and compute the mean, max and min values of the cells.

We applied this function to compute the Richness values of Natural forests patches (Figures \@ref(fig:nfrichness) and \@ref(fig:nfrichnesshist)), and Pine plantation target patch (Figures \@ref(fig:pinerichness) and \@ref(fig:pinerichnesshist)) (init and end configuration). The summary values are displayed on the bottom-left side of the diveRpine app.

Natural Forests

rich_nf <- calc(
  stack(landscape, rasterRich), 
  fun=function(x) ifelse(x[1] == nf_value, (x[1]/nf_value)*x[2], NA))

plot(rich_nf, axes=FALSE)
dfnf<- drop_na(raster::as.data.frame(rich_nf))

dfnf %>% 
  ggplot(aes(layer)) + geom_histogram() +
  theme_minimal() + 
  ylab("n pixels") + xlab("Richness Value") + 
  geom_vline(xintercept = mean(dfnf$layer)) +
  ggtitle("Natural Forests")

The mean, min and max values for natural forests are showed in the value box of the bottom-left part of the app.

Pine plantation

pp_value <- 1 
rich_pp <- calc(stack(landscape, rasterRich), fun=function(x) ifelse(x[1] == pp_value, x[1]*x[2], NA))

plot(rich_pp, axes=FALSE)
dfpp<- drop_na(raster::as.data.frame(rich_pp))
dfpp %>% 
  ggplot(aes(layer)) + geom_histogram() +
  theme_minimal() + 
  ylab("n pixels") + xlab("Richness Value") + 
  geom_vline(xintercept = mean(dfpp$layer)) +
  ggtitle("Pine plantation")

The mean, min and max values for the initial pine plantation are showed in the value box of the bottom-left part of the app.

Dispersal module

The next step is computed the input of seed propagules from sources (natural forest) into target pine plantation via dispersers [sensu @Nathan2012].

The quantity and quality of seed dispersion are influenced by:

Dispersers

We have considered three classes of dispersers:

For each type of disperser, different dispersion kernels have been considered:

df_disper <- read.csv("disperser_table.csv")

df_disper %>% 
  kableExtra::kbl(booktabs = T, 
                  col.names = 
                    c("Dispersers", "Dispersion range \n (m)", 
                      "Peak distance", "50% Distance", "Refs."),
                  caption = "Features of the dispersers", 
                  escape = TRUE)
# Create vectors of dispersl kernels 
vector_sb <- seq(0, 500, by = 1)
kernel_sb <- dlnorm(vector_sb, meanlog = log(51), sdlog = .7)
vector_mb <- seq(0, 1000, by = 1)
kernel_mb <- dlnorm(vector_mb, meanlog = log(201), sdlog = .7)
vector_ma <- seq(0, 2000, by = 1)
kernel_ma <- ifelse(vector_ma <= 400, 
                    dweibull(vector_ma, shape = 1.385, scale = 137),
             dlnorm(vector_ma, meanlog = 6.621, sdlog = 0.297))

dfsb <- 
  data.frame(cbind(kernel=kernel_sb, dist= vector_sb)) %>% 
  mutate(type = "small birds")
dfmb <- 
  data.frame(cbind(kernel=kernel_mb, dist= vector_mb)) %>% 
  mutate(type = "medium birds")
dfma <- 
  data.frame(cbind(kernel=kernel_ma, dist= vector_ma)) %>% 
  mutate(type = "mammals")

df <- bind_rows(dfsb, dfmb, dfma)

ggplot(df, aes(x=dist, y=kernel, fill=type)) + 
  geom_polygon(alpha=.5) + xlim(0,1500) +
  theme_bw()+ 
  xlab("Distance from Seed source") +
  ylab("Probability of dispersion") +
  scale_fill_manual(
    values=c("#493738","#A05A2C","#FFDD56" )) +
  theme(
    panel.grid = element_blank()
  ) 

According to the disperser type, the potential_dispersion() function uses by default different dispersion kernels. For small and medium birds a log-normal dispersion kernels were used. Specifically, log-normal density function with mean and standard deviation values of $log(51)$ and $log(2)$ respectively for small-sized birds, and log-normal density function with mean and standard deviation values of $log(201)$ and $log(2)$ for medium-sized birds. This distribution were implemented using the stats::dlnorm() function. For mammals, a combination of log-normal and Weibull dispersion kernel was used. Specifically, from 0 to 400 m of distance from the seed source, a Weibull distribution with a shape and scale parameters of 1.385 and 137 respectively was used (See stats::dweibull()); whereas a log-normal density function with mean and standard deviation values of $log(751)$ and $log(1.346)$ respectively, were applied for distances higher than 401 m from seed source. Different kernels functions could be specified using the parameters kernel_sbi, kernel_mbi, and kernel_ma within potential_dispersion() (see Advanced configuration article).

For each of the natural forest patches, the distance to the target pine plantation is computed. For instance, we computed the distance from the natural forest patch located at bottom-left side of our landscape (Figure \@ref(fig:landscapeConfigured)). And then, we applied the kernels of each disperser type using the seed source values ((Figure \@ref(fig:distanceNF)).

x <- landscape
# Get polygons of Natural forests 
nf_edges <- raster::rasterToPolygons(x, fun=function(x){x == nf_value}, dissolve = TRUE)
nf_patches <- sp::disaggregate(as(st_as_sf(nf_edges), "Spatial"))

i <- 2
# distance between nf polygong i and cells of the raster 
d <- rgeos::gDistance(nf_patches[i,], methods::as(x,"SpatialPoints"), byid=TRUE)
d_nfi <- x
d_nfi[] <- apply(d, 1, min)*10 # compute minimun distance; and multiply by 10 meters  
names(d_nfi) <- paste0("nf", i)
plot(d_nfi)
plot(nf_patches[i,], add=TRUE)

As we previously stated, we used different functions to compute the kernels of each disperser kernel_sbi, kernel_mbi, and kernel_ma. And the compute the potential contribution of propagules into target pine plantation according to the richness values of the natural forest patches.

# Get the mean, sd, se richness of the nf patch  
rich_nfi <- raster::mask(rich_nf, nf_patches[i,])

rich.mean <- raster::cellStats(rich_nfi, stat = "mean", na.rm=TRUE)
rich.sd <- raster::cellStats(rich_nfi, stat = "sd", na.rm=TRUE)
rich.se <- rich.sd/(sqrt(length(rich_nfi) - freq(rich_nfi, value=NA)))

Small birds contribution

## Small bird 
sbi <- raster::calc(d_nfi, fun = function(x){dlnorm(x, meanlog = log(51), sdlog = .7)})
names(sbi) <- paste0('sb',i)
### potential contribution 
sbipot <- stack(sbi*rich.mean, sbi*rich.sd, sbi*rich.se)
names(sbipot) <- c(paste0("sbpot_", i, "_mean"), paste0("sbpot_", i, "_sd"), paste0("sbpot_", i, "_se"))

plot(sbipot$sbpot_2_mean, main="Small birds")
plot(nf_patches[i,], add=TRUE)
## Medium bird 
mbi <- raster::calc(d_nfi, fun = function(x){dlnorm(x, meanlog = log(201), sdlog = .7)})
names(mbi) <- paste0('mb',i)
### potential contribution 
mbipot <- stack(mbi*rich.mean, mbi*rich.sd, mbi*rich.se)
names(mbipot) <- c(paste0("mbpot_", i, "_mean"), paste0("mbpot_", i, "_sd"), paste0("mbpot_", i, "_se"))

plot(mbipot$mbpot_2_mean, main="Medium birds")
plot(nf_patches[i,], add=TRUE)
## Mammals 
mai <- raster::calc(d_nfi, fun = function(x){
  ifelse(x <= 400, 
         dweibull(x, shape = 1.385, scale = 137),
         dlnorm(x, meanlog = 6.621, sdlog = 0.297))})
names(mai) <- paste0('ma',i)
### potential contribution 
maipot <- stack(mai*rich.mean, mai*rich.sd, mai*rich.se)
names(maipot) <- c(paste0("mapot_", i, "_mean"), paste0("mapot_", i, "_sd"), paste0("mapot_", i, "_se"))
plot(maipot$mapot_2_mean, main="Mammals")
plot(nf_patches[i,], add=TRUE)

Adjacency

Then, for each natural forest patches the adjacency to the pine-plantation target is computed. The higher the adjacency between the natural forest and the pine plantation, the lower the limitation of the propagule entry dispersed by birds. @Zamoraetal2010PositiveAdjacency found that the intercept and the slope of the linear relation between the seed limitation (values from 0 to 1) and the adjacency (i.e. percentage of pine-plantation perimeter in contact with native forests) were 0.733 and 0.0039 respectively. Those parameters are included by default in the function potential_dispersion(), but could be customized using the seedlim_int and seedlim_slope parameters. For each natural forest patch, the adjacency to target pine-plantation is computed. For those patches with adjacency, the potential dispersion by birds increases according a correction factor, that is computed as follows:

$$adj_{fc} = 1 + \frac{\textrm{seed Entry} - \textrm{seed Entry}{0}}{\textrm{seed Entry}{100} - \textrm{seed Entry}_{0}}$$

where $\textrm{seed Entry} = 1- \textrm{seed limitation}$; $\textrm{seed limitation}$ is computed using the seedlim_int and seedlim_slope parameters; $\textrm{seed Entry}{0}$ and $\textrm{seed Entry}{100}$ correspond to the seed entry for no adjacency and full adjacency respectively [@Zamoraetal2010PositiveAdjacency].

patch_adjacente <- 1 

x <- landscape
# Get perimeter of the pine plantations
pine <- raster::rasterToPolygons(x, fun = function(x) {
    x == pp_value
}, dissolve = TRUE)
perimeter_pine <- rgeos::gLength(pine)

 # --- Adjacency
intersectan <- sf::st_intersects(sf::st_as_sf(nf_patches[patch_adjacente, ]),
      sf::st_as_sf(pine),
      sparse = FALSE
    )
    if (intersectan == TRUE) {
      length_inter <- sf::st_length(
        sf::st_intersection(sf::st_as_sf(nf_patches[patch_adjacente, ]),
          sf::st_as_sf(pine),
          sparse = FALSE
        )
      )
    } else {
      length_inter <- 0
    }


 # Seed Limit
    seedlim_int <- 0.733
    seedlim_slope <- 0.0039

For instance, one of the natural forest patches, intersects to target-pine plantation (Figure \@ref(fig:inter)). The adjacency between natural forest patch and pine plantation corresponds to r round((length_inter / perimeter_pine) * 100, 3) % of the pine-plantation perimeter. So for this natural forest patch, a seed-entry is computed following the previous equation, and a factor of correction is applied to the input propagule.

plot(landscape)
plot(pine, add=TRUE, border="black")
plot(nf_patches[patch_adjacente, ], border="brown", add=TRUE)
## Generate adj factor for nf i
    adj <- (length_inter / perimeter_pine) * 100
    ## Compute the seed entry (1 - seed limit) (only for nf with intersection)
    # (seedlimit=a + b*adj) see Zamora et al.2010  a=0.7327; b = -0.0039
    seedentry <- (1 - (seedlim_int - (seedlim_slope * adj)))
    # Standardize seedentry from 0 to 1
    # 0 % adj --> 1 - (a + b*0%) = 1 - a; 0.267
    # 100 % adj --> 1 - (a + b*100); 0.657
    # std --> seedentry - 0% / (100% - 0%)
    adjF <- (seedentry - 0.267) / (0.657 - 0.267)
    fc <- 1 + 0.5 * adjF
rich_nf <- calc(
  stack(landscape, rasterRich), 
  fun=function(x) ifelse(x[1] == nf_value, (x[1]/nf_value)*x[2], NA))

According to literature, propagules input by birds and mammals in mountain pine plantation of our study area representing 3.7 and 0.2 seeds m^2^ yr^−1^ respectively [@Zamoraetal2010PositiveAdjacency; @Matiasetal2010SeedDispersal]. Those values are specified in the server part of the app (see server.R; to modify them see Advanced configuration article).

The user determines the percentage of each disperser type using the slide bars in diveRpine. Those values are used as weigths to ponderate the contribution of each disperser to the input propagule into pine-plantation.

piBird = (3.7)/100
piMammal = (0.2)/100
input$sb <- 20
input$mb <- 35 
perma <- 100 - (input$sb + input$mb)

Once, the diserpser types are configurated, the potential input of propagules into the pine plantation is computed using potential_dispersion() and input_propagule().The output is following at (Figure \@ref(fig:plotpropagule)).

pot_disp <- potential_dispersion(x = landscape, rich_nf = rich_nf,
                                 nf_value = 2, pp_value = 1)
pot_disp_pp <- input_propagule(x = landscape, pd = pot_disp, pp_value = 1)
propagule_sb <- pot_disp_pp[['sb']] * as.numeric(input$sb) * piBird
propagule_mb <- pot_disp_pp[['mb']] * as.numeric(input$mb) * piBird
propagule_ma <- pot_disp_pp[['ma']] * as.numeric(perma) * piMammal

propagule <- raster::calc(stack(propagule_sb,
                       propagule_mb,
                       propagule_ma), sum)
plot_propagule(propagule)

Simulation and computation of the final richness

Finally, the user can select the length of the simulation (number of years), and diveRpine estimates the quantity of propagules input into each pixel of the pine plantation. Then, the app calculates the final richness by considering the initial richness values, the propagule input, and assuming the existence of plant establishment constraints for this mountain area [@Queroetal2011LinkingStochasticity; @Matiasetal2010SeedDispersal; @Mendozaetal2009RecruitmentLimitation; @Matiasetal2011RepercussionsSimulated]. diveRpine generates a map (Figure \@ref(fig:riquezafinal)) with the end richness and the average values for the entire target pine plantation are shown.

 ## Compute the input over time
input$timeRange <- 30 
sim <- propagule*input$timeRange

rich_pp_end <- calc(stack(rich_pp, sim), sum)
rich_end <- raster::calc(stack(landscape, rasterRich, rich_pp_end),
                 fun = function(x) ifelse(x[1] == pp_value, x[1]*x[3], x[2]))
plot_richness(rich_end)

References



ajpelu/diverpine documentation built on Feb. 3, 2023, 8:09 p.m.