sprat-xsa-experimental
/
.Rhistory
512 строк · 22.4 Кб
1f.retro[[i]] <- f.t
2}
3result.retro.diagnostic.ssb <- data.frame(ssb.base, ssb.retro[[1]], ssb.retro[[2]], ssb.retro[[3]])
4config.retro.horizon <- 3
5print("[XSA toolkit]: Retrospective Mohn's rho tests")
6# compare XSA estimates in terminal year by -5 year retrospective
7lastYear <- as.numeric(range(data.stock)["maxyear"])
8ssb.base <- as.vector(ssb(window(data.stock+FLXSA(data.stock, data.indices, config.tuning.xsa), start=lastYear-3)))
9f.base <- as.vector(fbar(window(data.stock+FLXSA(data.stock, data.indices, config.tuning.xsa), start=lastYear-3)))
10ssb.retro <- list()
11f.retro <- list()
12for (i in 1:config.retro.horizon) { # prepare retrospective matrix for mohn's rho test
13# make retro
14tmp.xsa <- FLXSA(window(data.stock, end=(lastYear-i)), window(data.indices, end=(lastYear-i)), config.tuning.xsa)
15tmp.xsa.st <- data.stock + tmp.xsa
16ssb.t <- as.vector(ssb(window(tmp.xsa.st, start=lastYear-config.retro.horizon)))
17f.t <- as.vector(fbar(window(tmp.xsa.st, start=lastYear-config.retro.horizon)))
18ssb.retro[[i]] <- ssb.t
19f.retro[[i]] <- f.t
20}
21result.retro.diagnostic.ssb <- data.frame(ssb.base, ssb.retro[[1]], ssb.retro[[2]], ssb.retro[[3]])
22rownames(result.retro.diagnostic.ssb) <- (lastYear-config.retro.horizon):lastYear
23result.retro.diagnostic.f <- data.frame(f.base, f.retro[[1]], f.retro[[2]], f.retro[[3]])
24rownames(result.retro.diagnostic.f) <- (lastYear-config.retro.horizon):lastYear
25names(result.retro.diagnostic.ssb) <- c("ssb.base", "-1", "-2", "-3", "-4", "-5")
26result.retro.diagnostic.ssb <- data.frame(ssb.base, ssb.retro[[1]], ssb.retro[[2]], ssb.retro[[3]])
27rownames(result.retro.diagnostic.ssb) <- (lastYear-config.retro.horizon):lastYear
28result.retro.diagnostic.f <- data.frame(f.base, f.retro[[1]], f.retro[[2]], f.retro[[3]])
29rownames(result.retro.diagnostic.f) <- (lastYear-config.retro.horizon):lastYear
30names(result.retro.diagnostic.ssb) <- c("ssb.base", "-1", "-2", "-3", "-4", "-5")
31names(result.retro.diagnostic.ssb) <- c("ssb.base", "-1", "-2", "-3")
32names(result.retro.diagnostic.f) <- c("f.base", "-1", "-2", "-3")
33# replace NaN's (x/0) to NA (not available)
34is.nan.data.frame <- function(x) {
35return (do.call(cbind, lapply(x, is.nan)))
36}
37result.retro.diagnostic.f[is.nan(result.retro.diagnostic.f)] <- NA
38result.retro.diagnostic.ssb[is.nan(result.retro.diagnostic.ssb)] <- NA
39result.retro.mohnrho.ssb <- mohn(result.retro.diagnostic.ssb, peels = config.retro.horizon)
40result.retro.mohnrho.fbar <- mohn(result.retro.diagnostic.f, peels = config.retro.horizon)
41remove(ssb.base, f.base, ssb.retro, f.retro)
42result.retro.mohnrho.ssb
43result.retro.mohnrho.fbar
44source("~/Dev/R/BlackSea/sprat-xsa/run.R")
45ls
46# ************************************* #
47# Author: Piatinskii M., Azov-black sea bench of VNIRO
48# © 2019
49# **************************************#
50# make cleanup
51rm(list = ls(all.names=TRUE))
52# load libraries
53library("FLCore")
54library("FLXSA")
55library("FLAssess")
56library("ggplotFL")
57# library("FLBRP") # no support for R 4.0, require compilation from *nix
58library("FLash")
59#install.packages("devtools")
60#install_github("ices-tools-prod/msy")
61library("msy")
62library("rmarkdown")
63library("dplyr")
64library("magrittr")
65library("tibble")
66library("icesAdvice")
67fit.xsa
68source("~/Dev/R/bsea-models/sprat-xsa/run.R")
69result.xsa.fit
70AIC(result.xsa.fit)
71BIC(result.xsa.fit)
72source("http://flr-project.org/R/instFLR.R")
73# ************************************* #
74# Author: Piatinskii M., Azov-black sea bench of VNIRO
75# © 2019
76# **************************************#
77# make cleanup
78rm(list = ls(all.names=TRUE))
79# load libraries
80library("FLCore")
81library("FLXSA")
82library("FLAssess")
83library("ggplotFL")
84# library("FLBRP") # no support for R 4.0, require compilation from *nix
85library("FLash")
86#install.packages("devtools")
87#install_github("ices-tools-prod/msy")
88library("msy")
89# stock object configurations
90config.stock.name <- "Sprattus sprattus" # fish title
91config.stock.desc <- "Sprat stock information in FLCore format from 2000years" # fish stock description
92config.stock.fbar.min <- 1 # minimum fish age become fishing (Fbar min)
93config.stock.fbar.max <- 3 # maximum fish age at fishing (Fbar max)
94config.stock.no_harvestspawn <- TRUE # Set TRUE if there is no information about fishing before spawning
95config.stock.no_mspawn <- TRUE # Set TRUE if no information about natural mortality before spawning
96config.stock.no_discards <- TRUE # Set TRUE if no separated information about landing/discards exist (only catch)
97config.stock.window.start <- 2001 # model start
98config.stock.window.end <- 2022 # model end
99# configure surveys indices
100config.index1.name <- "Sprat crimea cpue index"
101config.index1.desc <- "Fishery index information about sprat abundance at Crimea shelf from real fishing surveys"
102config.index1.startf <- 0.3 # start month of survey in format month/12, example: 1 feb = 2/12 = 0.166
103config.index1.endf <- 0.7 # end month of survey in format month/12
104config.index1.type <- "number" # type of survey, allowed: number, biomass
105# same with previous
106config.index2.name <- "Sprat caucasian cpue index"
107config.index2.desc <- "Fishery index information about sprat abundance at Caucasian shelf from real fishing surveys"
108config.index2.startf <- 0.3
109config.index2.endf <- 0.7
110config.index2.type <- "number"
111# pre-analysis diagnostic procedures. Useful to choice the model parametrization, convergence, etc
112config.iter.fse = TRUE # Fse choice procedure
113config.iter.retro = TRUE # retrospective procedure
114config.iter.fseage = TRUE # Fse at age impact procedure
115# configure retrospective depth
116config.retro.horizon <- 5
117# Shrinkage standard error max value. Default value Fse = 0.5
118# Higher shrinkage se leads to high unrestraint of estimating procedure.
119config.tuning.xsa <- FLXSA.control(
120maxit = 100, # maximum covergence iterations
121fse = 1.5, # shrinkage s.e value
122shk.n = T,
123shk.f = T,
124shk.yrs = 4,
125tsrange = 15, # weighting time series length (from latest year)
126tspower = 3, # weighting procedure sequence (1 = linear, 2 = square, 3 = cubic)
127qage = 2, # age after catchability not depends on age
128)
129# sr model configuration
130config.srmodel.eqsim.use = TRUE # should we use eqsim package insted of FLSR default?
131config.srmodel.use_geomean = FALSE # set FALSE to use EQSIM SR model results to forecasting
132# eqsim model configurations (if config.srmodel.eqsim.use = TRUE)
133config.srmodel.eqsim.models = c("Segreg") # types of model to fit and compare
134config.srmodel.eqsim.simulations = 10 # number of simulations
135config.srmodel.eqsim.shift_years <- c(1994:2003) # remove years from sr-model fitting
136# flsr model configuration (if config.srmodel.eqsim.use = FALSE)
137config.srmodel.type <- segregAR1() # SR model type: ricker(), bevholt(), geomean(), segreg(), shepherd(), cushing(), AR in model name = AutoCorrelation fix
138config.srmodel.optimization = FALSE # Use optimization procedure for SR model fitting?
139# configure MSY reference point calculation: Blim, Bpa, Fmsy
140config.brp.blim_multiplier <- 0.2 # multiplier of SSBmax to get Blim ref.point, allowed: 0.2 - 0.4
141config.brp.trim_uncertainity <- TRUE # trim uncerteinity extreme deviations? Optimization procedure for Bpa estimate
142config.brp.current_range <- 2003:2021 # shift previous population states from BRP calculations
143# Custom forecast scenarious. By default performed: F_SQ, F_01, F_msy scenarious.
144# There you can define f(y+1), f(y+2), f(y+3) targets for 2 scenarious
145config.forecast.scenario1.f_year1 <- 0.4
146config.forecast.scenario1.f_year2 <- 0.4
147config.forecast.scenario1.f_year3 <- 0.4
148config.forecast.scenario2.f_year1 <- 0.5
149config.forecast.scenario2.f_year2 <- 0.5
150config.forecast.scenario2.f_year3 <- 0.5
151# additional scenario for manual Fmsy and F_01 estimates
152config.forecast.manual_F01 <- 0.605
153config.forecast.manual_FMSY <- 0.64
154# custom calculations. Calculate partial recruitment for Y/R analysis
155config.custom.partial.years <- 2004:2020
156# custom calculations. Calculate F01 reference point from Y/R analysis
157config.custom.f01.years <- 2004:2020 # years used to calculate mean(wt), mean(Fi/Fmax), mean(M)
158config.custom.f01.plusgroup = TRUE # is last group is plus group?
159config.custom.f01.oldest = 5 # oldest fish found in waters (not in stock, that means "even somewhen exist in sea")
160# ******** GLOBAL CONFIGURATION DONE!!! **** #
161# ********************************************************* #
162# Do not change enything below if you have no idea what is going on
163# ********************************************************* #
164# simple write functions
165savePic <- function(path, imgObj, width=1900, height=1600, res=200) {
166png(path, width=width, height=height, res=res, type="cairo")
167print(plot(imgObj) + theme_bw())
168dev.off()
169}
170saveText <- function(path, object) {
171con <- file(path, encoding = "UTF-8")
172sink(con)
173print(object)
174sink()
175close(con)
176}
177# get mbar from stock object
178mbar <- function(stock) {
179stock.min <- as.numeric(stock@range["min"])
180stock.max <- as.numeric(stock@range["max"])
181bar.min <- as.numeric(stock@range["minfbar"])
182bar.max <- as.numeric(stock@range["maxfbar"])
183diff.min <- 1 + bar.min - stock.min
184diff.max <- 1 + bar.max - bar.min
185if (diff.max > stock.max+1)
186diff.max <- stock.max+1
187vec <- (m(stock)[diff.min:diff.max,])
188bar <- apply(vec, 2, mean)
189return(bar)
190}
191# read input data - stock
192tmp.stock <- read.csv("input/stock.csv", sep=",")
193data.stock <- as.FLStock(tmp.stock)
194# read input data - index
195tmp.idx1.idx <- read.csv("input/survey1/index.csv", sep=",")
196tmp.idx1.eff <- read.csv("input/survey1/effort.csv", sep=",")
197tmp.idx2.idx <- read.csv("input/survey2/index.csv", sep=",")
198tmp.idx2.eff <- read.csv("input/survey2/effort.csv", sep=",")
199data.index1 <- FLIndex(index=as.FLQuant(tmp.idx1.idx), effort=as.FLQuant(tmp.idx1.eff), catch.n=as.FLQuant(tmp.idx1.idx))
200data.index2 <- FLIndex(index=as.FLQuant(tmp.idx2.idx), effort=as.FLQuant(tmp.idx2.eff), catch.n=as.FLQuant(tmp.idx2.idx))
201remove(tmp.stock, tmp.idx1.idx, tmp.idx1.eff, tmp.idx2.idx, tmp.idx2.eff)
202print("[XSA toolkit]: Load data: OK")
203# Set name,desc from cfgs
204name(data.stock) <- config.stock.name
205desc(data.stock) <- config.stock.desc
206# set fbar ranges
207range(data.stock)[c("minfbar", "maxfbar")] <- c(config.stock.fbar.min, config.stock.fbar.max)
208# shift data starting from 2000
209data.stock <- window(data.stock, start = config.stock.window.start, end = config.stock.window.end)
210# set harvest.spwn and m.spwn = 0 if no data exist (or XSA throw error)
211if (config.stock.no_harvestspawn) {
212harvest.spwn(data.stock) <- 0
213}
214if (config.stock.no_mspawn) {
215m.spwn(data.stock) <- 0
216}
217# if no info about discards/landings separatly than set discards = 0, landings = catch
218if (config.stock.no_discards) {
219discards(data.stock) <- 0
220discards.n(data.stock) <- 0
221discards.wt(data.stock) <- catch.wt(data.stock)
222landings(data.stock) <- catch(data.stock)
223landings.n(data.stock) <- catch.n(data.stock)
224landings.wt(data.stock) <- catch.wt(data.stock)
225}
226stock.wt(data.stock) <- catch.wt(data.stock)
227# set cfgs for index1 and index2
228type(data.index1) <- config.index1.type
229name(data.index1) <- config.index1.name
230desc(data.index1) <- config.index1.desc
231range(data.index1)[c("startf", "endf")] <- c(config.index1.startf, config.index1.endf)
232type(data.index2) <- config.index2.type
233name(data.index2) <- config.index2.name
234desc(data.index2) <- config.index2.desc
235range(data.index2)[c("startf", "endf")] <- c(config.index2.startf, config.index2.endf)
236print("[XSA toolkit]: FLStock and FLIndex object configured successful")
237data.indices <- FLIndices(data.index1, data.index2)
238data.stock
239data.stock@catch
240data.stock@catch.n
241data.stock@catch.wt
242format(data.stock@catch.wt, scientific = F)
243source("~/Dev/R/phdpm2/sprat-xsa-experimental/run.R")
244library("devtools")
245install_github("ices-tools-prod/msy")
246source("~/Dev/R/phdpm2/sprat-xsa-experimental/run.R")
247data.stock
248# make Fse comparision test
249if (config.iter.fse) {
250print("[XSA toolkit]: Fse impact factor estimate")
251steps <- seq(0.5, 2.5, by = 0.5)
252fseIters <- c()
253for (i in 1:length(steps)) {
254ctl <- config.tuning.xsa
255ctl@fse <- steps[i]
256res <- FLXSA(data.stock, data.indices, ctl) + data.stock
257fseIters <- c(fseIters, res)
258}
259result.fse.summary <- FLStocks(fseIters)
260names(result.fse.summary) <- steps
261# save output to pic
262savePic("output/1_FseChoose/summary_all.png", result.fse.summary)
263# get latest 5 year window
264lastYear <- result.fse.summary[[1]]@range["maxyear"]
265tmpObj <- window(result.fse.summary, lastYear-config.retro.horizon, lastYear)
266savePic("output/1_FseChoose/summary_short.png", tmpObj)
267remove(lastYear, tmpObj)
268# save text output - ssb
269con <- file("output/1_FseChoose/ssb.txt", encoding = "UTF-8")
270sink(con)
271for (i in 1:length(steps)) {
272print(sprintf("============= SSB at Fse = %s", steps[i]))
273print(ssb(result.fse.summary[[i]]))
274cat("\r\n")
275}
276sink()
277close(con)
278# save text output - rec
279con <- file("output/1_FseChoose/rec.txt", encoding = "UTF-8")
280sink(con)
281for (i in 1:length(steps)) {
282print(sprintf("============= Recruitment at Fse = %s", steps[i]))
283print(rec(result.fse.summary[[i]]))
284cat("\r\n")
285}
286sink()
287close(con)
288# save text output - fbar
289con <- file("output/1_FseChoose/fbar.txt", encoding = "UTF-8")
290sink(con)
291for (i in 1:length(steps)) {
292print(sprintf("============= Fbar at Fse = %s", steps[i]))
293print(fbar(result.fse.summary[[i]]))
294cat("\r\n")
295}
296sink()
297close(con)
298remove(steps, fseIters, ctl, res, con)
299}
300source("~/Dev/R/phdpm2/sprat-xsa-experimental/clean-output.R")
301source("~/Dev/R/phdpm2/sprat-xsa-experimental/run.R")
302source("~/Dev/R/phdpm2/sprat-xsa-experimental/clean-output.R")
303source("~/Dev/R/phdpm2/sprat-xsa-experimental/run.R")
304source("~/Dev/R/phdpm2/sprat-xsa-experimental/clean-output.R")
305source("~/Dev/R/phdpm2/sprat-xsa-experimental/run.R")
306print(paste0("Rho ssb=", round(result.retro.mohnrho.ssb, 3)))
307print(paste0("Rho F=", round(result.retro.mohnrho.fbar, 3)))
308?FLXSA.control
309data.stock
310data.stock@catch.n
311# ************************************* #
312# Author: Piatinskii M., Azov-black sea bench of VNIRO
313# © 2019
314# **************************************#
315# make cleanup
316rm(list = ls(all.names=TRUE))
317# load libraries
318library("FLCore")
319library("FLXSA")
320library("FLAssess")
321library("ggplotFL")
322# library("FLBRP") # no support for R 4.0, require compilation from *nix
323library("FLash")
324#install.packages("devtools")
325#install_github("ices-tools-prod/msy")
326library("msy")
327library("rmarkdown")
328library("dplyr")
329library("magrittr")
330library("tibble")
331library("icesAdvice")
332# ****** GLOBAL CONFIGURATIONS SECTION *******#
333# stock object configurations
334config.stock.name <- "Sprattus sprattus" # fish title
335config.stock.desc <- "Sprat stock information in FLCore format from 2000years" # fish stock description
336config.stock.fbar.min <- 1 # minimum fish age become fishing (Fbar min)
337config.stock.fbar.max <- 3 # maximum fish age at fishing (Fbar max)
338config.stock.no_harvestspawn <- TRUE # Set TRUE if there is no information about fishing before spawning
339config.stock.no_mspawn <- TRUE # Set TRUE if no information about natural mortality before spawning
340config.stock.no_discards <- TRUE # Set TRUE if no separated information about landing/discards exist (only catch)
341config.stock.window.start <- 1994 # model start
342config.stock.window.end <- 2022 # model end
343# configure surveys indices
344config.index1.name <- "Sprat crimea cpue index"
345config.index1.desc <- "Fishery index information about sprat abundance at Crimea shelf from real fishing surveys"
346config.index1.startf <- 0.3 # start month of survey in format month/12, example: 1 feb = 2/12 = 0.166
347config.index1.endf <- 0.7 # end month of survey in format month/12
348config.index1.type <- "number" # type of survey, allowed: number, biomass
349# same with previous
350config.index2.name <- "Sprat caucasian cpue index"
351config.index2.desc <- "Fishery index information about sprat abundance at Caucasian shelf from real fishing surveys"
352config.index2.startf <- 0.3
353config.index2.endf <- 0.7
354config.index2.type <- "number"
355# pre-analysis diagnostic procedures. Useful to choice the model parametrization, convergence, etc
356config.iter.fse = TRUE # Fse choice procedure
357config.iter.retro = TRUE # retrospective procedure
358config.iter.fseage = TRUE # Fse at age impact procedure
359# configure retrospective depth
360config.retro.horizon <- 5
361# Shrinkage standard error max value. Default value Fse = 0.5
362# Higher shrinkage se leads to high unrestraint of estimating procedure.
363config.tuning.xsa <- FLXSA.control(
364maxit = 100, # maximum covergence iterations
365fse = 1.5, # shrinkage s.e value
366shk.n = T,
367shk.f = T,
368shk.yrs = 4,
369tsrange = 15, # weighting time series length (from latest year)
370tspower = 3, # weighting procedure sequence (1 = linear, 2 = square, 3 = cubic)
371qage = 2, # age after catchability not depends on age
372)
373# sr model configuration
374config.srmodel.eqsim.use = TRUE # should we use eqsim package insted of FLSR default?
375config.srmodel.use_geomean = FALSE # set FALSE to use EQSIM SR model results to forecasting
376# eqsim model configurations (if config.srmodel.eqsim.use = TRUE)
377config.srmodel.eqsim.models = c("Segreg") # types of model to fit and compare
378config.srmodel.eqsim.simulations = 10 # number of simulations
379config.srmodel.eqsim.shift_years <- 1994:2005 # remove years from sr-model fitting
380# flsr model configuration (if config.srmodel.eqsim.use = FALSE)
381config.srmodel.type <- segregAR1() # SR model type: ricker(), bevholt(), geomean(), segreg(), shepherd(), cushing(), AR in model name = AutoCorrelation fix
382config.srmodel.optimization = FALSE # Use optimization procedure for SR model fitting?
383# configure MSY reference point calculation: Blim, Bpa, Fmsy
384config.brp.blim_multiplier <- 0.2 # multiplier of SSBmax to get Blim ref.point, allowed: 0.2 - 0.4
385config.brp.trim_uncertainity <- TRUE # trim uncerteinity extreme deviations? Optimization procedure for Bpa estimate
386config.brp.current_range <- 2003:2021 # shift previous population states from BRP calculations
387# Custom forecast scenarious. By default performed: F_SQ, F_01, F_msy scenarious.
388# There you can define f(y+1), f(y+2), f(y+3) targets for 2 scenarious
389# precautionary scenario: Fpa = FMSY * (B2022/Btr) = 0.64 * 66/87.5 = 0.482
390config.forecast.scenario1.f_year1 <- 0.48
391config.forecast.scenario1.f_year2 <- 0.48
392config.forecast.scenario1.f_year3 <- 0.48
393# Scenario MSY at M = 0,95
394# by old STECF (2010) results
395config.forecast.scenario2.f_year1 <- 0.95
396config.forecast.scenario2.f_year2 <- 0.95
397config.forecast.scenario2.f_year3 <- 0.95
398# additional scenario for manual Fmsy and F_01 estimates
399config.forecast.manual_F01 <- 0.605
400config.forecast.manual_FMSY <- 0.64
401# custom calculations. Calculate partial recruitment for Y/R analysis
402config.custom.partial.years <- 2004:2020
403# custom calculations. Calculate F01 reference point from Y/R analysis
404config.custom.f01.years <- 2004:2020 # years used to calculate mean(wt), mean(Fi/Fmax), mean(M)
405config.custom.f01.plusgroup = TRUE # is last group is plus group?
406config.custom.f01.oldest = 5 # oldest fish found in waters (not in stock, that means "even somewhen exist in sea")
407# ******** GLOBAL CONFIGURATION DONE!!! **** #
408# ********************************************************* #
409# Do not change enything below if you have no idea what is going on
410# ********************************************************* #
411# simple write functions
412savePic <- function(path, imgObj, width=1900, height=1600, res=200) {
413png(path, width=width, height=height, res=res, type="cairo")
414print(plot(imgObj) + theme_bw())
415dev.off()
416}
417saveText <- function(path, object) {
418con <- file(path, encoding = "UTF-8")
419sink(con)
420print(object)
421sink()
422close(con)
423}
424# get mbar from stock object
425mbar <- function(stock) {
426stock.min <- as.numeric(stock@range["min"])
427stock.max <- as.numeric(stock@range["max"])
428bar.min <- as.numeric(stock@range["minfbar"])
429bar.max <- as.numeric(stock@range["maxfbar"])
430diff.min <- 1 + bar.min - stock.min
431diff.max <- 1 + bar.max - bar.min
432if (diff.max > stock.max+1)
433diff.max <- stock.max+1
434vec <- (m(stock)[diff.min:diff.max,])
435bar <- apply(vec, 2, mean)
436return(bar)
437}
438# read input data - stock
439tmp.stock <- read.csv("input/stock.csv", sep=",")
440data.stock <- as.FLStock(tmp.stock)
441# read input data - index
442tmp.idx1.idx <- read.csv("input/survey1/index.csv", sep=",")
443tmp.idx1.eff <- read.csv("input/survey1/effort.csv", sep=",")
444tmp.idx2.idx <- read.csv("input/survey2/index.csv", sep=",")
445tmp.idx2.eff <- read.csv("input/survey2/effort.csv", sep=",")
446data.index1 <- FLIndex(index=as.FLQuant(tmp.idx1.idx), effort=as.FLQuant(tmp.idx1.eff), catch.n=as.FLQuant(tmp.idx1.idx))
447data.index2 <- FLIndex(index=as.FLQuant(tmp.idx2.idx), effort=as.FLQuant(tmp.idx2.eff), catch.n=as.FLQuant(tmp.idx2.idx))
448remove(tmp.stock, tmp.idx1.idx, tmp.idx1.eff, tmp.idx2.idx, tmp.idx2.eff)
449print("[XSA toolkit]: Load data: OK")
450# Set name,desc from cfgs
451name(data.stock) <- config.stock.name
452desc(data.stock) <- config.stock.desc
453# set fbar ranges
454range(data.stock)[c("minfbar", "maxfbar")] <- c(config.stock.fbar.min, config.stock.fbar.max)
455# shift data starting from 2000
456data.stock <- window(data.stock, start = config.stock.window.start, end = config.stock.window.end)
457# set harvest.spwn and m.spwn = 0 if no data exist (or XSA throw error)
458if (config.stock.no_harvestspawn) {
459harvest.spwn(data.stock) <- 0
460}
461if (config.stock.no_mspawn) {
462m.spwn(data.stock) <- 0
463}
464# if no info about discards/landings separatly than set discards = 0, landings = catch
465if (config.stock.no_discards) {
466discards(data.stock) <- 0
467discards.n(data.stock) <- 0
468discards.wt(data.stock) <- catch.wt(data.stock)
469landings(data.stock) <- catch(data.stock)
470landings.n(data.stock) <- catch.n(data.stock)
471landings.wt(data.stock) <- catch.wt(data.stock)
472}
473stock.wt(data.stock) <- catch.wt(data.stock)
474# set cfgs for index1 and index2
475type(data.index1) <- config.index1.type
476name(data.index1) <- config.index1.name
477desc(data.index1) <- config.index1.desc
478range(data.index1)[c("startf", "endf")] <- c(config.index1.startf, config.index1.endf)
479type(data.index2) <- config.index2.type
480name(data.index2) <- config.index2.name
481desc(data.index2) <- config.index2.desc
482range(data.index2)[c("startf", "endf")] <- c(config.index2.startf, config.index2.endf)
483print("[XSA toolkit]: FLStock and FLIndex object configured successful")
484data.stock@catch.n
485data.stock@catch.wt
486data.stock@catch.wt*1000
487data.stock@catch.wt*1000000
488data.stock@catch
489source("~/Dev/R/phdpm2/sprat-xsa-experimental/run.R")
490source("~/Dev/R/phdpm2/sprat-xsa-experimental/run.R")
491data.stock
492data.stock@catch.n * data.stock@catch.wt
493format(data.stock@catch.wt*1000000, scientific = F)
494data.stock@catch.wt*1000000
495data.stock@catch.wt*data.stock@catch.n
496data.stock@catch.n
497source("~/Dev/R/phdpm2/sprat-xsa-experimental/run.R")
498source("~/Dev/R/phdpm2/sprat-xsa-experimental/run.R")
499source("~/Dev/R/phdpm2/sprat-xsa-experimental/run.R")
500result.forecast.F_scenario1
501result.forecast.F_scenario1@stock.n
502result.forecast.F_MSY@harvest
503result.forecast.F_MSY@stock.n
504result.forecast.F_MSY@harvest
50519*0.75
50627*0.75
50726*0.25
50826*0.75
50915*0.75
51020*0.75
51146+15
51261*0.75
513