knitr::opts_chunk$set(echo=T, message=F, warning=F)
library(prioritizr) # devtools::load_all("~/github/prioritizr") #library(bbnj) # devtools::load_all() # setwd(here()); devtools::install_local(force=T) # devtools::install_github("ecoquants/bbnj") library(raster) library(sf) library(dplyr) library(readr) library(stringr) library(glue) library(here) library(fs) library(knitr) library(formattable) library(lwgeom) area = raster::area select = dplyr::select #message("library done") if (interactive()){ wd <- file.path(here::here(), "inst/app/www/scenarios/") setwd(wd) # getwd() if (!exists("rmd")){ #rmd <- file.path(getwd(), "s00a.bio.30pct.gl.mol50km.Rmd") rmd <- file.choose() } } else { rmd <- knitr::current_input(dir = T) } pfx <- rmd %>% path_ext_remove() tif <- glue("{pfx}_sol.tif")
r basename(pfx)Projection: Mol 50km
Planning unit cost: set to 1
Objective function:
add_min_set_objective(): Minimize the cost of the solution whilst ensuring that all targets are met Feature targets:
bio_vgpm: Vertically Generalized Production Modelnspp_*: number of species by 23 taxonomic groups from AquaMaps [future - 2100]rls_all: Red List Sum of averge extinction risk for all species from AquaMaps [future - 2100]phys_vents: hydrothermal vent countphys_seamounts: seamounts count (3 depth classes)phys_scapes_hetero: benthic heterogeneity# variables ---- rel_target <- 0.3 prjres <- "_mol50km" # prjres in: View(projections_tbl) redo <- T # problem & solution ---- P <- projections_tbl %>% filter(prjres == !!prjres) if (!file.exists(tif) | redo){ # planning unit: ---- r_pu_id <- get_d_prjres("r_pu_id", prjres) # plot(r_pu_id) r_pu <- setValues(r_pu_id, 1) %>% mask(r_pu_id) # plot(r_pu) # biodiversity: 2100 ---- s_bio_gmbi_future <- get_gmbi_grpsmdl_prjres("groups02_2100", prjres) lyrs_bio_future <- names(s_bio_gmbi_future) %>% setdiff(str_subset(names(s_bio_gmbi_future), "rli")) %>% setdiff(str_subset(names(s_bio_gmbi_future), "rls")) s_bio_gmbi_future <- subset(s_bio_gmbi_future, lyrs_bio_future) # rls 2100 rls_all_future <- get_gmbi_grpsmdl_prjres("groups00_2100", prjres) %>% subset(,subset="groups00_2100_rls_all") # features ---- s_seamounts <- get_d_prjres("s_phys_seamounts",prjres) lu_seamounts <- c(lteq200m="0to200",gt200lteq800m="gt200to800",gt800m="gt800") lbls_seamounts <- sprintf("phys_seamounts_%sm", lu_seamounts[names(s_seamounts)]) s_features <- stack( get_d_prjres("r_vgpm", prjres), s_bio_gmbi_future, rls_all_future, #raster(s_fish_gfw, "mean_scaled_profits_with_subsidies") %>% # gap_fill_raster(r_mask=r_pu_id) %>% # rescale_raster(inverse=T), #raster(s_fish_ubc, "mcp_2004"), s_seamounts, get_d_prjres("r_phys_vents",prjres), get_d_prjres("r_phys_scapes_hetero",prjres)) names(s_features) <- c( "bio_vgpm", gsub("^.*?_","",names(s_bio_gmbi_future)), "rls_all_future", #"fish_profit.subs" #"fish_mcp.2004", lbls_seamounts, "phys_vents", "scapes_hetero") # problem ---- p <- problem(r_pu, s_features) %>% add_min_set_objective() %>% add_relative_targets(rel_target) # solve ---- tif <- solve_log(p, pfx, redo=redo) }
report_solution(tif, redo=redo)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.