ohi logo
OHI Science | Citation policy

1 Methods

## load libraries
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(tidyr)
library(here)
## here() starts at /home/sgclawson/github/ohiprep_v2020
setwd(here::here("globalprep","fp","v2020"))

## Load FAO-specific user-defined functions
source('http://ohi-science.org/ohiprep_v2020/workflow/R/common.R')
## This file makes it easier to process data for the OHI global assessment
##  by creating the following objects:
## 
##  * dir_M = identifies correct file path to Mazu (internal server) based on your operating system
##  * mollCRS = the crs code for the mollweide coordinate reference system we use in the global assessment
##  * regions_shape() = function to load global shapefile for land/eez/high seas/antarctica regions
##  * ohi_rasters() = function to load two rasters: global eez regions and ocean region
##  * region_data() = function to load 2 dataframes describing global regions 
##  * rgn_syns() = function to load dataframe of region synonyms (used to convert country names to OHI regions)
##  * low_pop() = function to load dataframe of regions with low and no human population
##  * UNgeorgn = function to load dataframe of UN geopolitical designations used to gapfill missing data

2 Import Output Data: Mariculture data

Mariculture production in tonnes.

mar <- read.csv('../../mar/v2020/output/MAR_FP_data.csv')

Fisheries data.

fis <- read.csv("../../fis/v2020/output/FP_fis_catch.csv") %>%
  dplyr::select(rgn_id, year, fis_t = fis_catch)

3 Wrangle

3.1 Tidy MAR data

mar <- mar %>%
  group_by(rgn_id, year) %>%
  summarize(mar_t = sum(value, na.rm=TRUE)) %>%
  dplyr::select(rgn_id, year, mar_t) %>%
  ungroup()
## `summarise()` regrouping output by 'rgn_id' (override with `.groups` argument)
# this one is turning to NA in FP
filter(mar, rgn_id ==95) # ok, this makes sense
## # A tibble: 15 x 3
##    rgn_id  year mar_t
##     <int> <int> <dbl>
##  1     95  2004    21
##  2     95  2005     2
##  3     95  2006     2
##  4     95  2007     2
##  5     95  2008     0
##  6     95  2009     0
##  7     95  2010     0
##  8     95  2011     0
##  9     95  2012     0
## 10     95  2013     0
## 11     95  2014     0
## 12     95  2015     0
## 13     95  2016     0
## 14     95  2017     0
## 15     95  2018     0

3.2 Tidy FIS data

fis <- fis %>%
  mutate(fis_t = ifelse(fis_t==0, NA, fis_t)) %>%  # 11 NA values is correct
  group_by(rgn_id) %>%
  arrange(year) %>%
  fill(fis_t) %>% 
  ungroup()

3.3 Combine MAR and FIS

Adjust years so they are equivalent.

adjust <- max(mar$year) - max(fis$year)

mar <- mar %>%
  mutate(year = year - adjust)

tmp <- full_join(fis, mar, by=c('rgn_id', 'year'), all=TRUE)

## If NA, turn it into a 0 before weighting
tmp <- 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$w_fis)

4 Data check

Compare to previous year data (a big jump in fish data, so not super compatible, but should be correlated at least)

compare <- read.csv("../../fp/v2019/output/wildcaught_weight.csv") %>%
  rename(w_fis_old = w_fis) %>%
  left_join(tmp, by=c('rgn_id', 'year'))
plot(compare$w_fis_old, compare$w_fis)
abline(0, 1, col="red")

5 Save data

write.csv(tmp, 'output/wildcaught_weight.csv', row.names=FALSE)

## add gf file (no gapfilling)
tmp_gf <- tmp %>%
  mutate(w_fis = 0) %>%
  dplyr::select(rgn_id, year, gapfilled=w_fis)

write.csv(tmp_gf, 'output/wildcaught_weight_gf.csv', row.names=FALSE)