R/find_jumps_wrapper.R

Defines functions find_jumps_wrapper

Documented in find_jumps_wrapper

#'Find dispersal jumps 
#'
#'Find dispersal jumps after having applied find_thresholds(). Prune points selected due to sector limits and secondary diffusion.

#'@export
#'
#'@param dataset A data frame of unique points to be processed, ideally the dataset_unique resulting from find_thresholds()
#'@param potJumps A data frame of potential jumps to be refined, resulting from find_thresholds()
#'@param year Years to be considered (default: 2014 to 2020)
#'@param gap_size Distance between the invasion front and the positive point
#'necessary for it to be considered a jump, in kilometers (default: 15)
#'@param crs Coordinate system used for spatial layers (default: 4326)
#'
#'@return Two data frames: \code{Jumps} containing the list of jumps, and \code{potSecDiff} containing
#'potential secondary diffusion to be processed using find_secDiff()
#' 
#'@examples
#' jumps <- find_jumps(dataset)


find_jumps_wrapper <- function(dataset = grid_data, 
                               nb_sectors = 12,
                               centroid = c(-75.675340, 40.415240),
                               rotation = 1,
                               gap_size = 15,
                               negatives = T,
                               crs = 4326){
  
                         
  #1 Attribute sectors
  grid_data_sectors <- slfjumps::attribute_sectors(dataset = grid_data, # dataset to be explored
                                                   nb_sectors = nb_sectors, # number of sectors to divide the invasion range
                                                   centroid = centroid, # vector containing the centroid coordinates as long/lat
                                                   rotation = rotation) # number of rotations considered
  
  
  
  #2 Find thresholds
  Results_thresholds <- slfjumps::find_thresholds(dataset = grid_data_sectors, 
                                                  gap_size = gap_size, 
                                                  negatives = negatives)
  ## store resulting objects
  preDist <- Results_thresholds$preDist # list of threshold points = limits of the diffusive spread. Will be completed in find_secDiff()
  potJumps <- Results_thresholds$potJumps # list of potential jumps. Will be pruned in find_jumps()
  
  
  
  
  #3 Find jumps
  Results_jumps <- slfjumps::find_jumps(grid_data = grid_data, 
                                        potJumps = potJumps,
                                        gap_size = gap_size, 
                                        crs = crs)
  # store resulting objects
  Jumps <- Results_jumps$Jumps # final list of jumps
  diffusers <- Results_jumps$diffusers # list of positive cells stemming from diffusive spread
  potDiffusion <- Results_jumps$potDiffusion # list of cells containing a mix of secondary diffusion and additional threshold points. Will be pruned in find_secDiff()
  
  
  
  
  #4 Find sec diff
  Results_secDiff <- slfjumps::find_secDiff(potDiffusion = potDiffusion,
                                            Jumps = Jumps,
                                            diffusers = diffusers,
                                            Dist = preDist,
                                            gap_size = gap_size,
                                            crs = crs)
  # store resulting objects
  secDiff <- Results_secDiff$secDiff
  Dist <- Results_secDiff$Dist

  # select the results to return
  results <- list("Dist" = Dist, "Jumps" = Jumps, "secDiff" = secDiff)
  
  return(results)
} 
nbelouard/slfjumps documentation built on July 27, 2024, 8:28 a.m.