convert_r: Land conversion module

Description Usage Arguments Details Examples

View source: R/convert_r.R

Description

This module takes inputs from the targets and constraints modules and determines which pixels are converted.

Usage

1
2
convert_r(conv_prob, target, crop_frac, pot_yield, code, cropnames,
  write_out = FALSE)

Arguments

conv_prob

Conversion probability brick (from constraints*)

target

Production target data.frame

crop_frac

RasterBrick of crop allocation fraction

pot_yield

RasterBrick of potential crop yields (modified by ybeta)

code

Unique simulation code resulting from run_code function

cropnames

Vector of crop names in analysis

write_out

FALSE (default) or TRUE. If TRUE, brick is written to disk

Details

This function relies on vectorization of input rasters to rank pixels for each crop by their conversion probability, calculate the cumulative production from most likely to least likely to be converted, and then finding the pixels which are less than the production target. These are marked as converted.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
rc <- run_code(input_key = "ZA")
il <- fetch_inputs(input_key = "ZA", input = "R")
ybetas <- list(1, 1)
ybeta <- yield_mod_r(inlist = il[c("p_yield", "pp_curr")], ybetas = ybetas,
                     cropnames = il$cropnames)
prod_targ <- c("maize" = 2, "cassava" = 2, "ground" = 2, "cotton" = 2,
               "soy" = 2, "pulse" = 2, "sunflower" = 2, "sugarcane" = 2,
               "wheat" = 2)
target <- targets_r(prod_targ, currprod = il$currprod,
                    potprod = ybeta$pp_curr, cropnames = il$cropnames)
cbetas <- c("y_std" = 0, "C" = 1, "bd" = 1, "cost" = 1)
clist <- list("y_std" = ybeta$y_std, "C" = il$carbon_p, "bd" = il$cons_p,
              "cost" = il$cost)
conv_prob <- constraints_r(inlist = clist, cbetas = cbetas, code = rc,
                           cropnames = il$cropnames)
conv <- convert_r(conv_prob = conv_prob, target = target,
                  crop_frac = il$cropfrac, pot_yield = ybeta$p_yield,
                  code = il$code, cropnames = il$cropnames)
plot(conv)

marcusspiegel/agroEcoTradeoff documentation built on May 21, 2019, 11:44 a.m.