Transform and prepare the database in order to compute the indices of the create_selectivity_sheet() function.

Inputs are catch comparison data obtained from test and standard fishing gear.

Data are recorded under 4 tables: TR table records all information relative to the fishing trial and the gear used; HH table records all information relative to the fishing operation, SL table records all information to the catch weight for each fraction (landings and discards, and eventually landing categories), species (mandatory) and eventually landing category or sex; HL table records number of individuals for each length class.

Not all species are measured and/or weighted, but for a given species, the same level of information is required for each gear and fraction.

The create_selectivity_sheet() function ensures consistency between the 4 tables and allows for filtering on vessel/trial/fishing operation/species to create the summary sheet of the experiment.

The function computes raised numbers of individuals from sampled observed.

prep_sel_data(
  data,
  filters = list(project = "all", vessel = "all", trip = "all", station = "all",
    species_LAN = "all", species_DIS = "all", species_length = "all")
)

Arguments

data

list A list of four data.frames (TR,HH,SL,HL) based on the ICES RDB data exchange format corresponding to each level of the dataset. EU/ICES have defined common format and processing tools, for fisheries statistics. For more details on the input data format, see the related vignette : vignette("selectivity-data", package = "inser")

filters

list A list of filters to apply on the dataset. The optional filters can apply directly on the fields ‘project’, ‘vessel_identifier’, ‘selective_device’, ‘trip_code’, ‘station_number’. For the fields ‘species_LAN’, ‘species_DIS’, and ‘species_length’, the filter apply on the landings (LAN), discards (DIS) and on the measured species, respectively.

Value

data.frame A data.frame object corresponding to the join of the four tables.

Details

If the field ‘elevated_number_at_length’ is not provided in HL or some values are missing, the function calculate them using ‘number_at_length’ and the ratio between the subsample_weight and the weight (table SL).

Examples

### Example for protocol 'twin'

OTT_data_folder <-
  system.file("script_origin", "Data", "Example_OTT",
              package = "inser")

TR <- readr::read_delim(
  file = file.path(OTT_data_folder, "TR.csv"),
  delim = ";",
  escape_double = FALSE,
  locale = readr::locale(encoding = "WINDOWS-1252"),
  trim_ws = TRUE
)
#> Rows: 2 Columns: 31
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: ";"
#> chr (12): sampling_type, landing_country, vessel_flag_country, project, harb...
#> dbl (11): trip_code, year, vessel_length, vessel_power, vessel_size, vessel_...
#> lgl  (8): number_of_sets, days_at_sea, departure_date_time, return_date_time...
#> 
#>  Use `spec()` to retrieve the full column specification for this data.
#>  Specify the column types or set `show_col_types = FALSE` to quiet this message.

HH <- read.table(
  file.path(OTT_data_folder, "HH.csv"),
  sep = ";",
  header = TRUE,
  encoding = "WINDOWS-1252"
)#,colClasses = colClasses)

SL <- read.table(
  file.path(OTT_data_folder, "SL.csv"),
  sep = ";",
  header = TRUE,
  encoding = "WINDOWS-1252"
)

HL <- read.table(
  file.path(OTT_data_folder, "HL.csv"),
  sep = ";",
  header = TRUE,
  encoding = "WINDOWS-1252"
)

colClasses <- rep(NA, ncol(HH))
colClasses[which(names(HH) == "statistical_rectangle")] <-
  "character"

HH <- read.table(
  file.path(OTT_data_folder, "HH.csv"),
  sep = ";",
  header = TRUE,
  colClasses = colClasses,
  encoding = "WINDOWS-1252"
)

# HH<-HH |>
#   rename(pos_start_lat=pos_start_lat_dec) |>
#   rename(pos_start_lon=pos_start_lon_dec) |>
#     rename(pos_stop_lat=pos_stop_lat_dec) |>
#   rename(pos_stop_lon=pos_stop_lon_dec)
# 
# write.table(HH,file=  file.path(OTT_data_folder, "HH.csv"),row.names = F,sep=";")


TAB <- prep_sel_data(data = list(TR, HH, SL, HL))