Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
updating some file structure stuff; rerunning MPAs to include "no take"
Former-commit-id: fa4c4ef
Former-commit-id: 969b43e419999d7632d4c40e51e5a38fe1bff819
  • Loading branch information
oharac committed Jun 17, 2018
1 parent 394abe7 commit d3cc35c
Show file tree
Hide file tree
Showing 69 changed files with 388 additions and 275,573 deletions.
4 changes: 2 additions & 2 deletions data_setup/1_set_up_iucn_risk.Rmd
Expand Up @@ -24,11 +24,11 @@ knitr::opts_chunk$set(fig.width = 6, fig.height = 4, fig.path = 'Figs/',
source('https://raw.githubusercontent.com/oharac/src/master/R/common.R')
dir_git <- '~/github/spp_health_dists'
dir_git <- '~/github/spp_risk_dists'
### goal specific folders and info
dir_setup <- file.path(dir_git, 'data_setup')
dir_o_anx <- file.path(dir_O, 'git-annex/spp_health_dists')
dir_o_anx <- file.path(dir_O, 'git-annex/spp_risk_dists')
### provenance tracking
library(provRmd); prov_setup()
Expand Down
4 changes: 2 additions & 2 deletions data_setup/2_set_up_iucn_risk_regional.Rmd
Expand Up @@ -24,11 +24,11 @@ knitr::opts_chunk$set(fig.width = 6, fig.height = 4, fig.path = 'Figs/',
source('https://raw.githubusercontent.com/oharac/src/master/R/common.R')
dir_git <- '~/github/spp_health_dists'
dir_git <- '~/github/spp_risk_dists'
### goal specific folders and info
dir_setup <- file.path(dir_git, 'data_setup')
dir_o_anx <- file.path(dir_O, 'git-annex/spp_health_dists')
dir_o_anx <- file.path(dir_O, 'git-annex/spp_risk_dists')
# ### provenance tracking
library(provRmd); prov_setup()
Expand Down
4 changes: 2 additions & 2 deletions data_setup/2a_set_up_regional_codes.Rmd
Expand Up @@ -24,11 +24,11 @@ knitr::opts_chunk$set(fig.width = 6, fig.height = 4, fig.path = 'Figs/',
source('https://raw.githubusercontent.com/oharac/src/master/R/common.R')
dir_git <- '~/github/spp_health_dists'
dir_git <- '~/github/spp_risk_dists'
### goal specific folders and info
dir_setup <- file.path(dir_git, 'data_setup')
dir_o_anx <- file.path(dir_O, 'git-annex/spp_health_dists')
dir_o_anx <- file.path(dir_O, 'git-annex/spp_risk_dists')
# ### provenance tracking
library(provRmd); prov_setup()
Expand Down
2 changes: 1 addition & 1 deletion data_setup/3_set_up_iucn_trends.Rmd
Expand Up @@ -24,7 +24,7 @@ knitr::opts_chunk$set(fig.width = 6, fig.height = 4, fig.path = 'Figs/',
source('https://raw.githubusercontent.com/oharac/src/master/R/common.R')
dir_git <- '~/github/spp_health_dists'
dir_git <- '~/github/spp_risk_dists'
### goal specific folders and info
dir_data <- file.path(dir_git, 'data')
Expand Down
62 changes: 34 additions & 28 deletions data_setup/4_set_up_ocean_area_and_mpa_pct.Rmd
Expand Up @@ -28,13 +28,13 @@ library(fasterize)
source('~/github/src/R/common.R') ###
### includes library(tidyverse); library(stringr); dir_M points to ohi directory
dir_git <- '~/github/spp_health_dists'
dir_git <- '~/github/spp_risk_dists'
### goal specific folders and info
dir_setup <- file.path(dir_git, 'data_setup')
dir_spatial <- file.path(dir_git, 'spatial')
dir_anx <- file.path(dir_M, 'git-annex')
dir_o_anx <- file.path(dir_O, 'git-annex/spp_health_dists')
dir_o_anx <- file.path(dir_O, 'git-annex/spp_risk_dists')
# ### provenance tracking
library(provRmd); prov_setup()
Expand Down Expand Up @@ -71,9 +71,9 @@ Use ocean raster from OHI assessments, match to 0.10 degree raster, crosstab to

``` {r reproject_loiczid_to_mollweide}
tenthdeg_rast <- raster::raster(resolution = 0.10, ext = extent(c(-180, 180, -90, 90)))
tenthdeg_ids_rast <- raster::raster(resolution = 0.10, ext = extent(c(-180, 180, -90, 90)))
### default to WGS84
values(tenthdeg_rast) <- 1:length(tenthdeg_rast)
values(tenthdeg_ids_rast) <- 1:length(tenthdeg_ids_rast)
tenthdeg_moll_file <- file.path(dir_o_anx, 'spatial/tenthdeg_moll_ocean_934m.tif')
tenthdeg_moll_id_file <- file.path(dir_o_anx, 'spatial/tenthdeg_moll_id_934m.tif')
Expand Down Expand Up @@ -195,15 +195,20 @@ if(!file.exists(wdpa_marine_file)) {
# wdpa_poly$STATUS %>% table()
# Adopted Designated Established Inscribed Not Reported Proposed
# 34 215853 2 241 128 1537
# wdpa_poly$NO_TAKE %>% unique()
# x <- wdpa_poly %>% filter(NO_TAKE %in% c('All', 'Part'))
wdpa_marine <- wdpa_poly %>%
filter(MARINE > 0 | GIS_M_AREA > 0) %>%
filter(STATUS %in% c('Designated', 'Adopted', 'Established')) %>%
### no paper parks
filter(!str_detect(tolower(MANG_PLAN), 'non-mpa')) %>%
### omit non-MPA fisheries or species management plans
mutate(cat = iucn_cats[IUCN_CAT],
cat = ifelse(is.na(cat), 7, cat)) %>%
mutate(no_take = (NO_TAKE == 'All') | (NO_TAKE == 'Part' & NO_TK_AREA > 0.75 * GIS_M_AREA),
### if NO_TK_AREA is 75% or more of GIS area, count it...
cat = iucn_cats[IUCN_CAT],
cat = ifelse(no_take & !cat %in% 1:2, 7, cat), ### use 7 as a "no take" flag
cat = ifelse(is.na(cat), -1, cat)) %>% ### use -1 as an "other protected" flag
arrange(cat) %>%
st_transform(crs = proj4string(ocean_base))
Expand All @@ -212,10 +217,9 @@ if(!file.exists(wdpa_marine_file)) {
field = 'cat',
fun = 'first')
mask(wdpa_all_rast, tenthdeg_moll_ocean,
filename = wdpa_marine_file,
# progress = 'text',
overwrite = TRUE)
x <- mask(wdpa_all_rast, tenthdeg_moll_ocean,
filename = wdpa_marine_file,
overwrite = TRUE)
}
git_prov(file.path(dir_o_anx, 'wdpa/wdpa_jun2018/WDPA_June2018-shapefile-polygons.shp'), 'input')
Expand All @@ -225,16 +229,16 @@ git_prov(wdpa_marine_file, 'output') ### even in "if", mask() won't prov-registe

### Crosstab WDPA map to cell IDs

Be cautious when using `raster::crosstab()` as it returns factors that need to be coerced into integers... This code results in a file of cell IDs, IUCN protected area categories (1 = Ia and Ib, 2-6 = II - VI, 7 = other), and proportion of cell protected by that category.
Be cautious when using `raster::crosstab()` as it returns factors that need to be coerced into integers... This code results in a file of cell IDs, IUCN protected area categories (1 = Ia and Ib, 2-6 = II - VI, 7 = no take, -1 = other), and proportion of cell protected by that category.

``` {r crosstab mpa areas}
# wdpa_marine_file <- file.path(dir_o_anx, 'wdpa/wdpa_mar_by_cat_jun2018.tif')
# tenthdeg_moll_file <- file.path(dir_o_anx, 'spatial/tenthdeg_moll_934m.tif')
# tenthdeg_ocean_area_file <- file.path(dir_o_anx, 'spatial', 'area_rast_010_wgs84.tif')
# tenthdeg_moll_file <- file.path(dir_o_anx, 'spatial/tenthdeg_moll_id_934m.tif')
# tenthdeg_ocean_area_file <- file.path(dir_git, 'spatial', 'ocean_area_rast_010_wgs84.tif')
wdpa_all_rast <- raster(wdpa_marine_file)
tenthdeg_ocean_rast <- raster(tenthdeg_moll_file)
tenthdeg_moll_ocean_rast <- raster(tenthdeg_moll_file)
tenthdeg_area_rast <- raster(tenthdeg_ocean_area_file)
wdpa_cell_area_file <- file.path(dir_git, 'spatial/wdpa_mpa_area_010_wgs84.csv')
Expand Down Expand Up @@ -266,22 +270,22 @@ if(!file.exists(wdpa_cell_area_file)) {
return(wdpa_cells)
}
# system.time({
system.time({
wdpa_cells_list <- parallel::mclapply(1:n_chunks,
FUN = function(x) crosstab_chunk(wdpa_all_rast,
tenthdeg_ocean_rast,
tenthdeg_moll_ocean_rast,
chunk = x, n_chunks),
mc.cores = 10)
mc.cores = 12)
# user system elapsed
# 1221.984 1340.792 410.808
# })
})
wdpa_cells_df <- bind_rows(wdpa_cells_list)
tenthdeg_area_df <- data.frame(cell_id = values(tenthdeg_rast),
tenthdeg_area_df <- data.frame(cell_id = values(tenthdeg_ids_rast),
area_km2 = values(tenthdeg_area_rast))
reso_km2 <- raster::res(tenthdeg_ocean_rast)[1] / 1000
reso_km2 <- raster::res(tenthdeg_moll_ocean_rast)[1] / 1000
wdpa_area_df <- wdpa_cells_df %>%
full_join(tenthdeg_area_df) %>%
Expand All @@ -302,7 +306,7 @@ if(!file.exists(wdpa_cell_area_file)) {

Proportional protection can be multiplied by ocean area raster to get area of protection. Collect by category (to avoid duplicate "by" values):

* No Take (categories 1 & 2 only)
* No Take (categories 1 & 2 and specifically designated "no take")
* Conservation (categories 1-4)
* All protection (non-NA)

Expand All @@ -312,9 +316,9 @@ Note: these are not saved as rasters at this point... they are easily created fr
wdpa_area_df <- read_csv(wdpa_cell_area_file)
# tenthdeg_rast <- raster::raster(resolution = 0.10, ext = extent(c(-180, 180, -90, 90)))
# tenthdeg_ids_rast <- raster::raster(resolution = 0.10, ext = extent(c(-180, 180, -90, 90)))
# ### default to WGS84
# values(tenthdeg_rast) <- 1:length(tenthdeg_rast)
# values(tenthdeg_ids_rast) <- 1:length(tenthdeg_rast)
notake_df <- wdpa_area_df %>%
filter(wdpa_category <= 2) %>%
Expand All @@ -330,11 +334,13 @@ all_prot_df <- wdpa_area_df %>%
group_by(cell_id) %>%
summarize(mpa_pct = sum(mpa_pct))
notake_raster <- subs(tenthdeg_rast, notake_df, by = 'cell_id', which = 'mpa_pct')
plot(notake_raster, main = 'No take protection (Ia, Ib, II)')
conservation_raster <- subs(tenthdeg_rast, conservation_df, by = 'cell_id', which = 'mpa_pct')
plot(conservation_raster, main = 'Conservation protection (Ia - IV)')
all_prot_raster <- subs(tenthdeg_rast, all_prot_df, by = 'cell_id', which = 'mpa_pct')
notake_raster <- subs(tenthdeg_ids_rast, notake_df, by = 'cell_id', which = 'mpa_pct')
plot(notake_raster, main = 'No take protection (Ia, Ib, II + no take)')
conservation_raster <- subs(tenthdeg_ids_rast, conservation_df, by = 'cell_id', which = 'mpa_pct')
plot(conservation_raster, main = 'Conservation protection (Ia - IV + no take)')
all_prot_raster <- subs(tenthdeg_ids_rast, all_prot_df, by = 'cell_id', which = 'mpa_pct')
plot(all_prot_raster, main = 'All protection (any category)')
```

Expand Down
4 changes: 2 additions & 2 deletions data_setup/4a_set_up_eez_lme_rasts.Rmd
Expand Up @@ -26,8 +26,8 @@ library(sf)
source('https://raw.githubusercontent.com/oharac/src/master/R/common.R')
dir_git <- '~/github/spp_health_dists'
dir_o_anx <- file.path(dir_O, 'git-annex/spp_health_dists')
dir_git <- '~/github/spp_risk_dists'
dir_o_anx <- file.path(dir_O, 'git-annex/spp_risk_dists')
### goal specific folders and info
dir_check <- file.path(dir_git, 'data/iucn/map_check')
Expand Down
4 changes: 2 additions & 2 deletions data_setup/5_process_spp_shps.Rmd
Expand Up @@ -26,8 +26,8 @@ source('https://raw.githubusercontent.com/oharac/src/master/R/common.R')
library(sf)
dir_git <- '~/github/spp_health_dists'
dir_o_anx <- file.path(dir_O, 'git-annex/spp_health_dists')
dir_git <- '~/github/spp_risk_dists'
dir_o_anx <- file.path(dir_O, 'git-annex/spp_risk_dists')
source(file.path(dir_git, 'data_setup/api_fxns.R'))
Expand Down
4 changes: 2 additions & 2 deletions data_setup/6_aggregate_spp_ranges.Rmd
Expand Up @@ -27,8 +27,8 @@ source('https://raw.githubusercontent.com/oharac/src/master/R/common.R')
library(sf)
library(data.table)
dir_git <- '~/github/spp_health_dists'
dir_o_anx <- file.path(dir_O, 'git-annex/spp_health_dists')
dir_git <- '~/github/spp_risk_dists'
dir_o_anx <- file.path(dir_O, 'git-annex/spp_risk_dists')
source(file.path(dir_git, 'data_setup/api_fxns.R'))
Expand Down
Binary file modified data_setup/Figs/unnamed-chunk-2-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified data_setup/Figs/unnamed-chunk-2-2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified data_setup/Figs/unnamed-chunk-2-3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d3cc35c

Please sign in to comment.