# NOT RUN {
# Run the model with all inputs specified explicitly:
# Set up the inputs to the function - species-independent parameters
nfish <- nrow(NS_par)
nsc <- 32
maxsize <- max(NS_par$Linf)*1.01 # the biggest size is 1% bigger than the largest Linf
l_bound <- seq(0, maxsize, maxsize/nsc); l_bound <- l_bound[-length(l_bound)]
u_bound <- seq(maxsize/nsc, maxsize, maxsize/nsc)
mid <- l_bound+(u_bound-l_bound)/2
# Set up the inputs to the function - species-specific parameters
Linf <- NS_par$Linf # the von-Bertalanffy asymptotic length of each species (cm).
W_a <- NS_par$W_a # length-weight conversion parameter.
W_b <- NS_par$W_b # length-weight conversion parameter.
k <- NS_par$k # the von-Bertalnaffy growth parameter.
Lmat <- NS_par$Lmat # the length at which 50\% of individuals are mature (cm).
# Get phi_min
tmp <- calc_phi(k, Linf, nsc, nfish, u_bound, l_bound, calc_phi_min=FALSE,
phi_min=0.1) # fixed phi_min
phi <- tmp$phi
phi_min <- tmp$phi_min
# Calculate growth increments
tmp <- calc_ration_growthfac(k, Linf, nsc, nfish, l_bound, u_bound, mid, W_a, W_b, phi_min)
ration <- tmp$ration
sc_Linf <- tmp$sc_Linf
wgt <- tmp$wgt
g_eff <- tmp$g_eff
# Calculate maturity
mature <- calc_mature(Lmat, nfish, mid, kappa=rep(10, nfish), sc_Linf)
# Create recruitment functions
stored_rec_funs <- get_rec_fun(rep("hockey-stick", nfish))
recruit_params <- do.call("Map", c(c, list(a=NS_par$a, b=NS_par$b)))
# Calculate background mortality
M1 <- calc_M1(nsc, sc_Linf, phi_min)
# Calculate predator-prey size preferences
prefs <- calc_prefs(pred_mu=-2.25, pred_sigma=0.5, wgt, sc_Linf)
# Calculate prey preference and prey suitability
suit_M2 <- calc_suit_vect(nsc, nfish, sc_Linf, prefs, NS_tau)
# Calculate catchability
Qs <- calc_Q(curve=rep("logistic", nfish), species=NS_par$species_names,
max_catchability=rep(1, nfish), gear_name=NS_par$species_names,
nsc=nsc, nfish=nfish, mid=mid, l_bound=l_bound, u_bound=u_bound,
species_names=NS_par$species_names, eta=rep(0.25, nfish), L50=Lmat)
# Get an initial population
N0 <- get_N0(nsc, nfish, mid, wgt, sc_Linf, intercept=1e10, slope=-5)
years <- 10 # run the model for 10 years
tot_time <- years*phi_min # total number of time steps
# Define fishing effort to be 0.5 for all species
effort <- matrix(0.5, tot_time, dim(Qs)[3])
# Calculate F
Fs <- array(0, dim=c(nsc, nfish, tot_time))
for (j in 1:ncol(effort)) {
for (ts in 1:tot_time) {
Fs[,,ts] <- Fs[,,ts]+effort[ts, j]*Qs[,,j]
}
}
# Run the model
model_run <- run_LeMans(N0=N0, tot_time=tot_time, Fs=Fs, nsc=nsc, nfish=nfish,
phi_min=phi_min, mature=mature, sc_Linf=sc_Linf, wgt=wgt,
phi=phi, ration=ration, other=NS_other, M1=M1, suit_M2=suit_M2,
stored_rec_funs=stored_rec_funs, recruit_params=recruit_params,
eps=1e-05)
##############################################
# Alternatively:
NS_params <- LeMansParam(NS_par,tau=NS_tau,eta=rep(0.25,21),L50=NS_par$Lmat,other=NS_other)
# Define fishing effort
effort <- matrix(0.5, 10, dim(NS_params@Qs)[3])
# Run the model
model_run <- run_LeMans(NS_params, years=10, effort=effort)
# }
Run the code above in your browser using DataLab