Skip to content
Rob Scott edited this page Feb 2, 2021 · 9 revisions

Welcome to the ofp-sam-flr4mfcl wiki! In these pages we will try to lay out the design and structure of the package. We do not intend to provide a comprehensive description of the code here, but rather to give an overview of the package design along with a number of example scripts to demonstrate functionality.

In the description that follows we assume some familiarity with MFCL and its various input and output files. If you don't know much about MFCL you can find out more here.

NOTE: These pages are under development and not all links are currently working.

FLR4MFCL design

The code follows an object oriented design structured predominantly around the various input and output files of MFCL with a range of methods and functions that perform actions on those objects. The code follows a similar design to that of FLR and makes extensive use of the FLQuant object as the basic data structure from which more complex classes are constructed. The functionality of the FLQuant object is inherited directly from the FLCore package. However, the use of FLR does not extend much beyond the FLQuant. The remaining classes of FLR do not feature in FLR4MFCL.

Each input file is represented by a class that comprises a number of slots to hold specific information. In the example below the 'frq' object is of class MFCLFrq and contains all of the necessary information to represent an MFCL .frq input file.

> class(frq)
[1] "MFCLFrq"
attr(,"package")
[1] "FLR4MFCL"
> getSlots(class(frq))
        n_regions       n_fisheries      n_tag_groups         n_recs_yr         rec_month generic_diffusion 
        "numeric"         "numeric"         "numeric"         "numeric"         "numeric"         "logical" 
      frq_age_len       frq_version       region_size       region_fish       move_matrix        data_flags 
        "logical"         "numeric"         "FLQuant"         "FLQuant"          "matrix"          "matrix" 
     season_flags         n_move_yr        move_weeks             range          lf_range          age_nage 
         "matrix"         "numeric"         "numeric"         "numeric"         "numeric"         "numeric" 
             freq 
     "data.frame" 

The individual slots of each class can be accessed, and modified, using slot accessor functions as below.

> n_regions(frq)
[1] 8
> n_regions(frq) <- 8

Using a hierarchical design, complex objects can be constructed from simpler base classes. For example an object of class MFCLPar() is made up of several smaller (parent) classes representing the biological parameters (MFCLBiol), the flag settings (MFCLFlags), the tag reporting data (MFCLTagRep), etc. etc. Methods written for parent classes are inherited by any child class constructed from them.

> par <- MFCLPar()    # the MFCLPar constructor
> is(par)
[1] "MFCLPar"     "MFCLBiol"    "MFCLFlags"   "MFCLTagRep"  "MFCLRec"     "MFCLRegion"  "MFCLSel"    
[8] "MFCLParBits" "MFCLBase"  

Getting Started

Reading and writing objects

Basic read functions are provided for all of the standard MFCL input files (.ini, .frq, .tag files) as well as many, though not all, of the MFCL output files (.par, .rep, ...). A wide range of model configurations and data types can be accommodated by MFCL making the input files highly complex and variable between different assessments. In addition, MFCL is constantly being updated with ever more features such that the format and structure of the input and output files continues to evolve over time. The read and write functions within MFCL are continuously updated to work for the most recent assessments for the key tuna species. Back compatability with earlier input file formats is not guaranteed. Similarly compatability with other assessed species (eg. oceanic whitetip shark) cannot be guaranteed.

The following code example reads in the stock assessment data for the 2019 WCPO skipjack assessment (from one of the grid models), to create the ini, frq and tag objects (inputs) and the par and rep objects (outputs). Files for the 54 model grid will be downloaded, so this may take a little while.

library(FLR4MFCL)

temp <- tempfile()
download.file("https://oceanfish.spc.int/en/publications/doc_download/1921-skj2019forwebzip",temp)
ini <- read.MFCLIni(unz(temp, "Length50_GrowthDiag_Mix1_H0.8/skj.ini"))
frq <- read.MFCLFrq(unz(temp, "Length50_GrowthDiag_Mix1_H0.8/skj.frq"))
tag <- read.MFCLTag(unz(temp, "Length50_GrowthDiag_Mix1_H0.8/skj.tag"))
par <- read.MFCLPar(unz(temp, "Length50_GrowthDiag_Mix1_H0.8/07.par"))
rep <- read.MFCLRep(unz(temp, "Length50_GrowthDiag_Mix1_H0.8/plot-07.par.rep"))
unlink(temp)

Clone this wiki locally