R/larvaldispersal.R

#' Disperse and recruits larvae
#'
#' This function uses the \code{\link{dispersal}} function to disperse the recruits, but also applies both natural mortality and that linked to habitat carrying capacity.
#'
#' @param recruits a vector of the number of recruits per cell
#' @param cml A connectivity matrix containing the probability of dispersing from each starting location (rows) to each end location (columns). Can easily be generated by \code{initcm}
#' @param lM A vector of natural larval mortality to be selected from
#' @param CCs Habitat carrying capacity, in kg
#' @param fish
#' @inheritParams dispersal
#'
#' @return
#' @export
#'
#' @examples
#' # create a fish matrix
#' fish <- initpop(initial_abun=250*10^6,cells=length(BESTMPA_domain),maxage=50,rate=0.7)
#' # identify nearby breeding grounds
#' breeding_near <- apply(gDistance(spTransform(Breeding,proj),p,byid = T),1,which.min)
#' # generate recruits vector
#' recruits <- reproduction(fish,fecundity=5e+05,age_mat_steepness=2.5,age_mat_sigmoid=4,l_to_w_int=1.1e-05,l_to_w_power=2.91,Linf_mean=112.03,Linf_SD=5.336735,k_mean=0.13,k_SD= 0.01071429,t0=0.18,breeding_near=breeding_near,domain=BESTMPA_domain)
#' # exponential dispersal kernal
#' cm <- initcm(domain=BESTMPA_domain,e_fold=75000,cell_size=20000)
#' recruits <- larvaldispersal(recruits=recruits,cml=cml,lM=rnorm(10000,0.5,0.1),CCs=rnorm(length(recruits),0.5,0.1))
larvaldispersal <- function(recruits,cml,lM,CCs,fish){
    recruits <- dispersal(recruits,cm=cml,ages=0)

    recruits <- mortality(recruits,M=sample(lM,length(recruits)),ages=0)

    # density dependent recruitment
    recruits <- roundprob(recruits/(1+rowSums(fish)/CCs))
    recruits[is.nan(recruits)] <- 0
    return(recruits)
}
remi-daigle/BESTMPA documentation built on May 27, 2019, 4:55 a.m.