This script combines the fisheries catch data with the mariculture production data to create the weights for how much of each score will affect the entire food provision score.
#v2024 - Mariculture and Fisheries data was updated since last scenario year - Fixed trendline on graph
#v2023 - Updated Mariculture since last scenario year but not Fisheries - Updated scenario year input/some file paths to be more programmatic - Updated labeling of the graphs
## load libraries
library(dplyr)
library(tidyr)
library(here)
scen_year <- 2024 # change to latest year
prev_scen_year <- scen_year - 1
setwd(here::here("globalprep","fp", paste0("v", scen_year)))
## Load FAO-specific user-defined functions
source('http://ohi-science.org/ohiprep_v2021/workflow/R/common.R')
Mariculture production in tonnes.
mar <- read.csv(file.path("..", "..", "mar", paste0("v", scen_year), "output", "MAR_FP_data.csv")) # see metadata in its prep
Fisheries data.
Adjust years so they are equivalent.
adjust <- max(mar_tidy$year) - max(fis_tidy$year)
mar_adjust <- mar_tidy %>%
mutate(year = year - adjust)
tmp <- full_join(fis_tidy, mar_adjust, by = c('rgn_id', 'year')) # v2023: removed all = TRUE because was not a valid argument, did not see an equivalent
## If NA, turn it into a 0 before weighting
tmp_weights <- tmp %>%
mutate(fis_t = ifelse(is.na(fis_t), 0, fis_t)) %>%
mutate(mar_t = ifelse(is.na(mar_t), 0, mar_t)) %>%
mutate(w_fis = fis_t/(fis_t + mar_t)) %>%
mutate(w_fis = ifelse(mar_t == 0 & fis_t == 0, NA, w_fis)) %>%
filter(year >= 2005) %>%
dplyr::select(rgn_id, year, w_fis)
hist(tmp_weights$w_fis,
main = "Weights",
xlab = "Value")
Compare to previous year data
compare <- read.csv(paste0("../../fp/v", prev_scen_year, "/output/wildcaught_weight.csv")) %>%
rename(w_fis_old = w_fis) %>%
left_join(tmp_weights, by = c('rgn_id', 'year'))
plot(compare$w_fis_old, compare$w_fis,
xlab = paste0("Old data (v", prev_scen_year, ")"),
ylab = paste0("New data (v", scen_year, ")"),
abline(0, 1, col="red"))