Title: | Running the JJM Stock Assessment Model Inside the MSE FLR System |
---|---|
Description: | Runs the JJM stock assessment model for Chilean Jack Mackerel inside the MSE system of FLR's mse package. |
Authors: | Iago Mosqueira [aut, cre], Karolina Molla Gazi [aut] |
Maintainer: | Iago Mosqueira <[email protected]> |
License: | EUPL |
Version: | 0.2.0.9002 |
Built: | 2024-11-19 11:21:05 UTC |
Source: | https://github.com/SPRFMO/FLjjm |
Combines results from two sources of fisheries model runs, handling both single and multiple stock scenarios. It combines data such as stock numbers, harvest, data, and control.
.combinejjmsout(x, y)
.combinejjmsout(x, y)
x |
First set of fisheries model results. |
y |
Second set of fisheries model results. |
A combined list of fisheries model results.
This function converts age composition data to length composition data based on provided length-height (lh) relationships, selectivity (S_a), and other parameters.
AgeToLengthComp(lh, S_a, tyears, N_at, comp_sample, sample_type = "catch")
AgeToLengthComp(lh, S_a, tyears, N_at, comp_sample, sample_type = "catch")
lh |
A data frame or list containing length-height relationship data. |
S_a |
Matrix of selectivity at age. |
tyears |
Total number of years in the data. |
N_at |
Matrix of numbers at age over time. |
comp_sample |
Vector of sample sizes for each year. |
sample_type |
Type of sample, default is 'catch'. Can be 'catch' or other types. |
A list containing matrices: probabilities being in a length bin given age (plba), probabilities being harvested at an age (page), probabilities of sampling a given length bin (plb), and length frequencies (LF).
These functions are used to build various FLR (Fisheries Library in R) objects from the output of the JJMS (Just Another Management Strategy) stock assessment model. The functions handle different types of outputs including biological, fishery, stock, and index data.
The primary functions include:
buildFLBjjm
: Constructs an FLBiol object from jjm.output.
buildFLBsjjm
: Builds multiple FLBiol objects from jjm.output.
buildFLFsjjm
: Creates FLFisheries objects from jjm.output.
buildFLIsjjm
: Generates FLIndices objects from jjm.output.
buildFLRPsjjm
: Constructs FLPar objects with reference points from jjm.output.
buildFLSojjm
: Builds FLStock objects from jjm.output considering areas.
buildFLSjjm
: Constructs FLStock objects from jjm.output.
buildFLSsjjm
: Creates multiple FLStock objects from jjm.output.
Each function takes a jjm.output object as input, which is the result of running the JJMS model. They process this output into various FLR objects for further analysis and use within the FLR framework.
Iago Mosqueira (WMR) [email protected]
FLBiol
, FLFisheries
,
FLIndices
, FLStock
Build an FLBiol from a jjm.output object
buildFLBjjm(out, stock = 1, name = "CJM")
buildFLBjjm(out, stock = 1, name = "CJM")
out |
A jjm.output object, as returned by readJJM. |
stock |
Stock to extract, of relevance on 2-stock model runs, numeric. |
spwn |
Proportion of the year when spawning takes place. |
An object of class FLBiol.
Constructs an FLFisheries
object from a JJMS model output, processing data for
each fishery and creating corresponding FLCatch
and FLFishery
objects.
buildFLFsjjm(out, stock = 1)
buildFLFsjjm(out, stock = 1)
out |
JJMS model output object. |
stock |
The stock number to extract fisheries data for, default is 1. |
An FLFisheries
object constructed from the JJMS model output.
This function creates an FLIndices
, a list of FLIndexBiomass
objects,
each of them containing the data and estimates of a single index of abundance.
Slots on each FLIndexBiomass
object are filled with the following information:
index: data$Index
.
index.var: data$Indexerr
.
catch.n: data$Ipropage
.
catch.wt: data$Iwtatage
.
effort: Empty.
sel.pattern: output@sel_ind_i
, where i
refers to the index number.
index.q: output@q_i
, where i
refers to the index number.
range 'startf' and 'endf': (data$Imonths
- 1) / 12.
buildFLIsjjm(out)
buildFLIsjjm(out)
out |
A one or two-stock, single run, jjm.output object. |
stock=1 |
Stock for which indices are to be loaded. |
An FLIndices
object.
idx <- readFLIsjjm("h1_1.07", path = system.file("ext-data", "single_stock", package="FLjjm")) summary(idx) plot(idx)
idx <- readFLIsjjm("h1_1.07", path = system.file("ext-data", "single_stock", package="FLjjm")) summary(idx) plot(idx)
An object of class FLPar is created from the information in a jjm.output
object and for a given stock, if more than one is present.
The function currently extracts the following reference points from the
msy_mt
data.frame in the output
element of jjm.output
:
MSY: Maximum Sustainable Yield, in thousands of tonnes.
SB0: Virgin spawning biomass, in thousands of tonnes.
SBmsy: Spawning biomass at MSY, in thousands of tonnes.
Fmsy: Fishing mortality at MSY.
buildFLRPsjjm(out, stock = 1)
buildFLRPsjjm(out, stock = 1)
name |
Name of the ctl model file, character. |
path |
Path ot the model folder structure, character. |
stock=1 |
Stock to extract, of relevance on 2 stocks model runs, numeric. |
An object of class FLPar.
jjmR::readJJM FLCore::FLBiol buildFLBjjm
rps <- readFLRPsjjm(name = "h1_1.07", path = system.file("ext-data", "single_stock", package="FLjjm")) summary(rps)
rps <- readFLRPsjjm(name = "h1_1.07", path = system.file("ext-data", "single_stock", package="FLjjm")) summary(rps)
This function creates a collection of FLStock objects from a jjm.output object. It is particularly useful for multi-stock assessments.
This function creates a collection of FLStock objects from a jjm.output object. It is particularly useful for multi-stock assessments.
buildFLSsjjm(out) buildFLSsjjm(out)
buildFLSsjjm(out) buildFLSsjjm(out)
out |
A jjm.output object, typically the output of a stock assessment model. |
An FLStocks object containing multiple FLStock objects.
An FLStocks object containing multiple FLStock objects.
Updating dat and ctl file lists from FLstock(s) and FLIndices
buildjjmctl(stk, idx, dat, ctl, ...)
buildjjmctl(stk, idx, dat, ctl, ...)
stk |
TODO:description |
idx |
TODO:description |
dat |
TODO:description |
ctl |
TODO:description |
TODO:description
data(cjmstk) ctl <- buildjjmctl(stk, idx, mod$data, mod$control) data(cjmstks) ctl <- buildjjmctl(stks, idxs, mods$data, mods$control)
data(cjmstk) ctl <- buildjjmctl(stk, idx, mod$data, mod$control) data(cjmstks) ctl <- buildjjmctl(stks, idxs, mods$data, mods$control)
This method calculates the total catch by summing the catch (accounting for area sums) of each FLStock object within an FLStocks object.
## S4 method for signature 'FLStocks' catch(object)
## S4 method for signature 'FLStocks' catch(object)
object |
An FLStocks object. |
A numeric value representing the total catch.
Updates stock and index observations in a CJM fishery operation model based on provided arguments, tracking information, and F3 selectivity.
cjm.oem(stk, deviances, observations, args, tracking, F3sel)
cjm.oem(stk, deviances, observations, args, tracking, F3sel)
stk |
Stock data. |
deviances |
Deviances for the model. |
observations |
Observations data. |
args |
Argument list containing model parameters. |
tracking |
Tracking information. |
F3sel |
F3 selectivity data. |
A list with updated stock data, indices, observations, and tracking information.
This function updates stock observations and indices in a fishery operation model (OM) based on provided arguments and tracking information.
cjm2.oem(om, deviances, observations, args, tracking)
cjm2.oem(om, deviances, observations, args, tracking)
om |
Fishery operation model object. |
deviances |
Deviances for the model. |
observations |
Observations data. |
args |
Argument list containing model parameters. |
tracking |
Tracking information. |
A list with updated stock data, indices, observations, and tracking information.
This function converts age composition data from landings to length composition using specified biological parameters and selectivity.
cjmage2len( landings, selex, ess = 100, L_inf = 80.4, k = 0.16, L_0 = 18, M = 0.33, CVlen = 0.09, ages = an(dimnames(landings)$age), sample_type = "catch" )
cjmage2len( landings, selex, ess = 100, L_inf = 80.4, k = 0.16, L_0 = 18, M = 0.33, CVlen = 0.09, ages = an(dimnames(landings)$age), sample_type = "catch" )
landings |
Matrix of landings at age. |
selex |
Matrix of selectivity at age. |
ess |
Effective sample size for each year, default is 100. |
L_inf |
Asymptotic length, default is 80.4. |
k |
Growth coefficient, default is 0.16. |
L_0 |
Theoretical length at age zero, default is 18. |
M |
Natural mortality rate, default is 0.33. |
CVlen |
Coefficient of variation in length, default is 0.09. |
ages |
Vector of ages, default is derived from landings. |
sample_type |
Type of sampling, default is 'catch'. |
A matrix representing length composition for each year.
Converts FLQuants
objects, typically returned by a Harvest Control Rule (HCR) module,
into a fwdControl
object with different behavior based on the number of stocks.
cjmfwc(flqs, quant = "catch", nstocks = 1)
cjmfwc(flqs, quant = "catch", nstocks = 1)
flqs |
An |
quant |
The quant to use, defaults to 'catch'. |
nstocks |
Number of stocks, defaults to 1. |
A fwdControl
object with the corresponding FCB slot.
This function creates a perfect observation error model for a stock assessment, adjusting the stock data to match observations.
cperfect.oem( stk, deviances, observations, args, tracking, biomass = FALSE, ... )
cperfect.oem( stk, deviances, observations, args, tracking, biomass = FALSE, ... )
stk |
Stock data. |
deviances |
Deviances for the model. |
observations |
Observations data. |
args |
Argument list. |
tracking |
Tracking information. |
biomass |
Boolean, if TRUE, use biomass instead of numbers. |
... |
Additional arguments. |
A list with updated stock data, index, observations, and tracking.
Executes the JJMS model with specified arguments, manages file operations for the model run, and optionally cleans up the output directory.
exejjms(name, path, args = "", verbose = TRUE, clean = TRUE)
exejjms(name, path, args = "", verbose = TRUE, clean = TRUE)
name |
The name of the JJMS model. |
path |
The path to the directory where the JJMS model is located. |
args |
Additional arguments for the JJMS model execution. |
verbose |
If TRUE, prints the execution log to the console. |
clean |
If TRUE, cleans up the output directory after model execution. |
Invisible path where the model was executed.
This method calculates the average fishing mortality (fbar) across multiple FLStock objects contained within an FLStocks object.
## S4 method for signature 'FLStocks' fbar(object)
## S4 method for signature 'FLStocks' fbar(object)
object |
An FLStocks object. |
A numeric value representing the average fishing mortality.
This package provides tools for the Fishery Library (FLR) to interact with the JJMS (Just Another Management Strategy) stock assessment model. The package includes functions for building, reading, and executing JJMS assessments within the FLR framework.
The main functions include:
buildFLjjm
: Function to build FLjjm objects.
readFLjjm
: Function to read FLjjm data from files.
loadJJMS
: Function to load JJMS data.
exejjms
: Function to execute the JJMS model.
runjjms
: Function to run JJMS simulations.
jjms
: General function for JJMS model operations.
The package aims to facilitate the integration of JJMS model outputs with the FLR tools for fisheries science and management strategy evaluation.
Iago Mosqueira (WMR) [email protected]
Karolina Molla Gazi (WMR) [email protected]
FLjjm
in the FLjjm package for an
overview of the package.
This function performs a forward movement simulation on a fishery model object using specified control measures and rates over time.
fwdmov(object, control, rates, time = 0)
fwdmov(object, control, rates, time = 0)
object |
The fishery model object to be simulated. |
control |
A data frame or matrix containing control measures for each year. |
rates |
A list or vector of rates used in the simulation. |
time |
An optional time parameter, default is 0. |
The updated fishery model object after applying the forward movement simulation.
Simulates the movement of fish populations between two areas in a fishery operation model. Adjusts population numbers based on movement rates, fishing mortality, and natural mortality.
fwdmov.om(om, ctrl, FCB = FCB(ctrl), rates, time = 0, ...)
fwdmov.om(om, ctrl, FCB = FCB(ctrl), rates, time = 0, ...)
om |
A fishery operation model object. |
ctrl |
Control measures data frame or matrix. |
FCB |
Fishing mortality, default is derived from |
rates |
Movement rates matrix. |
time |
Time step for the simulation, default is 0. |
... |
Additional arguments. |
A list containing the updated fishery operation model object.
Executes the JJMS model for fisheries stock assessment. Handles both single and multiple stocks and can operate in parallel or sequentially. Updates the stock data with the results from the model runs.
jjms( stock, indices, dat, ctl, path = tempfile(), mp = FALSE, clean = mp, lengthcomp_F3 = NULL )
jjms( stock, indices, dat, ctl, path = tempfile(), mp = FALSE, clean = mp, lengthcomp_F3 = NULL )
stock |
FLStock or list of FLStocks for assessment. |
indices |
Indices data for the model. |
dat |
Data for each iteration of the model. |
ctl |
Control settings for each iteration. |
path |
Path to save temporary files, defaults to a temporary file path. |
mp |
If TRUE, runs in parallel; otherwise, runs sequentially. |
clean |
If TRUE, cleans up temporary files after execution. |
lengthcomp_F3 |
Optional length composition data for F3. |
The updated FLStock or list of FLStocks after model execution.
Performs a JJMS stock assessment, modifying and running the JJMS model with provided arguments.
jjms.sa(stk, idx, args, tracking, ...)
jjms.sa(stk, idx, args, tracking, ...)
stk |
Stock data. |
idx |
Index data. |
args |
Argument list. |
tracking |
Tracking information. |
... |
Additional arguments. |
A list with the resulting stock data, tracking information, and arguments.
This function loads FLStocks from JJMS model directories located at a specified path. It can handle both single and multiple stock scenarios and offers an option to combine the loaded stocks into a single object.
loadFLSjjms(path, combine = FALSE)
loadFLSjjms(path, combine = FALSE)
path |
The path to the directory containing the JJMS model data. |
combine |
Boolean, if TRUE, combine the loaded FLStocks into a single object. |
FLStocks object(s) loaded from the specified path.
Loads a JJMS model from a given path and constructs various components of a fisheries model, including biological data, fisheries data, indices, reference points, and stock data.
loadJJMS(name, path)
loadJJMS(name, path)
name |
The name of the JJMS model. |
path |
The path to the directory containing the JJMS model data. |
A list containing biological data, fisheries data, indices, reference points, stock data, and model data and control settings.
Reads the first configuration file in a JJMS model directory to extract the model's name.
namejjms(path)
namejjms(path)
path |
The path to the directory containing the JJMS model data. |
A string with the name of the JJMS model.
Reads a JJMS model control file to determine the number of stocks.
nStocksjjms(name, path)
nStocksjjms(name, path)
name |
The name of the JJMS model. |
path |
The path to the directory containing the JJMS model data. |
Numeric value representing the number of stocks in the JJMS model.
Removes unnecessary files from a JJMS model run directory, keeping only essential files.
packjjmsrun(path)
packjjmsrun(path)
path |
The path to the JJMS model run directory. |
Invisible TRUE if all files are successfully removed, FALSE otherwise.
A placeholder function for perfect CJM stock assessment, potentially for testing or method development purposes.
perfcjm.sa(stk, idx, args, tracking, ...)
perfcjm.sa(stk, idx, args, tracking, ...)
stk |
Stock data. |
idx |
Index data. |
args |
Argument list. |
tracking |
Tracking information. |
... |
Additional arguments. |
A list with stock data, tracking information, and arguments.
An object of class FLBiol is created from the information in the various files in a jjms folder structure. See buildFLBjjm for how each slot is populated from the inputs and outputs of jjms.
readFLBjjm(name, path, stock = 1)
readFLBjjm(name, path, stock = 1)
name |
Name of the ctl model file, character. |
path |
Path ot the model folder structure, character. |
stock=1 |
Stock to extract, of relevance on 2 stocks model runs, numeric. |
An object of class FLBiol.
jjmR::readJJM FLCore::FLBiol buildFLBjjm
bio <- readFLBjjm(name="h1_1.07", path=system.file("ext-data", "single_stock", package="FLjjm")) summary(bio)
bio <- readFLBjjm(name="h1_1.07", path=system.file("ext-data", "single_stock", package="FLjjm")) summary(bio)
An object of class FLFisheries, a list of FLFishery objects, is created from the information in the various files in a jjms folder structure. See buildFLFsjjm for how each slot is populated from the inputs and outputs of jjms.
readFLFsjjm(name, path)
readFLFsjjm(name, path)
name |
Name of the ctl model file, character. |
path |
Path ot the model folder structure, character. |
An object of class FLIndices.
jjmR::readJJM FLFishery::FLFisheries FLFishery::FLFishery buildFLFsjjm
fisheries <- readFLFsjjm(name="h1_1.07", path = system.file("ext-data", "single_stock", package="FLjjm")) summary(fisheries)
fisheries <- readFLFsjjm(name="h1_1.07", path = system.file("ext-data", "single_stock", package="FLjjm")) summary(fisheries)
An object of class FLIndices, a list of FLIndex objects, is created from the information in the various files in a jjms folder structure. See buildFLIsjjm for how each slot is populated from the inputs and outputs of jjms.
readFLIsjjm(name, path)
readFLIsjjm(name, path)
name |
Name of the ctl model file, character. |
path |
Path ot the model folder structure, character. |
An object of class FLIndices.
jjmR::readJJM FLCore::FLIndices FLCore::FLIndex buildFLIsjjm
indices <- readFLIsjjm(name="h1_1.07", path = system.file("ext-data", "single_stock", package="FLjjm")) summary(indices)
indices <- readFLIsjjm(name="h1_1.07", path = system.file("ext-data", "single_stock", package="FLjjm")) summary(indices)
An object of class FLoem is created from the information in the various files in a jjms folder structure. The @observations slot is created containing the past observations of catch and biology (as an FLStock or FLStocks) and for the indices of abundance (as an FLIndices)
readFLoemjjm(name, path, method = cjm.oem, iter = 1, ...)
readFLoemjjm(name, path, method = cjm.oem, iter = 1, ...)
name |
Name of the ctl model file, character. |
path |
Path to the model folder structure, character. |
An object of class FLoem.
jjmR::readJJM mse::FLoem buildFLSjjm buildFLIsjjm
# One stock OM oem <- readFLoemjjm(name="h1_1.07", path=system.file("ext-data", "single_stock", package="FLjjm")) oem # Two stock OM oemtwo <- readFLoemjjm(name="h2_1.07", path=system.file("ext-data", "two_stock", package="FLjjm")) oemtwo
# One stock OM oem <- readFLoemjjm(name="h1_1.07", path=system.file("ext-data", "single_stock", package="FLjjm")) oem # Two stock OM oemtwo <- readFLoemjjm(name="h2_1.07", path=system.file("ext-data", "two_stock", package="FLjjm")) oemtwo
An object of class FLombf is created from the information in the various files in a jjms folder structure. Three slots are created from the corresponding calls to buildFLjjm functions.
@biols, of class FLBiols from a call to buildFLBsjjm.
@fisheries, of class FLFisheries, from a call to buildFLFsjjm.
@refpts, of classs FLPars, from a call to buildFLRPsjjm.
readFLomjjm(name, path, iter = NULL, ...)
readFLomjjm(name, path, iter = NULL, ...)
name |
Name of the ctl model file, character. |
path |
Path to the model folder structure, character. |
An object of class FLBiol.
jjmR::readJJM FLombf buildFLBjjm buildFLFsjjm
# One stock OM om <- readFLomjjm(name="h1_1.07", path=system.file("ext-data", "single_stock", package="FLjjm")) summary(om) # Two stock OM omtwo <- readFLomjjm(name="h2_1.07", path=system.file("ext-data", "two_stock", package="FLjjm")) summary(omtwo)
# One stock OM om <- readFLomjjm(name="h1_1.07", path=system.file("ext-data", "single_stock", package="FLjjm")) summary(om) # Two stock OM omtwo <- readFLomjjm(name="h2_1.07", path=system.file("ext-data", "two_stock", package="FLjjm")) summary(omtwo)
An object of class FLPar is created from the information in the output files in a jjms folder structure. See buildFLRPsjjm to check what reference points are being extracted from the inputs outputs of jjms.
readFLRPsjjm(name, path, stock = 1)
readFLRPsjjm(name, path, stock = 1)
name |
Name of the ctl model file, character. |
path |
Path ot the model folder structure, character. |
stock=1 |
Stock to extract, of relevance on 2 stocks model runs, numeric. |
An object of class FLPar.
jjmR::readJJM FLCore::FLBiol buildFLBjjm
rps <- readFLRPsjjm(name="h1_1.07", path=system.file("ext-data", "single_stock", package="FLjjm")) summary(rps)
rps <- readFLRPsjjm(name="h1_1.07", path=system.file("ext-data", "single_stock", package="FLjjm")) summary(rps)
An object of class FLStock is created from the information in the various files in a jjms folder structure. See buildFLSjjm for how each slot is populated from the inputs and outputs of jjms.
readFLSjjm(name, path, stock = 1, output = TRUE)
readFLSjjm(name, path, stock = 1, output = TRUE)
name |
Name of the ctl model file, character. |
path |
Path ot the model folder structure, character. |
stock=1 |
Stock to extract, of relevance on 2 stocks model runs, numeric. |
An object of class FLStock.
jjmR::readJJM FLCore::FLStock buildFLSjjm
bio <- readFLSjjm(name="h1_1.07", path = system.file("ext-data", "single_stock", package="FLjjm")) summary(bio)
bio <- readFLSjjm(name="h1_1.07", path = system.file("ext-data", "single_stock", package="FLjjm")) summary(bio)
An object of class FLStocks is created from the information in the various files in a jjms folder structure. See buildFLSjjm for how each slot is populated from the inputs and outputs of jjms.
readFLSsjjm(name, path, output = FALSE)
readFLSsjjm(name, path, output = FALSE)
name |
Name of the ctl model file, character. |
path |
Path ot the model folder structure, character. |
An object of class FLStock.
jjmR::readJJM FLCore::FLStock buildFLSjjm
bio <- readFLSsjjm(name="h2_1.07", path=system.file("ext-data", "two_stock", package="FLjjm"), output=TRUE) summary(bio)
bio <- readFLSsjjm(name="h2_1.07", path=system.file("ext-data", "two_stock", package="FLjjm"), output=TRUE) summary(bio)
Executes the JJMS model with the given model data, saving the model files to a specified path. The function creates necessary directories, writes model files, and calls the JJMS model.
runjjms(mod, path = tempfile(), args = "", verbose = TRUE)
runjjms(mod, path = tempfile(), args = "", verbose = TRUE)
mod |
The JJMS model data to be executed. |
path |
The path to save model files and run the JJMS model, defaults to a temporary file path. |
args |
Additional arguments for the JJMS model execution. |
verbose |
If TRUE, execution details are printed; otherwise, they are suppressed. |
The path where the JJMS model was executed.
This method calculates the total spawning stock biomass (ssb) by summing the ssb of each FLStock object within an FLStocks object.
## S4 method for signature 'FLStocks' ssb(object)
## S4 method for signature 'FLStocks' ssb(object)
object |
An FLStocks object. |
A numeric value representing the total spawning stock biomass.
This function constructs various components of a fisheries model from a given model object. It builds biological data, fisheries data, indices, reference points, and stock data.
yourFunctionName(mod)
yourFunctionName(mod)
mod |
The model object from which components are to be constructed. |
A list containing biological data, fisheries data, indices, reference points, stock data, and model data and control settings.