R/kissmigAccess.R

Defines functions kissmigAccess

Documented in kissmigAccess

#' Get accessiblity map from kissmig output
#'
#' \command{kissmigAccess} calculates a accessibility map from a kissmig output of first occurrence (type='FOC'). These maps
#' allows the integration of limited migration in species distribution models and macroecological analyses.
#' @usage kissmigAccess(grd, rel=FALSE)
#' @param grd a single RasterLayer of first occurrence generated by kissmig
#' @param rel if TRUE, kissmigAccess returns relative values with maximum 1, otherwise absolute interger values
#' @details
#' \command{kissmig} maps of first occurrences show values of the first iteration step a raster cell was colonized. Early
#' colonized cells have low values, late colonized cells high values. These values are the opposite of accessibility,
#' which is high for early colonized, and low for late colonized cells. \command{kissmigAccess} simply calculates for each
#' cell the accessibility as the difference between the cell value and \command{max(grd)+1}. Cells which have never been
#' colonized remain unchanged (value 0).
#' @seealso \code{\link{kissmig}}
#' @export kissmigAccess

kissmigAccess <- function(grd, rel=FALSE) {
  v <- values(grd)
  v[is.na(v)] <- 0
  values(grd) <- v
  values(grd)[values(grd)>0] <- max(values(grd))-values(grd)[values(grd)>0]+1
  if (rel==TRUE) {grd <- grd/max(values(grd))}
  return(grd)
}

Try the kissmig package in your browser

Any scripts or data that you put into this service are public.

kissmig documentation built on June 2, 2022, 1:06 a.m.