## 
## 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
## here() starts at /home/sgclawson/github/ohiprep_v2019
setwd(here::here("globalprep","fp","v2019"))
## Load FAO-specific user-defined functions
source('http://ohi-science.org/ohiprep_v2019/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
Mariculture production in tonnes.
Fisheries data.
mar <- mar %>%
  group_by(rgn_id, year) %>%
  summarize(mar_t = sum(value, na.rm=TRUE)) %>%
  dplyr::select(rgn_id, year, mar_t) %>%
  ungroup()
# this one is turning to NA in FP
filter(mar, rgn_id ==95) # ok, this makes sense## # A tibble: 14 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
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)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/v2018/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")