4  R routines

DISPLACE requires input files in a specific format for the modeling framework to read them correctly. The previous sections described the contents and structure of the raw inputs, which must then be transformed to meet these requirements. In this section, we walk through the R routines needed to adapt the inputs.

The required DISPLACE inputs depend on the type of analysis being performed and the model modules being used. While other DISPLACE applications make use of additional routines to prepare such inputs (see the complete routines repository from François et al.), here we only include those relevant to our case study. These are divided into two main groups: routines for preparing data for the populations model and routines for preparing data for the fleet model. Additional routines are included to prepare the remaining data needed to run DISPLACE.

In this repository, the routines are located in the routines folder, and the code to execute them sequentially can be found in r/functions_routines.R. Here we use R 4.5.0, and the packages included in r/config.R. Be aware that as describerd in some of the previous sections, some model inputs are hardcoded within this routines, so modify the code as needed for your case study.

Routines for the population inputs located in raw_inputs/POPULATIONS are:

Routines for the fleet inputs in raw_inputs/FISHERIES are:

The routine 09_GenerateOtherCatchesOnNodes.R assigns additional fixed catches to the nodes beyond those of our modeled fleet. For instance, if other nations or fleets not explicitly characterized in the model exert fishing pressure on the populations defined in the analysis, the catch from these can be indicated in the file OTHER/othercatchespercountry.csv as fixed removals (in tonnes per year). While recruits are proportionally assigned based on coverage and density from SDM inputs, this routine assigns other catches evenly across the species’ coverage area, without accounting for species density. The routine can, however, be updated to weight other catches according to species distribution.

Additional routines required to run DISPLACE are:

The execution of r/functions_routines.R runs these routines sequentially and generates the contents of the processed_inputs folder (initially empty in this repository). To create its contents, simply execute this script.

source(here::here("r/functions_routines.R"))

In addition to running the routines, functions_routines.R also:

The script also includes the function generate_dis_run_files, which defines the .bat and .dsf files needed to run DISPLACE without using the GUI. This function allows the user to specify:

Once all processed inputs are generated (this can be done in Windows, macOS, or Linux using R), DISPLACE can be run from a Windows machine either via the GUI or by double-clicking the generated .bat file.